Sử dụng VIM NERDTree Plugin.remap NERDTree Nhấp đúp vào 'T'
Có cách nào để remap Nhấp đúp vào hành động Tệp để mở tệp âm thầm trong tab mới (T)?
Sử dụng VIM NERDTree Plugin.remap NERDTree Nhấp đúp vào 'T'
Có cách nào để remap Nhấp đúp vào hành động Tệp để mở tệp âm thầm trong tab mới (T)?
1 Giới thiệu
này làm việc cho NERD cây phiên bản 4.2.0.
2 thư mục mở và các tập tin trong một tab mới
Nếu bạn muốn mở thư mục và tập tin trong một tab mới, bạn chỉ cần thêm dòng sau vào ~/.vimrc
của bạn.
let g:NERDTreeMapOpenInTabSilent = '<2-LeftMouse>'
3 file Chỉ mở trong một tab mới
Nếu bạn chỉ muốn mở file trong một tab mới, bạn phải làm một cái gì đó phức tạp hơn.
Thêm chức năng này ở đâu đó trong 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
và thay thế dòng
nnoremap <silent> <buffer> <2-leftmouse> :call <SID>activateNode(0)<cr>
với:
nnoremap <silent> <buffer> <2-leftmouse> :call <SID>openInTabAndCurrent(0,1)<cr>
Bạn có thể tìm dòng này trong hàm s:bindMappings()
trong file NERD_tree.vim
.
Mặc dù phiên bản NERDtree của tôi cũng được báo cáo là 4.2.0 (git nhân bản 2015-07-22), dường như đã có một số tái cấu trúc chính trong thời gian đó, do đó giải pháp của jens-na trong phần (3) đã không chuyển giao (nhưng vẫn không có vẻ là một giải pháp out-of-the-box, một trong hai). Tôi đã phải thay thế một dòng trong autoload/nerdtree/ui_glue.vim, theo sự khác biệt dưới đây. (Lưu ý: thử nghiệm trên MacVim)
--- .vim/bundle/nerdtree/autoload/nerdtree/ui_glue.vim.backup 2015-07-22 19:39:53.000000000 +0200
+++ .vim/bundle/nerdtree/autoload/nerdtree/ui_glue.vim 2015-07-22 19:40:44.000000000 +0200
@@ -10,7 +10,7 @@
call NERDTreeAddKeyMap({ 'key': '<MiddleRelease>', 'scope': "all", 'callback': s."handleMiddleMouse" })
call NERDTreeAddKeyMap({ 'key': '<LeftRelease>', 'scope': "all", 'callback': s."handleLeftClick" })
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "DirNode", 'callback': s."activateDirNode" })
- call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."activateFileNode" })
+ call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "FileNode", 'callback': s."openInNewTab" })
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "Bookmark", 'callback': s."activateBookmark" })
call NERDTreeAddKeyMap({ 'key': '<2-LeftMouse>', 'scope': "all", 'callback': s."activateAll" })
Điều này có vẻ là cách duy nhất để làm điều đó cho NERDTree hiện tại, cũng không có vấn đề với nhấp đúp chuột vào dirs (sử dụng Linux với GVim). – kjyv
Shift + t trên bất kỳ tệp nào trong NERDTree. Oh xin lỗi, chỉ cần đọc lại câu hỏi. Bạn yêu cầu ánh xạ và không chỉ âm thầm mở tệp. Đang thử – kiddorails
Có thể bạn sẽ cần chỉnh sửa [mã của NERDTree] (https://github.com/scrooloose/nerdtree/blob/master/plugin/NERD_tree.vim#L2869) của chính mình. – romainl