简体   繁体   English

有没有一种方法可以映射特定于插件的键在Vim中做多个键?

[英]Is there a way to map plugin specific keys to do multiple keys in Vim?

I'd like to map NERDTree's tab opening key, 't', to do multiple things. 我想映射NERDTree的标签页打开键“ t”来执行多项操作。 Namely, I'd like it to open the tab then do the following list of commands: TlistToggle Ctrl W, Ctrl T, Ctrl W, Shift K, 30, Ctrl W, minus-sign. 即,我希望它打开选项卡,然后执行以下命令列表:TlistToggle Ctrl W,Ctrl T,Ctrl W,Shift K,30,Ctrl W,减号。 So that I open the taglist for the file, then horizontally split the list and the file, then resize the tag list. 因此,我打开了文件的标签列表,然后水平分割列表和文件,然后调整标签列表的大小。

I've tried the following: 我尝试了以下方法:

nnoremap <t> NERDTree-t TlistToggle <C-W><C-T><C-W><S-K>30<C-W> -

but this doesn't seem to do anything. 但这似乎无能为力。

Thoughts? 有什么想法吗? Am I just completely doing this wrong. 我只是完全做错了吗? Is this even possible? 这有可能吗?

  • The NERDTree mapping is not a global one, but only exists (and makes sense) in the plugin's sidebar. NERDTree映射不是全局映射,而是仅存在于插件的边栏中(并且很有意义)。 That makes it more difficult to override, but you can hook into NERDTree setting its 'filetype' , and then define a buffer-local mapping to override NERDTree's: 这使重写变得更加困难,但是您可以将NERDTree设置为它的'filetype' ,然后将其绑定,然后定义一个本地缓冲区映射以覆盖NERDTree的:

    :autocmd FileType nerdtree nnoremap t ... :autocmd FileType书呆子nnoremap ...

  • While normal mode commands (like the <Cw>... stuff) can indeed be concatenated, that's not true for the plugin invocations. 虽然可以串联普通模式的命令(例如<Cw>...东西),但对于插件调用而言并非如此。 You can find out NERDTree's via :nmap <buffer> t : 您可以通过:nmap <buffer> t找到NERDTree的:

    :call nerdtree#invokeKeyMap("t") :call nerdtree#invokeKeyMap(“ t”)

The Taglist's is also an Ex command; 标记列表也是一个Ex命令; you can combine both with | 您可以将| (written as <Bar> in mappings): (在映射中写为<Bar> ):

:call nerdtree#invokeKeyMap("t")<Bar>TlistToggle<CR>

So, something like this should work (I didn't test it): 因此,这样的事情应该可以工作(我没有测试过):

:autocmd FileType nerdtree nnoremap <buffer> t :call nerdtree#invokeKeyMap("t")<Bar>TlistToggle<CR><C-W><C-T><C-W>K30<C-W>-

Here is the final solution I used to open a file in new tab from NERDTree and then split and resize the file & TlistToggle: 这是我用来从NERDTree的新选项卡中打开文件,然后拆分并调整文件大小和TlistToggle的最终解决方案:

autocmd FileType nerdtree nnoremap <buffer> t :call nerdtree#ui_glue#invokeKeyMap("t")<CR> :TlistToggle<CR> <C-w><C-t><C-w>K :exe "resize " . ((winheight(0) + winheight(1)) * 3/20)<CR>

And this resizes the tag list that was opened in a horizontal tab by 15% of the total amount of lines in the whole window. 这会将在水平选项卡中打开的标签列表的大小调整为整个窗口中行总数的15%。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM