sponsor Vim development Vim logo Vim Book Ad

lastpos.vim : Last position jump improved for Easy Vim

 script karma  Rating 7/4, Downloaded by 1165  Comments, bugs, improvements  Vim wiki

created by
Andy Wokula
 
script type
utility
 
description
With Easy Vim [1], the code to perform a last position jump [2] can't restore a cursor position beyond EOL, because the jump will be executed in Normal mode [3].  The result in this case is a by-one error [4], so most people [5] won't find that annoying ...

The good news is that Vim seems to store a correct value in the viminfo file -- one solution is to restore the last position while in Insert mode, which is what the plugin does.

Easy Vim actually is not required, the plugin will also work with a normal setup, or when you use  :startinsert  in the vimrc to merely start up in Insert mode.

The code is slightly more cautious than the original: the cursor won't be moved if something else already moved it, or if the buffer is special (help buffer, etc.).  Furthermore, to fix [6] a related case [7], the BufWinEnter autocommand is used instead of BufReadPost.

This lengthy description applies for a rather short piece of code.

[1] :help 'insertmode' or :help -y
[2] :h last-position-jump
[3] explanation http://groups.google.com/group/vim_use/msg/c571f994f211f8fe
[4] the position is almost right, no issue for Bram: http://groups.google.com/group/vim_dev/msg/fbcffe406ff01b7f
[5] especially of the few Easy vimmers
[6] not sure if "modify" is the better word as what follows is probably not a bug
[7] Cursor column not remembered ... http://groups.google.com/group/vim_dev/msg/b3512cecaab3e0b1
 
install details
Drop the file into your plugin folder, restart Vim.

For newbies: this folder could be ~\vimfiles\plugin -- replace '~\vimfiles' with the first entry of your 'runtimepath'.

If you are using the example vimrc :help vimrc_example.vim, you may have

autocmd BufReadPost *
  \ if line("'\"") > 1 && line("'\"") <= line("$") |
  \  exe "normal! g`\"" |
  \ endif

in your vimrc – make sure to remove this old code.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
lastpos.vim 0.6 2010-04-15 7.0 Andy Wokula Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github