Closed Hritik14 closed 10 months ago
This can be achieved by chaining these commands, Maybe it's not the prettiest approach, But it will do exactly what you want(If I'm not mistaken about your situation)
map <C-f> :NERDTreeVCS \| NERDTreeClose \| NERDTreeFind<CR>
Let me know if it didn't fix your problem, In that case, we can work on something else together.
@Hritik14 You should use |
when you are entering the command directly, and escape it like this \|
if you are using it in your config file(for example using as a custom binding), In addition to \|
you may also use <bar>
.
So either do :NERDTreeVCS | NERDTreeClose | NERDTreeFind
or use something like this map <C-f> :NERDTreeVCS \| NERDTreeClose \| NERDTreeFind<CR>
in your .vimrc/init.vim
to bind these commands to <C-f>
(or your preferred short cut)
@Hritik14 Have you found this answer to solve your problem? If that's the case I would appreciate it if you go ahead and close your issue.
@rzvxa thanks, this seems to work partially with two problems
q
to quitI tried solving (1) by adding NERDTreeFocus
but to no avail. Although, the original command, when issued from vim without hotkey focuses NERDTree (https://asciinema.org/a/ueYAkoBDOiCioTPGTI9tmv2vU)
@rzvxa thanks, this seems to work partially with two problems
1. Cursor does not switch to NERDTree (https://asciinema.org/a/FHm3cAqoulmYVbZwenZJVAW7J) 2. I cannot toggle nerdtree, need to use `q` to quit
I tried solving (1) by adding
NERDTreeFocus
but to no avail. Although, the original command, when issued from vim without hotkey focuses NERDTree (https://asciinema.org/a/ueYAkoBDOiCioTPGTI9tmv2vU)
that's weird with my setup it works correctly(both get focus and toggle with NERDTreeToggle) would you kindly provide some minimal vim config to reproduce this? try to remove as many lines as possible in your vimrc / init.vim What is your operating system and what version of Vim / Neovim do you use? Currently, I'm using Neovim as my daily driver so it may be a vim specific issue. Anything that can help me with narrowing the problem and get it to be reproducible on my machine can help(I can test on both Linux and Windows but I don't have a Mac machine so I can't really help with Macvim)
@rzvxa (1)
is working now. I don't know what went wrong earlier. Thanks.
Although, cannot toggle with the same key mapping (ie <C-f>
above). I can use a different hotkey for that or q
. thanks
for toggling you can use this:
map <C-f> :if g:NERDTree.IsOpen() \| NERDTreeClose \| else \| NERDTreeVCS \| NERDTreeClose \| NERDTreeFind \| endif<cr>
or you can go the extra mile and do it the "right" way:
function! s:NERDTreeFindVCSToggle() abort
if g:NERDTree.IsOpen()
execute("NERDTreeClose")
else
execute("NERDTreeVCS | NERDTreeClose | NERDTreeFind")
endif
endfunction
command NERDTreeFindVCSToggle call s:NERDTreeFindVCSToggle()
map <C-f> :NERDTreeFindVCSToggle<cr>
Hello, I'm looking for a command like
:NERDTreeFindVCSToggle
it is essentially like:NERDTreeFind
but also ensures VCS root is used and it toggles nicely when assigned to a hotkey.I looked at the code and I think this can be implemented by:
NERDTreeFocus
fromfindAndRevealPath
. This will ensure we do not always want toNERDTreeFocus
but at times wantNERDTreeToggle
instead. Here: https://github.com/preservim/nerdtree/blob/32168889bdbc1e7d1d313e3e41c1cc794b38eac5/autoload/nerdtree/ui_glue.vim#L332NERDTreeFocusToggle
now that we have the above decoupledNERDTreeFocusToggleVCS
using next steps:NERDTreeFocusToggle
I don't have any experience in writing vim plugins so this might not be the best way to do it. If so, can someone guide me please?