Browse Source

Merge branch 'restore-cursor-position'

Marco Hinz 12 years ago
parent
commit
22edae78d1
2 changed files with 26 additions and 5 deletions
  1. 16 4
      autoload/startify.vim
  2. 10 1
      doc/startify.txt

+ 16 - 4
autoload/startify.vim

@@ -9,10 +9,11 @@ endif
 let g:autoloaded_startify = 1
 
 " Init: values {{{1
-let s:cmd          = (get(g:, 'startify_change_to_dir', 1) ? ' <bar> lcd %:h' : '') . '<cr>'
-let s:numfiles     = get(g:, 'startify_files_number', 10)
-let s:show_special = get(g:, 'startify_enable_special', 1)
-let s:session_dir  = resolve(expand(get(g:, 'startify_session_dir',
+let s:cmd              = (get(g:, 'startify_change_to_dir', 1) ? ' <bar> lcd %:h' : '') . '<cr>'
+let s:numfiles         = get(g:, 'startify_files_number', 10)
+let s:show_special     = get(g:, 'startify_enable_special', 1)
+let s:restore_position = get(g:, 'startify_restore_position')
+let s:session_dir      = resolve(expand(get(g:, 'startify_session_dir',
       \ has('win32') ? '$HOME\vimfiles\session' : '~/.vim/session')))
 
 " Function: #insane_in_the_membrane {{{1
@@ -70,6 +71,9 @@ function! startify#insane_in_the_membrane() abort
   endif
 
   autocmd startify CursorMoved <buffer> call s:set_cursor()
+  if s:restore_position
+    autocmd startify BufReadPost * call s:restore_position()
+  endif
 
   1
   call cursor((s:show_special ? 4 : 2) + s:offset_header, 5)
@@ -411,4 +415,12 @@ function! s:get_index_as_string(idx) abort
   endif
 endfunction
 
+" Function: s:restore_position {{{1
+function! s:restore_position() abort
+  autocmd! startify *
+  if line("'\"") > 0 && line("'\"") <= line('$')
+    call cursor(getpos("'\"")[1:])
+  endif
+endfunction
+
 " vim: et sw=2 sts=2

+ 10 - 1
doc/startify.txt

@@ -182,6 +182,14 @@ Default: does not exist
 Show <empty buffer> and <quit>.
 
 
+============-
+
+    let g:startify_restore_position = 0
+
+Jump to the last cursor position when opening a file. You don't need this, if
+you already have this in your vimrc: |last-position-jump|.
+
+
 ============-
 
     let g:startify_custom_indices = []
@@ -319,7 +327,8 @@ getting feedback! Same for issues or feature requests.
 
 Thank you for flying mhi airlines. Get the Vim on!
 
-You can also follow me on Twitter: [@_mhinz_](https://twitter.com/_mhinz_)
+You can also follow me on Twitter: @_mhinz_
+
 
 ==============================================================================
 8. License                                                    *startify-license*