12
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 ...
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 ...
7
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 ...
6
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 ...
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 ...
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
:...
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> ...
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.
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 ...
5
votes
Close session and all buffers with one command
You can use:
:qa
for quit all or
:qa!
The later forces to quit Vim even if some buffer modifications have nor been saved.
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 ...
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 ...
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 ...
4
votes
Accepted
what is the purpose of the view folder in the .vim folder?
~/.vim/view is a default value (under *nix) for :h 'viewdir' option, which, in turn, is used by the :h :mkview and :h :loadview commands.
:mkview is a rarely used :mksession-like command which saves ...
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 ...
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).
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 ...
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 ...
3
votes
Can the default filename for :mksession be changed?
Fortunately it is relatively easy to compile vim to use a different name if desired: edit src/feature.h to change
#define SESSION_FILE "Session.vim"
to whatever name you want. Then ...
2
votes
Can I open a file in an existing Vim instance from an external command?
In addition to @craigp's answer, you can also open a file in a remote tab.
vim --servername SERVER --remote-tab FILE
2
votes
Make Vim sessions save the content of unnamed buffers
Vim workarounds:
write temporary notes/code in predefined system-wide or project-wide files (possibly with the help of some custom functions/mappings)
use a Vim note-taking plugin
In both cases ...
2
votes
Make Vim sessions save alternate files
Since there is no option to do this directly, you can hack around like this:
function! MkSession(filename)
execute 'mksession! '.a:filename
let l:alternate = fnameescape(expand('#'))
if l:...
2
votes
How to share the same buffer between multiple vim instances
If you are still looking for an answer and willing to try neovim, the neovim-remote does what you need.
From the readme:
Open files always in the same nvim process no matter which terminal you're ...
2
votes
Can capitalized marks be saved in session INSTEAD of viminfo?
Is there an easy setting to make this switch?
Nope
I know I could write some vimscript to save my session marks somewhere and reload them to overwrite whatever viminfo is doing, but I don't want ...
2
votes
Accepted
Update a Vim Session file's loaded plugins without losing window positioning
With the help of @Matt, we were able to get my new plugins loaded, and markdown folds working.
Open vim with the session file
vim -S Session.vim
Modify sessionoptions by removing options and folds ...
2
votes
Accepted
How to preserve options in Vim sessions?
Thanks for pointing to sessionoptions, this answered my question like this:
Step by step:
nvim file1.txt
:vsp file2.txt
A perfect environment to compare files.
Note: it is necessary to apply each ...
2
votes
When opening an existing session and an existing file at the same time, the focus goes to the last opened file in the session
You can cheat a little using this method:
vim -S Session.vim -c ":e OTHER_FILE"
This will source your Session.vim then load the file you want.
From what I have read in the man page, the ...
2
votes
Accepted
Simple way to store additionnal config in the scope of the actual directory
Off the top of my head perhaps something like this in your vimrc...
let g:localconffile = '.myvimconf'
func! LoadLocalConfig() abort
let l:fname = expand('%:p:h') . '/' . g:localconffile
if ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sessions × 64buffers × 12
vimrc × 6
neovim × 6
vimscript × 4
gvim × 3
colorscheme × 3
terminal-buffer × 3
viminfo × 3
persistent-state × 3
terminal × 2
vim-windows × 2
spell-checking × 2
save × 2
invocation × 2
clientserver × 2
key-bindings × 1
command-line × 1
cut-copy-paste × 1
autocmd × 1
cursor-movement × 1
microsoft-windows × 1
functions × 1
highlight × 1
plugin-system × 1