58

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 plugin is exactly what I need for this sort of scenario. It does a great job of managing sessions, in vim and mccvim, and it gives you a list of recent files as ...


46

The most simple version is: create ~/.vim/undo-dir/ directory and add the following to the .vimrc: set undodir=~/.vim/undo-dir set undofile However, it's not flawless, and it's better to read on. From my own .vimrc: " Let's save undo info! if !isdirectory($HOME."/.vim") call mkdir($HOME."/.vim", "", 0770) endif if !isdirectory($HOME."/.vim/undo-dir") ...


26

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 :Obsession. If you don't supply an argument, it writes a session file called Session.vim by default. To reload a ...


14

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


12

In short, there is not a cleaner way to wipe registers so completely that they disappear from :reg. Rather than murk around with ~/.viminfo, I tend to "softclear" registers when I'm really and truly done with them by setting them to be blank. To clear the a register, for instance, I type qaq to set the a register to an empty string. Equivalently, :let @a=''...


10

The answer to your title question is what you observed. From the vim user manual :help 21.3 When you run Vim multiple times, the last one exiting will store its information. This may cause information that previously exiting Vims stored to be lost. Each item can be remembered only once. However, the filename of the viminfo file (where the command ...


10

You can use the :browse command for that: :browse oldfiles For a keystroke, map it: nnoremap <Leader>o :browse oldfiles<cr> Then you can press Leader o in normal mode to view a list of files. From :help v:oldfiles: v:oldfiles oldfiles-variable v:oldfiles List of file names that is loaded from the ...


8

I had this exact problem. Here's what I added to my vimrc to fix it for me: " Always write undo history, but only read it on demand " use <leader>u to load old undo info " modified from example in :help undo-persistence if has('persistent_undo') set undodir=~/.vim/undo " location to store undofiles nnoremap <leader>u :call ReadUndo()<CR&...


8

What I do is add the following to my .vimrc: set undofile set undodir=~/.vim/undo/ That way all your undo/change tree information is saved across vim sessions, and next time you open your file you can still undo/redo old edits.


7

Put them in a function (into your vimrc or a file in the plugin folder): function! Stuff() 1,1s/^\|\t/|!/g 1,1s/$/|/g 2,$s/^\|\t/|/g 2,$s/$/|/g endfunction You can then use :call Stuff()<cr> to run them or make a custom command: command DoStuff call Stuff() And just do :DoStuff<cr> If you wanna run them directly from a buffer ...


7

For those wanting to remove the register name (say, a) from the :registers list, there is a way to do it now. Run the command :call setreg('a', []). I found this out from this question on StackOverflow from user @LucHermitte. His answer details how to clear multiple registers. If you want this task to be super easy, get creative with your .vimrc :)


6

Here is the full list of settings which should be added to your .vimrc if you want to prevent any leakage of sensitive files. set nobackup set nowritebackup set noundofile set noswapfile set viminfo="" set noshelltemp set history=0 set nomodeline set secure I recommend you create a new configuration file called .vimrc_secure and run Vim with vim -u ~/....


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

For Windows, the home directory is set in %USERPROFILE%. I believe vim will use this as $HOME. In my case, the _viminfo is located in the C:\Users\<username>, which is the home directory, while the %HOME% is not set as well.


5

You can run all of them in the same command by joining them with a | (vertical bar): :1,1s/^\|\t/|!/g | 1,1s/$/|/g | 2,$s/^\|\t/|/g | 2,$s/$/|/g It will then be available in your command history (: ↑ or q :), which should be persistent across Vim sessions as long as you have your .viminfo set up corectly.


5

Oooh, ooh, finally a chance to show off this nifty command! Vim can "go back in time." It has an :earlier command... :ea :earlier :earlier {count} Go to older text state {count} times. :earlier {N}s Go to older text state about {N} seconds before. ...


4

Check out Ctrl-P's MRU feature. Once you've installed it, type :CtrlPMRUFiles and it'll pop open a fuzzy finder at the bottom of the screen that you can fuzzy search through.


4

Update 2015-06-28: I fixed a small bug, and released this as a plugin. The plugin code is slightly better, in that it warns again after moving the cursor; I recommend you use the plugin. The answer from superjer works great, but has the unfortunate side-effect that you can only undo changes from the last Vim session, and not all previous Vim sessions. This ...


4

Using :saveas keeps the undo history intact. :saveas is equivalent to the combination of :w newname followed by :e #. I usually find it more handy than the :w + :e, especially since with :saveas it's not really possible to forget about doing the second command and end up editing the first file. (Which you can guess is something I've done more than once!)


3

No, the 'undodir' option cannot be set from a modeline, because it has the 'SECURE' flag set. Since this is a global option, it does not make sense to set this option differently for a specific file, that would also affect all other buffers that are edited later then. However it might be possible to use a BufRead in combination with a BufWritePost ...


3

I have the following, which stops and beeps when undo reaches the persisted buffer contents. runtime autoload/repeat.vim " Must load the plugin now so that the plugin's mappings can be overridden. let s:undoPosition = [] function! s:StopAtSavedPosition( action ) " Buffers of type "nofile" and "nowrite" never are 'modified', so only do " the check ...


3

Put this in your .vimrc: command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor and clear every register with :WipeReg If you would like that to happen every time you start Vim also add: autocmd VimEnter * WipeReg


2

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).


2

I think I'd also accept an answer that gave a command that reverted the file to the state it was in since the last time you opened it. (Or better, jumped back to that undo state.) > Rich I really liked the quoted idea so I made :Revert command. I hope you'll find it relevant to your question. function! s:Real_seq(inner, outer) abort let node = a:outer ...


2

Take note of the server name of your GVim window by looking at its title, it should have something like VIM or VIM1. You can then use this command to insert foo at the current cursor position: $ vim --servername VIM --remote-send "ifoo<Esc>" For more information, see :help clientserver.


2

One of the simplest ways is save these commands to a file and :source the file. Example, add the following to foo.vim: 1,1s/^\|\t/|!/g 1,1s/$/|/g 2,$s/^\|\t/|/g 2,$s/$/|/g Now you can source the file via :source foo.vim to run those commands. If you find yourself using these commands often then you may want to create a command (possibly using a function) ...


1

Tim Pope created eunuch plugin with such feature. It has :Move and :Rename commands. Do not know if it works under Windows since description is about UNIX shell commands, can't test it right now. Also as filbranden said you can copy with :saveas.


1

For corporative environments usually is set the %HOMEDRIVE and %HOMEPATH% and the GVIM use it (version 8.1 at least) . option.txt help file : *$HOME-windows* On MS-Windows, if $HOME is not defined as an environment variable, then at runtime Vim will set it to the expansion of $HOMEDRIVE$HOMEPATH. If $HOMEDRIVE is not set then ...


1

Are you sure the HOME variable isn't set? I have encountered cases where ENV was not set, but HOME always seems to be assigned a value in my (G)Vim instances. If you type echo $HOME in command mode, Vim should display what value is set for HOME. Alternatively, you can try e $HOME\.viminfo and see if this opens the contents of the .viminfo file. If this is ...


1

One easy way to save any kind of action is to record it as a macro. These are stored in the named registers, "a to "z, and with the default 'viminfo' setting, these registers will be saved to the .viminfo file and thus persisted across Vim restarts. (See :h 'viminfo'.) So for example, the following series of keystrokes would store your first example ...


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