Skip to content

Commit

Permalink
Vastly improve <leader>ne
Browse files Browse the repository at this point in the history
Now <leader>ne does two additional things:
  1. It makes the opened NERDtree the implicit NERDTree for commands
    like NERDTreeFind
  2. When the current buffer is a file, it expands the tree to that
    file.  This plays particularly well with fzf
  • Loading branch information
hjdivad committed Apr 16, 2020
1 parent bfccecf commit f030f34
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions config/nvim/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Plug 'fszymanski/fzf-quickfix'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'

Plug 'scrooloose/nerdtree'
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

" Formatting
Expand Down Expand Up @@ -517,6 +517,24 @@ augroup EnterKeyManager
augroup end
call s:install_enter_hook()

function s:OpenNERDTree()
let isFile = (&buftype == "") && (bufname() != "")

if isFile
let findCmd = "NERDTreeFind " . expand('%')
endif

" open a NERDTree in this window
edit .

" make this the implicit NERDTree buffer
let t:NERDTreeBufName=bufname()

if isFile
exe findCmd
endif
endfunction

" use coc.vim for K doc lookup
nnoremap <silent> K :call <SID>show_documentation()<CR>
nmap <leader>gd <Plug>(coc-definition)
Expand Down Expand Up @@ -545,7 +563,7 @@ nmap <leader>hn :GitGutterNextHunk<CR>
nmap <Leader>hp :GitGutterPrevHunk<CR>
nmap <Leader>hu :GitGutterUndoHunk<CR>
nmap <Leader>hP :GitGutterPreviewHunk<CR>
nmap <leader>ne :edit .<CR>
nmap <leader>ne :call <SID>OpenNERDTree()<CR>
nmap <leader>nt :NERDTreeFocus<CR>
nmap <leader>nf :NERDTreeFind<CR>
nmap <leader>ln <Plug>(coc-diagnostic-next)<CR>
Expand Down

0 comments on commit f030f34

Please sign in to comment.