当前位置:网站首页>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
边栏推荐
- NEON优化:性能优化经验总结
- 机器学习:随机梯度下降(SGD)与梯度下降(GD)的区别与代码实现。
- Atomic in golang, and cas Operations
- Openjudge noi 1.7 10: simple password
- 从零开始匹配vim(0)——vimscript 简介
- Dark horse notes - exception handling
- Informatics Olympiad YBT 1171: factors of large integers | 1.6 13: factors of large integers
- Js逆向——捅了【马蜂窝】的ob混淆与加速乐
- Failed to successfully launch or connect to a child MSBuild. exe process. Verify that the MSBuild. exe
- C language - array
猜你喜欢
随机推荐
AI 从代码中自动生成注释文档
7.6模拟赛总结
Wood extraction in Halcon
Oracle:CDB限制PDB资源实战
C语言实例_5
移植DAC芯片MCP4725驱动到NUC980
THREE.AxesHelper is not a constructor
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Receive user input, height BMI, BMI detection small business entry case
Case development of landlord fighting game
Table table setting fillet
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
[100 cases of JVM tuning practice] 04 - Method area tuning practice (Part 1)
接收用户输入,身高BMI体重指数检测小业务入门案例
机器学习:随机梯度下降(SGD)与梯度下降(GD)的区别与代码实现。
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
域分析工具BloodHound的使用说明
taro3.*中使用 dva 入门级别的哦
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
NEON优化:性能优化常见问题QA