Hard refresh in vim (not :so %)

Viewed 177

Sometimes in vim I'll need to exit the vimrc file and enter back into it to update changes (for example if I'm editing other files related to it). To do this I'll normally do:

:wq
$ vim
ctrl-o ctrl-o " in vim

Would there be a way to do this all within vim? Something like:

:wq | !vim %

Additionally, why does it require me to do ctrl-o two times to go to the previous buffer (it almost seems like the first ctrl-o does nothing)?


Update: Please note that I am aware of doing :so % or :so $MYVIMRC, etc. My question here is how do I basically reset 100% of the things to whatever are in my current files? That is, unset ALL mappings, variables, etc. that may have been updated, removed, etc; update ALL files that may have changed (functions, plugins, colorschemes, etc.). I don't think "Running :so % on 20 files" is a good solution here, which is why my current solution is to close the file and re-open it.

3 Answers

As others have mentioned, you can source your .vimrc, but that doesn't completely reset Vim. If you want to just restart Vim, then you can do so by re-execing it.

Vim doesn't provide a built-in way to exec processes from within it, since typically one doesn't want to replace one's editor with another process, but it is possible to do so with Perl or Ruby, as you see fit:

:perl exec "vim"

or

:ruby exec "vim"

This may or may not work on Windows, and it of course requires that your Vim version have been compiled with support for the appropriate interpreters. Debian provides both in the vim-nox, vim-gtk3, and vim-athena packages, but not in vim or vim-tiny; Ubuntu, last I checked, did not provide Ruby support but did include Perl.

If you want to re-exec with the same buffer, you can use one of these:

:perl exec "vim", $curbuf->Name();

or

:ruby exec "vim", Vim::Buffer.current.name

Note that re-execing may cause your screen to be slightly messed up when exiting, so you may need to use reset to set it back to normal.

I don't know if you had tried this but you can source your vimrc file from vim itself by typing

:so $MYVIMRC

In order to apply the changes, you don't have to exit vim and open it again, no need for a "hard refresh" :) If you want to apply in on the .vimrc file itself, you can type

:so %

to apply the changes in another file, you can type:

:so ~/.vimrc #path to your .vimrc file

in normal mode, Ctrl-O takes you to where your cursor has been backward and Ctrl-I forward. You can check your jump list by typing :jumps, to clear your jumps :clearjumps

in insert mode, Ctrl-O escapes to normal mode and lets the user to do one normal mode command.

Related