mirror of
https://github.com/mhinz/vim-galore.git
synced 2025-02-24 01:59:28 +08:00
Rewrite last-position-jump section
This commit is contained in:
parent
6bef4e23da
commit
6999e71040
18
README.md
18
README.md
@ -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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user