I am looking to jump automatically to the last position in any file that I open.

I have in my ~/.vimrc file:

autocmd BufReadPost *                                                                                                                                                                                   
  \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \ exe "normal! g`\"" |
  \ endif

This works fine if I open a file using the vim command.

But if I write vim . in a directory to load netrw and use t to open a file in a new tab, the cursor appears at the top of the file and not at the last position.

I then have to use `" to jump to the last position.

Is there any way to jump to the last position when using netrw and t?


  • 1
    Simple answer would be to map t in netrw buffer to open the file under cursor in a new tab and do '".
    – 3N4N
    Apr 3, 2019 at 18:12
  • 1
    I had some trouble remapping. I added to my ~/.vimrc file autocmd FileType netrw noremap <buffer> t j just to test, and t does get mapped to j. But when I tried to map anything to t, e.g., autocmd FileType netrw noremap <buffer> j t or even autocmd FileType netrw noremap <buffer> t t, nothing happens. In any case, I found an easy workaround. Just adding to ~/.vimrc let g:netrw_browse_split = 3 allows me to hit enter to open the file in a new tab and jump to the last position. Apr 4, 2019 at 13:54
  • Glad it worked. And the reason mapping j to t wasn't working is because you were using noremap. t was already a mapping, you either needed to use nremap or, more appropriately, find out what command was netrw-t mapped to and map j to that command directly.
    – 3N4N
    Apr 4, 2019 at 14:21
  • Thanks. Actually, nremap did not work, either, but I did instead incorporate this: vi.stackexchange.com/questions/13344/…. I just added ``\"` to a couple of lines to get let command .= "t\"gT:" . ( a:firstline + i ) . "\<CR>:+tabmove\<CR>"` and let command .= "t\"gT". This does not change the mapping for t, but it works well. I might look into the t` mapping later. Apr 4, 2019 at 17:53


Your Answer

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

Browse other questions tagged or ask your own question.