Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now
48

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 Startify plugin is exactly what I need for this sort of scenario: https://github.com/mhinz/vim-startify It does a great job of managing sessions, in vim and mccvim, and it ...


23

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 (or buffer layout) by giving the command :Obsess. If you don't supply an argument, it writes a session file called Session.vim by default. To reload a session, ...


22

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 vim instance. macOS only MacVim runs a server by default - you can use mvim --remote-tab-silent to open a file in a new tab in your existing MacVim instance, or ...


12

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 sessions by default in a centralised repository as per configuration on a per directory basis and loads them automatically when you launch vim without any arguments on ...


10

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 documentation: :mks[ession][!] [file] Write a Vim script that restores the current editing session. When [!] is included an existing file is overwritten. When [file] ...


6

From doc/automatic-tex-plugin.txt in the Automatic LaTeX Plugin source: *b:atp_ProjectScript* *g:atp_ProjectScript* Setting one of the variables |b:atp_ProjectScript| or |g:atp_ProjectScript| to 0 the feature will be turned off. Local variable, i.e. b: has ...


6

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 looks the same. You can use a Session to quickly switch between different projects, automatically loading the files you were last working on in that ...


6

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 additional settings and actions associated with a given Session, such as creating menu items in the GUI version. ... I have a feeling this is the issue.


5

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 :mksession but will also save the unnamed buffers. (Note that I had some inspiration from this answer To do so it will call a function which does the following: First ...


5

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 colorscheme and font size you can disable storing them with this entry in your vimrc set sessionoptions-=options


5

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 when you reload your session it is back. You can inspect the contents of your session file to confirm it. Thus you probably can continue using your session if ...


5

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 overwritten. I think the reason why your default theme is loaded a second time when you source your Session.vim, is because the latter includes this line (83) : ...


5

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 install vim-lastplace to quickly try it out.


5

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> for details.


4

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 start the server, or use one if its not already started. It can be called like this: gvim --remote-silent '+cal cursor(line,col)' some_file eg: gvim --...


4

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 Linux/Unix system, this file must be owned by you (ls -l ~/.viminfo to verify that it is and chown $USER ~/.viminfo if it's not). Otherwise, it will have no ...


4

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 scripts and Vim's "clientserver" functionality. I decided to chase that down...primarily for my own edification but since it works I figured I'd share it. (Your ...


4

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 to mks, use this: exe 'command -bang Sdfs mks<bang>' sessionlocation :h :command-bang :h <bang>


3

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 -c :sp a.vim" When I run vv I get two buffers with a.vim on each. Why is that? Vim open a.vim and then execute the command :sp, which split the buffer in ...


3

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 paste from the system register. First find out what symbol represents your system clipboard. In Linux you have two options + or *. I use + but more info can ...


3

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 implement such buffer-local spelling exception yourself: Get a temp file via tempname(), prepend it to 'spellfile', and then zg / 1zg will place the exception ...


3

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("'\"") > 0 && line("'\"") <= line("$") && &filetype != "gitcommit" | \ execute("normal `\"") | \ endif BufReadPost gets run ...


3

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 current directory will be saved in the session data. The entry for sesdir in Help says: sesdir the directory in which the session file is located ...


2

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


2

Assuming the functions are something you don't want all the time, so you don't want them in your .vimrc file, you can define them in a separate file and use :source filename to load in the definitions. This avoids the security issues of set exrc and loading untrusted files. If the pathname to your functions file is irritatingly long, you could even define ...


2

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 notes are saved in files, so when reopening your session their content will not be lost. When starting a new unit of work, just erase the previous content of the ...


2

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:alternate != '' call system('echo "let @#=\"'.l:alternate.'\"" >> '.a:filename) endif endfunction command! -nargs=1 MkSession call MkSession(<f-...


2

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 index 439467c..ca4133a 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -11091,6 +11091,8 @@ makeopens( } if (tabnr > 1) need_tabnew ...


2

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 to spend the time if I don't have to. That is exactly how you would do this. Example code: command! -bang -complete=file -nargs=? Mksession mksession<bang&...


1

As a partial solution: before saving the session, use :set bl when in the netrw window, thus making it a listed buffer. Your sessionoptions should also have buffers as one of its entries. Then, save a session (ie. :mksession somefilename). Its only a partial solution because the restored window, although the window exists, is filled properly, and netrw ...


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