Przeglądaj źródła

Fix vim position restore checking for mark badly

Bad mark handling meant it was throwing errors sometimes in netrw. The "new"
version comes from vim's help files itself. The previous bad version was from
the vim wiki.
Weiyi Lou 10 lat temu
rodzic
commit
0f525b1738
1 zmienionych plików z 6 dodań i 27 usunięć
  1. 6 27
      vim/settings/cursorposition.vim

+ 6 - 27
vim/settings/cursorposition.vim

@@ -1,36 +1,15 @@
-" Cursor Position - Modeline and Notes {{{
-" vim: set sw=2 ts=2 sts=2 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell:
-"
-"   cinaeco/dotfiles Cursor Position from last editing session.
-"
-"   Taken from spf13-vim.
-"
-" }}}
-
-" Cursor Autocommands {{{
 if has("autocmd")
 
-  " Restore Position {{{
-  " http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
-  " Restore cursor to file position in previous editing session
-  function! ResCur()
-    if line("'\"") <= line("$")
-      normal! g`"
-      return 1
-    endif
-  endfunction
-
-  augroup resCur
-    autocmd!
-    autocmd BufWinEnter * call ResCur()
-  augroup END
-  " }}}
+  " Restore Position
+  " Based on the last-position mark '"'. Go to it if it is not the first line,
+  " and if it is valid i.e. within the number of lines in the file.
+  " From `:help line()`
+  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
 
-  " Git Commit Exception{{{
+  " Git Commit Exception
   " Instead of reverting the cursor to the last position in the buffer, we
   " set it to the first line when editing a git commit message
   au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
-  " }}}
 
 endif
 " }}}