如何使 Vim 插件 NERDTree 的 <CR> 表現得更像 `go`? (How to make Vim plugin NERDTree's <CR> behave more like `go`?)


問題描述

如何使 Vim 插件 NERDTree 的 表現得更像 go? (How to make Vim plugin NERDTree's behave more like go?)

在 NERDTree 中, 與快捷方式 o 相同,在其幫助文檔中描述如下:

Default key: o
Map option: NERDTreeMapActivateNode
Applies to: files and directories.

If a file node is selected, it is opened in the previous window.

If a directory is selected it is opened or closed depending on its current
state.

If a bookmark that links to a directory is selected then that directory
becomes the new root.

If a bookmark that links to a file is selected then that file is opened in the
previous window.

我想打開一個文件,光標只保留在 NERDTree 中

我發現這只是快捷鍵 go 所做的操作。但是go只能應用於files,而o應用於文件和目錄

在 NERDTree 的幫助文檔中:

Default key: go
Map option: None
Applies to: files.

If a file node is selected, it is opened in the previous window, but the
cursor does not move.

The key combo for this mapping is always "g" + NERDTreeMapActivateNode (see
NERDTree‑o).

更具體地說,我希望 在應用於 目錄時表現得像 o gofiles.

沒有 Customisation 標誌可以做到這一點。

有沒有什麼好的方法來實現它,包括修改源腳本?

非常感謝!


參考解法

方法 1:

It seems that it can be accomplished using custom mappings which unfortunately cannot be defined usual way in your .vimrc. You need to distinguish if the node is a 'FileNode' or a 'DirNode' so the mappings must be specified in a file like ~/.vim/nerdtree_plugin/mymappings.vim.

call NERDTreeAddKeyMap({
    \ 'key': '<CR>', 
    \ 'scope': 'DirNode',
    \ 'callback': 'NERDTreeCustomActivateDirNode',
    \ 'quickhelpText': 'open or close a dirctory',
    \ 'override': 1 })

function! NERDTreeCustomActivateDirNode(node)
    call a:node.activate()
endfunction

call NERDTreeAddKeyMap({
    \ 'key': '<CR>',
    \ 'scope': 'FileNode',
    \ 'callback': 'NERDTreeCustomPreviewNodeCurrent',
    \ 'quickhelpText': 'open a file with the cursor in the NERDTree',
    \ 'override': 1 })

function! NERDTreeCustomPreviewNodeCurrent(node)
    call a:node.open({'stay': 1, 'where': 'p', 'keepopen': 1})
endfunction

I found the inspiration in /autoload/nerdtree/ui_glue.vim.

(I don't have NERDTree so it is not tested.)

(by Daizyryuichiro)

參考文件

  1. How to make Vim plugin NERDTree's behave more like go? (CC BY‑SA 2.5/3.0/4.0)

#mapping #nerdtree #vim






相關問題

Hibernate 單向父/子關係 - delete() 對子表執行更新而不是刪除 (Hibernate Unidirectional Parent/Child relationship - delete() performs update on child table instead of delete)

TIGER shapefile - 使用和解釋 (TIGER shapefiles - using and interpreting)

查找位置的城市和郵政編碼 (Finding City and Zip Code for a Location)

如何使 Vim 插件 NERDTree 的 <CR> 表現得更像 `go`? (How to make Vim plugin NERDTree's <CR> behave more like `go`?)

在 NHibernate 上的多對多關係上添加自定義列 (Add custom columns on many to many relationship on NHibernate)

在大型 .NET 項目中管理 DTO 和映射 (Managing DTOs and mapping in large .NET project)

使用 Fluent NHibernate 進行繼承映射 (Inheritance Mapping with Fluent NHibernate)

Biztalk映射問題,請想法 (Biztalk Mapping Problem, Ideas please)

BizTalk 數據庫查找 functoid 固定條件 (BizTalk Database Lookup functoid fixed condition)

EntityFramework FluentAPI 映射問題 (EntityFramework FluentAPI mapping issue)

將外鍵添加到現有數據庫 (Adding foreign keys to an already existing database)

如何重命名對像數組中對象的所有鍵? (How does one rename all of an object's keys within an array of objects?)







留言討論