当前位置:网站首页>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.vimin , If you want to loadluaTo configure , You can put the file in~/.config/nvim/init.luain . echo、echomWill print strings , The difference isechomSend the printed content to a place calledmessage-historyWrite in the right place .luaMediumprintHaveechomThe function of- have access to
messageCommand viewmessage-historyThe content of - from
vimscriptFrom the use of , It says vim Some orders of , We write the command in the file and let vim To carry out .vim Command andvimscriptIt's a little bit likeshellCommand andshellThe relationship between scripts
边栏推荐
- [hfctf2020]babyupload session parsing engine
- 界面控件DevExpress WinForms皮肤编辑器的这个补丁,你了解了吗?
- Gnet: notes on the use of a lightweight and high-performance go network framework
- go-zero微服务实战系列(九、极致优化秒杀性能)
- 系统休眠文件可以删除吗 系统休眠文件怎么删除
- 安利一波C2工具
- 2022 Google CTF SEGFAULT LABYRINTH wp
- Openjudge noi 1.7 08: character substitution
- Add the applet "lazycodeloading": "requiredcomponents" in taro,
- Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
猜你喜欢

JTAG principle of arm bare board debugging

子网划分、构造超网 典型题

ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
![[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)](/img/7a/bd03943c39d3f731afb51fe2e0f898.png)
[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)

云呐-工单管理制度及流程,工单管理规范

go-zero微服务实战系列(九、极致优化秒杀性能)
![[signal and system]](/img/aa/a65d6da1d1d9410254ca7b775e24a6.png)
[signal and system]

2022 Google CTF SEGFAULT LABYRINTH wp

字节P7专业级讲解:接口测试常用工具及测试方法,福利文

移植DAC芯片MCP4725驱动到NUC980
随机推荐
How to manage distributed teams?
第三方跳转网站 出现 405 Method Not Allowed
Openjudge noi 1.7 08: character substitution
Analysis of mutex principle in golang
LLDP兼容CDP功能配置
交叉验证如何防止过拟合
Lldp compatible CDP function configuration
Vocabulary in Data Book
[hfctf2020]babyupload session parsing engine
There is an error in the paddehub application
The difference between spin and sleep
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
Gnet: notes on the use of a lightweight and high-performance go network framework
ARM裸板调试之JTAG原理
mysql: error while loading shared libraries: libtinfo. so. 5: cannot open shared object file: No such
Atomic in golang and CAS operations
Google发布安全更新,修复Chrome中已被利用的0 day
域分析工具BloodHound的使用说明
Segmenttree
让我们,从头到尾,通透网络I/O模型