0

When I open a directory in netrw by opening vim like vim ., it will show me a list of files in the current directory. If I find a file then press t it will open that file in a new tab, when I'm done, I'll close the file with :q, then the netrw tab will be shown again but my cursor will be at the top, not over the file I just opened. How do I get it to not move the cursor?

4
  • Following your description, my cursor stays on the same file
    – Maxim Kim
    Commented May 19, 2022 at 8:47
  • Have a look at How to debug my vimrc and How to debug a mapping to make sure nothing is interfering
    – D. Ben Knoble
    Commented May 19, 2022 at 15:13
  • What version of vim/netrw are you on? I'm on 8.2/168. and I removed my .vim/.vimrc away and it still happens.
    – Jake
    Commented May 19, 2022 at 16:44
  • Personally with 8.2.4699 (netrw dates to 9th Feb 2021 according to header) I don't have the issue you describe; instead, the cursor stays on the file.
    – D. Ben Knoble
    Commented May 19, 2022 at 20:47

1 Answer 1

0

I had to add the following line in my .vimrc:

let g:netrw_fastbrowse = 2

When that variable is set to 2, it will not refresh the listing every time you enter the buffer, and so it will not position your cursor at the top of the screen.

Extra info:

I found within netrw there's an autocommand like this:

au BufEnter *  sil call s:LocalBrowse(expand("<amatch>"))

not sure what it's trying to do, but if I disable it, makes my cursor stay where I want it to be. So I wrote a file in ~/.vim/after/plugin/netrw.vim with this line:

au! FileExplorer BufEnter

while this works with starting vim like vim . it doesn't work when running something like :e . once inside vim. So the better solution is to set the variable above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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