Vim编辑器-Basic Abbreviations, Keyboard Mapping, and Initialization Files
8 Basic Abbreviations, Keyboard Mapping, and Initialization Files
-
Abbreviations
An abbreviation is a short word that takes the place of a long one. For example, ad stands for advertisement.The Vim editor enables you to type in an abbreviation and then will automatically expand it for you.To tell Vim to expand the abbreviation ad into advertisement every time you type it, use the following command:
:abbreviate ad advertisement
-
Listing Your Abbreviations
The command:abbreviate
lists all your current abbreviations. Figure 8.1 shows a
typical execution of this command. -
Mapping
Mapping enables you to bind a set of Vim commands to a single key. Suppose, for example, that you need to surround certain words with curly braces. In other words, you need to change a word such as amount into {amount}.
With the :map command, you can configure Vim so that the F5 key does this job. The command is as follows:
:map <F5> i{<Esc>ea}<Esc>
-
Listing Your Mappings
The :map command (with no arguments) lists out all your current mappings -
Fixing the Way Delete Works
If you find that your keyboard has the Backspace and Delete keys backward, you can use the following command to swap them:
:fixdel
-
Controlling What the Backspace Key Does
The ‘backspace’ option controls how thekey works in insert mode.
For example, the following command tells Vim to allow backspacing over autoindents:
:set backspace=indent
The following command enables you to backspace over the end of lines:
:set backspace=eol
In other words, with this option set, if you are positioned on the first column and press, the current line will be joined with the preceding one.
The following command enables you to backspace over the start of an insert:
:set backspace=start
In other words, you can erase more text than you entered during a single insert command.
You can combine these options, separated by commas. For example:
:set backspace=indent,eol,start
-
Saving Your Setting
After performing all your :map, :abbreviate, and :set commands, it would be nice if you could save them and use them again.
The command :mkvimrc writes all your settings to a file.The format of this com- mand is as follows:
:mkvimrc file
During startup, the Vim editor looks for an initialization file. If it is found, it is auto- matically executed. (Only the first file found is read.)
The initialization files are as follows:
UNIX
$HOME/.vimrc $HOME/_vimrc $HOME/.exrc $HOME/_exrc
MS-DOS
$HOME/_vimrc $HOME/.vimrc $VIM/_vimrc $VIM/.vimrc $HOME/_exrc $HOME/.exrc $VIM/_exrc $VIM/.exrc
One way you can find out which initialization files are read is to use the :version
command:
:version
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战