Rewrite last-position-jump section

This commit is contained in:
Marco Hinz 2017-04-23 16:37:22 +02:00
parent 6bef4e23da
commit 6999e71040
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F

View File

@ -1497,23 +1497,23 @@ Help:
## Restore cursor position when opening file ## Restore cursor position when opening file
Without this, you will always be at line 1 when opening a file. With this, you When you open a file, the cursor will be positioned at line 1, column 1.
will be at the position where you left off. Fortunately the viminfo file remembers [marks](#marks). The `"` mark contains
the position in the buffer where you left off.
Put this in your vimrc:
```vim ```vim
autocmd BufReadPost * autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") | \ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" | \ execute "normal! g`\"" |
\ endif \ endif
``` ```
This simply does `` g`" `` (jump to position where you left off without changing Read: If the mark `"` contains a line number greater than line 1 but not greater
jumplist) if that position still exists (the file might have fewer lines since than the last line in the file, jump to it.
it was altered by another program).
This requires the use of a viminfo file: `:h viminfo-'`. :h viminfo-'
:h `quote
:h g`
## Temporary files ## Temporary files