69 votes
Accepted

How to save window, split, and buffer layout?

You can use vim's :mksession and write each "workspace" to a different file, then reopen a session using vim -S session_file, however, if you're open to using a plugin then I find the vim-startify ...
  • 2,261
31 votes

How to save window, split, and buffer layout?

You can use tpope's vim-obsession plugin to easily manage sessions. It is like a wrapper to Vim's in-built mksession, but provides a set of other niceties as well. You can save the current session (...
  • 15.8k
28 votes
Accepted

Can I open a file in an existing Vim instance from an external command?

You need vim compiled with +clientserver, and then you can use the command: vim --servername SERVER to start a vim instance, and vim --servername SERVER --remote FILE to open the file in the named ...
  • 2,261
16 votes

How to save window, split, and buffer layout?

As a side note, I'd like to point out that I built yet another plugin dhruvasagar/vim-prosession as an extension to tpope/vim-obsession that enhances it even further to create & manage vim ...
  • 5,245
15 votes

How do I restore a group of tabs?

In vim, there is a feature which allows you to save your current session to a vimscript file. This can be done using the :mksession command. Here is a synopsis of the command given in the vim ...
11 votes

How do I restore a group of tabs?

You can save a session of vim with all its settings including your open tabs with :mksession ~/session.vim and load it with :source ~/session.vim if you don't want to store options like your ...
  • 921
11 votes

Remember previous session

Vim has a built-in session mechanism, from :h session: A Session keeps the Views for all windows, plus the global settings. You can save a Session and when you restore it later the window layout ...
  • 46.8k
7 votes

Can I open a file in an existing Vim instance from an external command?

While @craigp's answer is correct, I found it most convenient to simply add --remote-silent without worrying about server names,(this assumes you don't want to address named vim instances). This will ...
  • 3,443
6 votes

Make Vim sessions save the content of unnamed buffers

You could use the following function. It is extremely hacky and I haven't tested it plenty but it seems to work. The idea is to create a command :Mksession which will work like the original :...
  • 46.8k
6 votes
Accepted

Source vim session file: Track down unexpected sourcing of other file

See :h :mksession, the 10th point: If a file exists with the same name as the Session file, but ending in "x.vim" (for eXtra), executes that as well. You can use *x.vim files to specify ...
  • 9,340
6 votes
Accepted

How do I get rid of <filename>.project.vim files?

From doc/automatic-tex-plugin.txt in the Automatic LaTeX Plugin source: *b:atp_ProjectScript* *g:...
  • 13.9k
6 votes
Accepted

Vim lost custom highlight settings after recovering from sessions

Your last comment says that your default colorscheme is sourced twice : once before your custom highlight groups, and once after. The second time it's loaded, your custom highlight groups must be ...
  • 6,506
5 votes
Accepted

Make vim sessions adopt changes to vimrc file

The :map command defines a new mapping, while the :unmap removes them. If you define a new mapping, it will remain there until you explicitly removes it. Your session file is probably saving it, so ...
  • 6,470
5 votes

How can I restore the cursor position when opening a file?

The vim-lastplace plugin does exactly what you want (I am the author). It improves on the above code snippet by handling commit messages intelligently. If you have debian-testing you can apt-get ...
5 votes
Accepted

Remapping of j as gj etc in .vimrc is not applied in a session

Mappings defined with <buffer> are only effective in the buffer that's active when they are defined. Remove <buffer> to have them work more-or-less everywhere. See :help map-<buffer> ...
  • 2,520
5 votes
Accepted

Can I retain and restore all the GUI windows and its files on launch on Vim?

As I mentioned in my comments a session is associated with a single invocation of Vim so you can't do exactly what you're hoping to do. But I also mentioned something might be possible using shell ...
  • 18.5k
5 votes

How can I read a command-line argument in vimrc?

Vim version 8.1.2233 adds the read-only variable v:argv, which can be used to parse the command line arguments given to Vim.
4 votes

How does one perform a multi-line copy and paste between two sessions in Vim?

I know this is old but I came across it and thought a different option might be useful for other people searching for this question. I would yank to the system register and then open the new file and ...
  • 143
4 votes
Accepted

How does one perform a multi-line copy and paste between two sessions in Vim?

Assuming you have a viminfo file (located at ~/.viminfo on Linux/Unix systems and $HOME\_viminfo on Windows), all of your buffers should be persistent across Vim sessions. Note that if you're on a ...
  • 13.9k
4 votes
Accepted

Change saved session's working directory

The behavior of :mksession is driven by the flags you have set in 'sessionoptions' (alias 'ssop'). The two flags that are likeliest to be factors here are curdir and sesdir. The former is simple, the ...
  • 18.5k
4 votes
Accepted

! is required but not allowed for custom command

E189 "..." exists (add ! to overwrite) is reported by :h :mksession if session file exists , add ! after mks should fix that: exe 'command Sdfs mks!' sessionlocation If you want to pass ! from Sdfs ...
  • 5,968
4 votes

How to save quickfix list per neovim session using :mksession?

Quickfix lists (shortened to "qflist" from here on) are not saved with :mksession. Probably because the list is saved in a temporary file which is scrubbed when exiting the current vim ...
  • 3,341
3 votes
Accepted

Empty first tab lost when using sessions

This is indeed a bug in Vim. I filed a GitHub issue, and someone on the vim-dev mailing list addressed it. Here's a patch that fixes it in Vim 8.0.52: diff --git a/src/ex_docmd.c b/src/ex_docmd.c ...
3 votes

Ignore word spelling on a per-file/buffer basis

There's nothing built-in; I guess the reasoning is that spelling (at least for a certain language) is inherently global. Any differences should be reflected in the language / dialect chosen. You can ...
3 votes
Accepted

Using '-c' when calling vim from terminal

The issue is that you need to escape your space: alias viml='vim -c :SLoad\ zzz' Let's consider a simpler case: I have a file named a.vim in the current directory and my alias is: alias vv="vim ...
  • 15.3k
3 votes
Accepted

How can I restore the cursor position when opening a file?

What I use (adapted from :help restore-cursor): " Go to the last cursor location when a file is opened, unless this is a " git commit (in which case it's annoying) au BufReadPost * \ if line("'\""...
3 votes

How to save window, split, and buffer layout?

You can try the vim-workspace plugin, its session management features are automated, scoped for your current working directory, and is pretty simple (only need to run ToggleWorkspace once).
  • 81
3 votes

Is there a `:browse oldfiles` for vim sessions?

There's a single :h v:oldfiles list saved to / restored from :h viminfo. And it has nothing to do with :h session-file. On the other hand, "session" does not store "oldfiles"-sort ...
  • 17.9k
3 votes

Is it by design that opening with -S doesn't account for changes in file permission?

Session is simply a VimScript file. You can read through it and see what is going on. What it does, it re-creates buffer(s) and after that it attempts to restore all previously saved options. By doing ...
  • 17.9k
2 votes
Accepted

Save functions in a session

Put the function in a file with the same name as your session file but ending in x.vim as described in item 10 under :help mks
  • 5,964

Only top scored, non community-wiki answers of a minimum length are eligible