I have NERDTree opened on the default left side, and some vim file on the right side. After I do search with Ag like :Ag! "echo" I get results in the quickfix window. I chose one of the results and by pressing "e" it opens it to the right side and close the quickfix window, but cursor goes to the left side where the NERDTree is located. Is there a way to jump to opened file right after I click "e" and not pressing "ctrl+w" and "l"?
I have the same setup (NERDTree and Ag) and hadn’t noticed this behavior. My workflow is to open a file and then open NERDTree (or vice versa), then Ag at some point. And pressing Enter
or e
just took me to the line in the file, as expected. The key is that I have some file already open.
I can reproduce the problem you’re seeing by firing up Vim with no file, then opening NERDTree, then running Ag. So a workaround is to have some file open first -- not just an empty Vim with NERDTree open.
The workaround is pretty, uh, workable. It’s already natural to open and close NERDTree frequently. A useful mapping for this is:
nmap <Leader>n :NERDTreeToggle<CR>
An alternative mnemonic would be <Leader>e
for Explore. And while we’re at it:
nmap <Leader>g :Ag!<CR>
So the sequence to grep (if you have NERDTree open but no buffer open) is simply ,n,g
(assuming your leader is ,
).