开发者

how to write a shortcut map in vim?

开发者 https://www.devze.com 2022-12-22 18:53 出处:网络
I 开发者_运维问答want to add a shortcut like I type :open_my_document, it become :e /var/book/document.txt.

I 开发者_运维问答want to add a shortcut like I type :open_my_document, it become :e /var/book/document.txt. how to?


If you want to create a custom command, use :command:

:command Open_my_document e /var/book/document.txt

Then you can use:

:Open_my_document

Normally you can just type :Ope and then hit tab and vim will complete the full command name.

Note that your command needs to start with a capital letter because only built-in vim commands can start with lower-case letters.


I think you might be looking for something like :h cabbr or :h cmap.

If you use cabbr, your text will not change once you enter your custom command. If you use cmap, it will. It's easier to just try both out to see which you'd rather use.

I don't know advantages/disadvantages of one or the other, personally, I use cmap.


Add this to your .vimrc:

map :open_my_document :e /var/book/document.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消