gpt4 book ai didi

vim - 将 NERDTree 双击重新映射到 'T'

转载 作者:行者123 更新时间:2023-12-01 18:50:50 24 4
gpt4 key购买 nike

使用 VIM NERDTree 插件。

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

最佳答案

1 简介

这适用于 NERD 树版本 4.2.0 .

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

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

let g:NERDTreeMapOpenInTabSilent = '<2-LeftMouse>'

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

并替换该行

nnoremap <silent> <buffer> <2-leftmouse> :call <SID>activateNode(0)<cr>

与:

nnoremap <silent> <buffer> <2-leftmouse> :call <SID>openInTabAndCurrent(0,1)<cr>

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

关于vim - 将 NERDTree 双击重新映射到 'T',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10670111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com