remap NERDTree Double Click to 'T'

后端 未结 2 1844
别跟我提以往
别跟我提以往 2021-02-05 21:08

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)?

2条回答
  •  长发绾君心
    2021-02-05 21:41

    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   <2-leftmouse> :call activateNode(0)
    

    with:

    nnoremap   <2-leftmouse> :call openInTabAndCurrent(0,1)
    

    You can find this line in the function s:bindMappings() in the file NERD_tree.vim.

提交回复
热议问题