For a few years now at work I have been using the GNOME Terminal, and have gotten very used to that. I usually organize my work by categorizing each task on its own virtual desktop, then within each virtual desktop I have multiple Gnome Terminals each with multiple terminal tabs, most of which have a file open for editing.

This setup really makes it hard for me to reboot, and when I do, its a real pain trying to save what files I had opened and where. I have looked further into the GNOME Terminal, as well as Konsole, but as far as I can tell, neither of these terminal programs can do what I want. I want to be able to save a session in either GNOME or Konsole, but when I reload that session, the files that were previously open in VI, will be open in VI again. All they seem to do now, is just reload the directory that I was in, but not open the file in VI.

Is there a program that is capable of doing this, or perhaps a setting I am missing in either GNOME or Konsole that will allow for automatic reopening of files I had open in VI before closing the session?

  • 1
    This may be off-topic, but most of the time, those settings are uneeded because linux hosts hardly nerver need a reboot. – mveroone Sep 30 '13 at 12:14
  • @Kwaio I suppose its more for the scenario when my machine crashes. For instance, on Friday, all of my terminals just decided to crash, yet other programs remained open and unaffected. First time I have experienced that in 3 years of using this machine though. – halexh Sep 30 '13 at 12:23
  • You could create a directory of symlinks to the files you want openned, and make a script on startup that opens them all. just an idea – mveroone Sep 30 '13 at 14:43

Did you try to store it on a session?

:h session

its better you ask on http://unix.stackexchange.com, however i found some good links on the internet...you should take a look on those following links.

stackoverflow link - Save and Restore vim state

vim configuration

all important VI commands


With Vim, you can run :mksession to save your current session, i.e., mappings, options, variables, current directory, tabs, windows (and their layouts), etc. This saves all the session information into a file in the current directory called Session.vim (you can provide a filename to the :mksession command if you want to save different sessions in different files, e.g., :mksession work-task.vim). Since the information is stored in a file, it will persist after a restart of the computer.

To restore your session the next time you start Vim, simply run, :source Session.vim or :source work-task.vim

See Vim’s help session-file for full details.


The following in your .vimrc will save sessions on exit and restore them on startup:

function! MakeSession()
  let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
  if (filewritable(b:sessiondir) != 2)
    exe 'silent !mkdir -p ' b:sessiondir
  let b:filename = b:sessiondir . '/session.vim'
  exe "mksession! " . b:filename

function! LoadSession()
  let b:sessiondir = $HOME . "/.vim/sessions" . getcwd()
  let b:sessionfile = b:sessiondir . "/session.vim"
  if (filereadable(b:sessionfile))
    exe 'source ' b:sessionfile
    echo "No session loaded."

au VimEnter * nested :call LoadSession()
au VimLeave * :call MakeSession()


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.