重新映射 NERDTree 双击到“T" [英] remap NERDTree Double Click to 'T'
问题描述
使用 VIM NERDTree 插件.
有没有办法重新映射双击文件操作以在新选项卡中静默打开文件 (T)?
1 简介
这适用于 NERD 树版本 4.2.0.>
2 在新标签页中打开目录和文件
如果您想在新选项卡中打开目录和文件,您只需将以下行添加到您的~/.vimrc
.
let g:NERDTreeMapOpenInTabSilent = '<2-LeftMouse>'
3 只在新标签页中打开文件
如果您只想在新标签页中打开文件,您必须做一些更复杂的事情.
在 NERD_tree.vim
的某处添加这个函数:
" 在新标签页中打开文件" KeepWindowOpen - 即使设置了 NERDTreeQuitOnOpen 也不关闭窗口"stayCurrentTab: 如果为 1 则 vim 将留在当前选项卡中,如果为 0 则 vim" 将转到打开新文件的选项卡功能!s:openInTabAndCurrent(keepWindowOpen,stayCurrentTab)if getline(".") ==# s:tree_up_dir_line返回 s:upDir(0)万一让 currentNode = s:TreeFileNode.GetSelected()如果当前节点 != {}让 startToCur = strpart(getline(line(".")), 0, col("."))如果 currentNode.path.isDirectory调用 currentNode.activate(a:keepWindowOpen)返回别的调用 s:openInNewTab(a:stayCurrentTab)返回万一万一端功能
并替换该行
nnoremap <无声><缓冲区><2-左鼠标>:call activateNode(0)
与:
nnoremap <无声><缓冲区><2-左鼠标>:call <SID>openInTabAndCurrent(0,1)<cr>
您可以在 NERD_tree.vim
文件中的 s:bindMappings()
函数中找到这一行.
Using VIM NERDTree Plugin.
Is there any way to remap the Double Click on a File action to open the file silently in a new tab (T)?
1 Introduction
This works for NERD tree version 4.2.0.
2 Open directories and files in a new tab
If you would like to open directories and files in a new tab you can simply add the following line to your ~/.vimrc
.
let g:NERDTreeMapOpenInTabSilent = '<2-LeftMouse>'
3 Only open files in a new tab
If you only want to open files in a new tab you have to do something more sophisticated.
Add this function somewhere in NERD_tree.vim
:
" opens a file in a new tab
" KeepWindowOpen - dont close the window even if NERDTreeQuitOnOpen is set
" stayCurrentTab: if 1 then vim will stay in the current tab, if 0 then vim
" will go to the tab where the new file is opened
function! s:openInTabAndCurrent(keepWindowOpen, stayCurrentTab)
if getline(".") ==# s:tree_up_dir_line
return s:upDir(0)
endif
let currentNode = s:TreeFileNode.GetSelected()
if currentNode != {}
let startToCur = strpart(getline(line(".")), 0, col("."))
if currentNode.path.isDirectory
call currentNode.activate(a:keepWindowOpen)
return
else
call s:openInNewTab(a:stayCurrentTab)
return
endif
endif
endfunction
and replace the line
nnoremap <silent> <buffer> <2-leftmouse> :call <SID>activateNode(0)<cr>
with:
nnoremap <silent> <buffer> <2-leftmouse> :call <SID>openInTabAndCurrent(0,1)<cr>
You can find this line in the function s:bindMappings()
in the file NERD_tree.vim
.
这篇关于重新映射 NERDTree 双击到“T"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!