3

假设我在 Vim 的 NERDTree 中有以下目录结构:

/some/folder/
|-apples.txt
|-bananas.txt
|- ...
|-mandarins.txt
|-mangos.txt
|- ...
|-strawberry.txt
`-watermelon.txt

我的光标在顶层目录上,我想跳到mandarins.txt. 如何通过尽可能少的击键来实现这一点?

4

2 回答 2

7

NERDTree 窗口包含一个特殊的缓冲区,带有filetype=nerdtree.
在此窗口/缓冲区中,NERDTree 重新映射您的键。
您仍然可以使用/patternto 搜索模式。
点击Enter文件名,将打开它。


您可以键入/mand,然后按Enter两次。

于 2012-06-13T08:07:43.873 回答
1

我并不完全喜欢搜索的解决方案,因为它突出显示了您在所有打开的窗口中的搜索,而且我认为“跳跃”应该可以用更少的击键来实现。

因此,感谢kevepsilonhable的输入,我编写了一个简单的文件类型插件,将以下脚本放入~/.vim/ftplugin/nerdtree.vim

" Quick jump to first item starting with X
function! s:NERDJump(search, backwards)
    if a:backwards
        :silent! :exe '?\c\(|\|`\)\(\~\|+\|-\)'.a:search
    else
        :silent! :exe '/\c\(|\|`\)\(\~\|+\|-\)'.a:search
    end 
endfunction
command! -nargs=* NERDJump call s:NERDJump(<f-args>)

" Search forwards
nmap <buffer> na :NERDJump a 0<CR>
nmap <buffer> nb :NERDJump b 0<CR>
nmap <buffer> nc :NERDJump c 0<CR>
nmap <buffer> nd :NERDJump d 0<CR>
nmap <buffer> ne :NERDJump e 0<CR>
nmap <buffer> nf :NERDJump f 0<CR>
nmap <buffer> ng :NERDJump g 0<CR>
nmap <buffer> nh :NERDJump h 0<CR>
nmap <buffer> ni :NERDJump i 0<CR>
nmap <buffer> nj :NERDJump j 0<CR>
nmap <buffer> nk :NERDJump k 0<CR>
nmap <buffer> nl :NERDJump l 0<CR>
nmap <buffer> nm :NERDJump m 0<CR>
nmap <buffer> nn :NERDJump n 0<CR>
nmap <buffer> no :NERDJump o 0<CR>
nmap <buffer> np :NERDJump p 0<CR>
nmap <buffer> nq :NERDJump q 0<CR>
nmap <buffer> nr :NERDJump r 0<CR>
nmap <buffer> ns :NERDJump s 0<CR>
nmap <buffer> nt :NERDJump t 0<CR>
nmap <buffer> nu :NERDJump u 0<CR>
nmap <buffer> nv :NERDJump v 0<CR>
nmap <buffer> nw :NERDJump w 0<CR>
nmap <buffer> nx :NERDJump x 0<CR>
nmap <buffer> ny :NERDJump y 0<CR>
nmap <buffer> nz :NERDJump z 0<CR>

" Search backwards
nmap <buffer> Na :NERDJump a 1<CR>
nmap <buffer> Nb :NERDJump b 1<CR>
nmap <buffer> Nc :NERDJump c 1<CR>
nmap <buffer> Nd :NERDJump d 1<CR>
nmap <buffer> Ne :NERDJump e 1<CR>
nmap <buffer> Nf :NERDJump f 1<CR>
nmap <buffer> Ng :NERDJump g 1<CR>
nmap <buffer> Nh :NERDJump h 1<CR>
nmap <buffer> Ni :NERDJump i 1<CR>
nmap <buffer> Nj :NERDJump j 1<CR>
nmap <buffer> Nk :NERDJump k 1<CR>
nmap <buffer> Nl :NERDJump l 1<CR>
nmap <buffer> Nm :NERDJump m 1<CR>
nmap <buffer> Nn :NERDJump n 1<CR>
nmap <buffer> No :NERDJump o 1<CR>
nmap <buffer> Np :NERDJump p 1<CR>
nmap <buffer> Nq :NERDJump q 1<CR>
nmap <buffer> Nr :NERDJump r 1<CR>
nmap <buffer> Ns :NERDJump s 1<CR>
nmap <buffer> Nt :NERDJump t 1<CR>
nmap <buffer> Nu :NERDJump u 1<CR>
nmap <buffer> Nv :NERDJump v 1<CR>
nmap <buffer> Nw :NERDJump w 1<CR>
nmap <buffer> Nx :NERDJump x 1<CR>
nmap <buffer> Ny :NERDJump y 1<CR>
nmap <buffer> Nz :NERDJump z 1<CR>

mandarins.txt现在我可以按跳到nm

于 2012-06-18T07:55:40.110 回答