Combine two vim commands into one
I'm having trouble combining two vim commands, specifically <C-w>s
and <leader>x
into <leader>r
(i.e开发者_高级运维. split window and open spec counterpart of current file). Any help?
Thanks!
It would help if you'd post what exactly you've tried that didn't work. Generally, doing what you describe should be simple. It should be enough to put this in your .vimrc
file:
nmap <leader>r <c-w>s<leader>x
This maps <leader>r
to expand to the key sequence <c-w>s<leader>x
. Note that these are not "commands", as you call them in your question, they're "mappings". A "command" is something completely different in vim, you can read up on that with :help user-commands
.
One thing to be careful of is using nmap
instead of nnoremap
. The command nmap
maps the sequence on the left to the sequence on the right while re-using mappings that have already been defined. On the other hand, nnoremap
creates a mapping with the original meanings of the keys, so in your case won't work (since <leader>x
is defined by some plugin). This is one possible reason you may have failed while trying to do it, but I can't tell from your question.
精彩评论