开发者

Mapping a command with another command in vim

Just trying to remap the command to open bufferexplorer (\be) with the shorter version (\b). My try is:

map <leader>b <ESC><leader>be<CR>开发者_JAVA百科

Needless to say, this does not work. Any help?


Why do you have <CR> there? Your mapping will invoke bufexplorer and immediately exit it, choosing buffer under cursor (it is current buffer, is not it?) (I may be mistaking as I used bufexplorer only for a few hours). Correct one is

map <leader>b <C-\><C-n><leader>be

I also suggest replacing <Esc> with <C-\><C-n> which unconditionally exits to normal mode without beeping, it may be used for throwing away register and count too.

Note that mapleader variable must be at the same state as it were when bufexplorer defined its <leader>be mapping.


The original command itself is likely just a mapping to a command line mode command. I looked up the \be in BufExplorer's help and it says an alternative way of invoking would be :BufExplorer. So try the following:

noremap <silent> <leader>b :BufExplorer<CR>

Or maybe nmap instead of map depending on your needs.


Since default leader symbol is \ you can just

map <leader>b <ESC>\be<CR>

but if you care for actual leader symbol value, try something like

:execute 'map <leader>b <ESC>' . (exists('mapleader') ? mapleader : '\') . 'be<CR>'

where construction (exists('mapleader') ? mapleader : '\') substitutes appropriate leader symbol (see :help mapleader).

Note: if you change mapleader value after this mapping command, the mapping will beсome useless

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜