Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  58] [ 0]  / answers: 1 / hits: 36748  / 2 Years ago, thu, february 10, 2022, 3:45:59

I just moved from RH/Fedora to Ubuntu 12.04. In RedHat, when I reopen a file with VIM, it opens with the cursor on the line it was on when I closed the file. However, what I am seeing now is that when I reopen a file, the cursor is always at the top, every time. As some of the files I am working with are 20k lines long, this gets a bit old quickly.



I installed the full version of VIM via apt-get on my new Ubuntu so that I could use the arrow keys in insert mode. The version that is printed out is VIM - Vi IMproved 7.3.



Any help at all would be gratefully welcomed.


More From » vim

 Answers
0

Add the following lines to your ~/.vimrc or global /etc/vim/vimrc



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


This will jump to the last known cursor position unless:




  • the position is invalid

  • the position is inside an event handler


[#34921] Saturday, February 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ularousand

Total Points: 380
Total Questions: 109
Total Answers: 101

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;