Skip to content

Instantly share code, notes, and snippets.

@iansinnott
Created July 1, 2015 19:31
Show Gist options
  • Save iansinnott/06d18951bc086994a205 to your computer and use it in GitHub Desktop.
Save iansinnott/06d18951bc086994a205 to your computer and use it in GitHub Desktop.
Vim Stuff
" When opening a buffer open to the last line where the cursor was when
" exiting. See :help last-position-jump for more.
" NOTE: This opens with the cursor in the correct spot, but does not
" automcatically open folds.
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
@iansinnott
Copy link
Author

Using this autocommand Vim will remember the last position of the cursor in a file and return to that location when you re-open the file. It's very useful for having immediate context on what you were working on last time the file was open.

@slashfoo
Copy link

slashfoo commented Jul 1, 2015

I'd add a if &filetype !~ '^git\c' && to the if statement, that way you don't get that for gitcommit messages and git related files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment