Home » Questions » Computers [ Ask a new question ]

Vim open file at location that was last viewed

Vim open file at location that was last viewed

When I close a file in vim and reopen it, the file opens at the start of the file. Is there anyway to make the file open at the last place the I viewed?

Asked by: Guest | Views: 116
Total answers/comments: 2
Guest [Entry]

"I just noticed that my cursor has started to have this behavior. I went through my vimrc (commenting out line by line) and found that this code will also work:

""make vim save and load the folding of the document each time it loads""
""also places the cursor in the last place that it was left.""
au BufWinLeave * mkview
au BufWinEnter * silent loadview

(Quotes finished to make it easier to read)

The main purpose of this block is to make any folds created appear again when a file is opened but apparently it also saves/loads the cursor position."
Guest [Entry]

There is a plugin called vim-lastplace (I am the author) that will open your files where you left off. It improves on the above suggestions by ignoring commit messages because you're typically editing a new message and want to start at the top of the commit message file.