当前位置:网站首页>Match VIM from zero (0) -- Introduction to vimscript
Match VIM from zero (0) -- Introduction to vimscript
2022-07-07 01:22:00 【aluluka】
Through the previous series of articles , I believe you guys should have been right vim There was a strong interest in , Maybe many friends become like me through slow use , Leave vim You won't be able to write code . If you want to use it for a long time vim, Even the vim As the main code editor , Then spend some time studying vim The configuration of is very useful . If you just because linux
The platform is installed by default vi/vim
, Usually, it is mainly used to change the matching file , Temporary use , Then I'd better quit this article , So as not to waste time .
The title says to build from zero basis vim A bit of a headline party , To understand the content of the following series of articles, at least understand vim Some of the basic concepts in it , I think before reading this series of columns , You should know the following
- know vim, And know vim Basic operation , For example, enter the insertion mode 、 Move the cursor , And know how to save and exit
- know vim Related terms , Buffer list 、 buffer 、 window 、 Command mode 、 Insert mode and so on
- know vim Where is your configuration file
If you don't know , Please move to my column , Follow the contents of the column to do experiments . Understand these concepts mentioned inside .
About configuration , I am going to introduce the following aspects :
- vimscript Basic content of , And add some things that have not been introduced before vim Characteristics of
- neovim lua Corresponding interface
- Some plug-ins and related configurations are recommended , Do throw bricks and attract jade
There may be a little friend to ask ,vimscript
Both writing and reading are obscure , and neovim
Has adopted a more understandable and modern lua
了 , It is necessary to learn vim script
Do you ?
I think it's necessary , First neovim
yes vim
Another implementation of , Want to learn well neovim
Nature can't get around vim
, And learn well vim
Naturally, I can't get around vimscript
. secondly ,lua
The interface in the script inherits from vimscript
. Want to use lua
The premise of configuration is to know how to use vimscript
To configure . They are like learning MFC
I can't get around it Win32 API
equally . So I think I want to learn neovim
The configuration of naturally cannot be bypassed vimscript
. and neovim
Fully compatible with vim
Don't worry about it vimscript
stay neovim
Problems that cannot be implemented in . indicating contrast neovim
It didn't happen vimscript
100% function , Sometimes it still depends on vimscript
To achieve .
Demo environment
The previous series of articles were intended to be in mac
For demonstration on , But what I found was that mac
It's troublesome to record on the screen , and mac
Upper neovim
I've configured it , Behavior may be naked vim
There's a gap ( Although you can start without loading the configuration file ), So I used WSL2 Ubuntu Upper neovim Do a demonstration .
Just this demo environment is not right vim Configured . It is also convenient to demonstrate from 0 Start configuration .
The environment of this tutorial is linux in neovim
Of 0.6.1
edition , Although the official has released 0.8 edition , however Ubuntu It seems that the official source is still 0.6. Let's continue to demonstrate with it
first vimscript Script
Any language I learn seems to be from printing hello world
At the beginning , I'm not immune . Our tutorial also starts from printing hello world
Let's get started
vimscript
Can be used in echo
and echom
To print statements , For example, we can enter echo "hello world"
. We found that at the bottom of the screen hello world
word .
Then we use echom "hello world"
Find out , It is still printed below hello world
word . What's the difference ?
To understand the difference between them, we need to introduce a new command :message
. This command allows you to view message-history
The content in , We can simply understand this command as viewing vim
Operation log of ( Although not checking the log ). Executing this order, we found ,message-history
Only one of them hello world
. At this time, their differences come out , One will write the printing information while printing message-history
, The other is just printing .
You just need to print different sentences to know echom
The content will be written to the log , and echo
Can't . Here's a place for you to experiment , I'm not going to do a demonstration .
Now let's finish a little exercise , Use vim Script to write a welcome message, such as hello, jack
, We let users see this welcome message every time they open it . For users here, we will fix it for the time being , Later, we can make dynamic changes Welcome users .
We know that every time we open vim, It will load the configuration file , We just need to write the command to be executed into the configuration file . Remember where the configuration file is ? in the light of neovim
It supports vimscript
and lua
To configure ( Of course, it also supports other languages ). Let's switch the directory to ~/.config/nvim
. If you have been configured before , Please make a backup of the configuration first . And make sure init.lua
(lua To configure ) and init.vim
(vimscript To configure ) There can only be one
Let's try to use vimscript
To complete this function . We create a new document ~/.config/nvim/init.vim
. Then write a sentence in it echo 'hello, jack'
, And then quit . We find that every time we enter neovim
after , There will always be such a sentence below .
Let's see how to use it lua
To print such a sentence ?lua
The corresponding function in is print
. We can go straight to Previously backed up init.lua
Write in print("hello, jack")
To complete this work ( Remember now before init.vim Backup
). It should be noted that lua
Medium print
Write write the information together to message
in , That is to say, it is connected with echom
The effect is the same . If you want to execute echo
Operation can be used api.vim.nvim_echo()
. Its usage is complicated , I won't introduce it now , Interested partners can check the official website , Try it to implement this example of printing welcome messages .
This concludes the content of this article , Finally, I'll give you a summary :
- neovim If you want to load vimscript To configure , You can put the configuration file in
~/.config/nvim/init.vim
in , If you want to loadlua
To configure , You can put the file in~/.config/nvim/init.lua
in . echo
、echom
Will print strings , The difference isechom
Send the printed content to a place calledmessage-history
Write in the right place .lua
Mediumprint
Haveechom
The function of- have access to
message
Command viewmessage-history
The content of - from
vimscript
From the use of , It says vim Some orders of , We write the command in the file and let vim To carry out .vim Command andvimscript
It's a little bit likeshell
Command andshell
The relationship between scripts
边栏推荐
- 从底层结构开始学习FPGA----FIFO IP的定制与测试
- 移植DAC芯片MCP4725驱动到NUC980
- The difference between spin and sleep
- C语言实例_5
- Neon Optimization: About Cross access and reverse cross access
- 界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
- [signal and system]
- Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
- 免费白嫖的图床对比
- [100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
猜你喜欢
动态规划思想《从入门到放弃》
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
Lldp compatible CDP function configuration
"Exquisite store manager" youth entrepreneurship incubation camp - the first phase of Shunde market has been successfully completed!
Analysis of mutex principle in golang
boot - prometheus-push gateway 使用
JTAG principle of arm bare board debugging
[hfctf2020]babyupload session parsing engine
从底层结构开始学习FPGA----FIFO IP的定制与测试
随机推荐
云呐|工单管理软件,工单管理软件APP
405 method not allowed appears when the third party jumps to the website
身体质量指数程序,入门写死的小程序项目
Gnet: notes on the use of a lightweight and high-performance go network framework
Spark TPCDS Data Gen
Installation of torch and torch vision in pytorch
Dynamic planning idea "from getting started to giving up"
Typical problems of subnet division and super network construction
NEON优化:矩阵转置的指令优化案例
NEON优化:性能优化经验总结
MySQL中回表的代价
Deep learning framework TF installation
736. Lisp 语法解析 : DFS 模拟题
Google发布安全更新,修复Chrome中已被利用的0 day
HMM notes
Let's see through the network i/o model from beginning to end
资产安全问题或制约加密行业发展 风控+合规成为平台破局关键
table表格设置圆角
How to evaluate load balancing performance parameters?
Data type of pytorch tensor