Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer

Put this in your .vimrc :

if has("autocmd")
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") X= line("$") |
  \   exe "normal g'\"" |
  \ endif

Just change the big X with <.

If I put < the code fails to print correctly.

share|improve this answer
+1. As a BTW, you can read more on this from :help last-position-jump. – DaveParillo Feb 19 '10 at 23:46
Also, this command ('") is not available in vi, which might be why sixtyfootersdude's vi is not behaving like this by default. It's the default behavior in vim. – DaveParillo Feb 19 '10 at 23:48
+1: Thanks for the response but I think that I found a simpler solution (by mistake) – sixtyfootersdude Feb 24 '10 at 15:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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