Azazia Software Knowledgebase
Search:     Advanced search
Browse by category:
Contact Us

Restoring the cursors last position in the VI (VIM) editor

Add comment
Views: 27
Votes: 0
Comments: 0
Posted: 22 Jul, 2010
by: Patridge B.
Updated: 22 Jul, 2010
by: Patridge B.
To add Colors, line numbers, and restore the cursors last position in the VI editor, you place the following into a .vimrc file in your $HOME directory.

--------------------------------------------------------------------
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
  set number
end
" Tell vim to remember certain things when we exit
"  '10 : marks will be remembered for up to 10 previously edited files
"  "100 : will save up to 100 lines for each register
"  :20 : up to 20 lines of command-line history will be remembered
"  % : saves and restores the buffer list
"  n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo

" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
 au!
 autocmd BufReadPost *
 \ if expand("<afile>:p:h") !=? $TEMP |
 \ if line("'\"") > 1 && line("'\"") <= line("$") |
 \ let JumpCursorOnEdit_foo = line("'\"") |
 \ let b:doopenfold = 1 |
 \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
 \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
 \ let b:doopenfold = 2 |
 \ endif |
 \ exe JumpCursorOnEdit_foo |
 \ endif |
 \ endif
 " Need to postpone using "zv" until after reading the modelines.
 autocmd BufWinEnter *
 \ if exists("b:doopenfold") |
 \ exe "normal zv" |
 \ if(b:doopenfold > 1) |
 \ exe "+".1 |
 \ endif |
 \ unlet b:doopenfold |
 \ endif
augroup END
----------------------------------------------------------------
Others in this Category
document VI editor Backup (VIB) Utility
document E:Lists directory /var/lib/apt/lists/partial is missing.
document Regular Expression to Escape all Illegal (non alphanumeric) Characters Except a space
document Quick One liners to test a string whether or not it is an Integer, Alphanumeric, or Character
document Using Awk to display a directory listing on files with spaces until the end of line
document UNIX Command Line way to convert HEX ascii codes to Text
document Postfix/Sendmail Errors: NOQUEUE: reject: RCPT .... Relay access denied DSN: Service unavailable
document Display path, user name, and host name next to the cursor in the .bashrc or .bash_profile



RSS