rojomoke
rojomoke

Reputation: 4015

Keeping view of edited file after exiting vim

When I quit vim, the display reverts to whatever I was seeing before I entered. On non-vim vi, you keep the vi screen intact except for the bottom line.

Is there an option in vim that allows that latter behaviour?

Upvotes: 4

Views: 1836

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172520

Vim uses a terminal feature called the alternate screen to write its UI there, and restore the original shell contents (where Vim was launched from) on exit. This is controlled by two ANSI escape sequences (see how does vi restore terminal content after quitting it).

You can disable that from within Vim by clearing the corresponding terminal settings. Put the following into your ~/.vimrc:

set t_ti= t_te=

Alternatively, you could also disable this capability in the terminal; at least the multiplexers screen and tmux allow this. See Prevent Applications Like Vim and Less Clearing Screen on Exit for details. For example, for tmux, add set-window-option -g alternate-screen off to your .tmux.conf; for screen, add alterscreen off to your .screenrc.

Upvotes: 7

imbichie
imbichie

Reputation: 1606

May be this is what you are looking for, just paste the below commands in your .vimrc. I got it from some where in the net.

" Return to last edit position when opening files
  autocmd BufReadPost *
       \ if line("'\"") > 0 && line("'\"") <= line("$") |
       \   exe "normal! g`\"" |
       \ endif

Upvotes: -2

Related Questions