重新映射NERDTree双击到'T'

evo*_*ion 11 vi vim nerdtree

使用VIM NERDTree插件.

有没有办法重新映射双击文件操作以在新选项卡(T)中静默打开文件?

jen*_*-na 7

1简介

这适用于NERD树版本4.2.0.

2在新选项卡中打开目录和文件

如果您想在新选项卡中打开目录文件,只需将以下行添加到您的~/.vimrc.

let g:NERDTreeMapOpenInTabSilent = '<2-LeftMouse>'
Run Code Online (Sandbox Code Playgroud)

3仅在新选项卡中打开文件

如果你只是想打开的文件在一个新的标签,你必须做一些事情更复杂.

在以下位置添加此功能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
Run Code Online (Sandbox Code Playgroud)

并更换线

nnoremap <silent> <buffer> <2-leftmouse> :call <SID>activateNode(0)<cr>
Run Code Online (Sandbox Code Playgroud)

有:

nnoremap <silent> <buffer> <2-leftmouse> :call <SID>openInTabAndCurrent(0,1)<cr>
Run Code Online (Sandbox Code Playgroud)

您可以s:bindMappings()在文件中的函数中找到此行NERD_tree.vim.