2

How do I map <leader>r which clears CtrlP's cache and refreshes NERDTree's root directory?

Pseudo code, I have:

map <Leader>r :CtrlPClearCache<cr>g:NERDTreeMapRefreshRoot<cr>

CtrlPClearCache clears the cache, but I haven't found a command to refresh the root node of NERDTree, without being in a NERDTree window.

3

Refresh both CtrlP and NERDTree

I use a custom key map to refresh both NERDTree and CtrlP:

nmap <Leader>r :NERDTreeFocus<cr>R<c-w><c-p>:CtrlPClearCache<cr>

I've mapped it to Leader + r, but you can map it to whatever you want.


How it works:

  1. :NERDTreeFocus<cr> - Changes to the NERDTree window
  2. R - Refreshes the root node
  3. <c-w><c-p> - Goes back to the previously selected window
  4. :CtrlPClearCache<cr> - Refreshes the CtrlP cache

Note: Only works with recursive map versions (i.e. map or nmap instead of noremap or nnoremap)

| improve this answer | |
2

I guess you have to focus the NERDTree window in order to refresh the root. This should do the trick:

nnoremap <Leader>r :CtrlPClearCache<cr>call NERDTreeMapRefreshRoot()<cr>
function! NERDTreeMapRefreshRoot()
    if nerdtree#isTreeOpen()
        call nerdtree#putCursorInTreeWin()
        call nerdtree#invokeKeyMap('R')
        " Go back to previous window.
        wincmd p
    endif
endfunction
| improve this answer | |
  • Is there no way to refresh the node tree without the NERDTree window/buffer opened? – Christian Fazzini Mar 31 '15 at 16:38
  • You'd have to ask the plugin's author for a definitive answer (or go through the (quite complex) sources), but usually, there isn't, as most Vim commands operate on the current buffer only. – Ingo Karkat Mar 31 '15 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.