1

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?

3
  • 1
    This may be off-topic, but most of the time, those settings are uneeded because linux hosts hardly nerver need a reboot.
    – mveroone
    Commented Sep 30, 2013 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
    Commented Sep 30, 2013 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
    Commented Sep 30, 2013 at 14:43

3 Answers 3

0

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

0

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.

0

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
    redraw!
  endif
  let b:filename = b:sessiondir . '/session.vim'
  exe "mksession! " . b:filename
endfunction

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

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

source

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .