问题
I use the Vim plugin ack.vim, but I don't understand why the command is :Ack
with a capital "A" (a little annoying to hold shift).
Is it possible to remap this to :ack
?
回答1:
Built-in commands start with a lowercase character and custom commands start with an uppercase character. Those are the rules. Vim simply won't let you define a custom command starting with a lowercase.
If you don't like it, nothing prevents you from creating a normal mode mapping:
nnoremap <leader>a :Ack<Space>
which is even faster than :ack<Space>
.
回答2:
Yes, but It is not as simple as it sounds:
cnoreabbrev <expr> ack getcmdtype() == ':' && getcmdline() ==# 'ack' ? 'Ack' : 'ack'
Long story short vim does not provide a native way to create lowercase commands. Using mappings causes delays so abbreviations are preferred. The trick is to be careful when the abbreviation should expand as cabbrev
's expand at other times than just ex commands and in other places e.g. search. Here is another thread talking about this point.
Hari Krishna Dara created a plugin: cmdalias.vim. It uses a variation of the technique above
来源:https://stackoverflow.com/questions/16821907/is-it-possible-to-remap-an-ex-command-in-vim-remap-ack-to-ack