开发者

Combine two vim commands into one

开发者 https://www.devze.com 2023-04-10 11:25 出处:网络
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 hel

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.

0

精彩评论

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