1

In a netrw listing, when I press - key to go up a directory, I would like the cursor placed on the line corresponding to the dir I have just left (exactly how happens on some file managers, e.g. Nemo).

For example: I'm in a directory named 'foo', I press - and on the listing of parent dir, the cursor is placed on the line corresponding to 'foo/'.

Is there a way to instruct netrw to do so?

2

After some attempts, I found a tailored solution which works for me (feel free to improve on it).

I save the name of current directory, go up dir, then search the name of saved cwd (with trailing /) to place the cursor on previous directory name line.
Also I mapped this key-sequence to the <Backspace> key (to be active on a netrw buffer only).

Here is the line I added to my .vimrc file:

au FileType netrw nmap <buffer> <Backspace> :let @z=expand("%:t")<CR>-/\<<C-R>=@z<CR>/\><CR>

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.