I'd like to map NERDTree's tab opening key, 't', to do multiple things. 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. 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. 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:
:autocmd FileType nerdtree nnoremap t ...
While normal mode commands (like the <Cw>...
stuff) can indeed be concatenated, that's not true for the plugin invocations. You can find out NERDTree's via :nmap <buffer> t
:
:call nerdtree#invokeKeyMap("t")
The Taglist's is also an Ex command; you can combine both with |
(written as <Bar>
in mappings):
: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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.