I have a function I wrote specifically for a certain session in vim. Manually redefining it every time I load the session is tedious. Is there any way custom functions can be saved with the session? If not, what're some options for speeding up reloading that function every time I load the session?
3 Answers
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
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 a function in your .vimrc
just to call :source /home/me/annoyingly/long/path/name/functionsfile
.
-
If my functions were more general use, this would be good, but they've all been very session specific so far. Good idea to keep in mind though. Commented Nov 9, 2015 at 19:00
Assuming that “certain session” means “certain project” and “certain directory” I would try to use the per-project .vimrc
file. To get vim to additionally read the .vimrc
in the current directory, I have set exrc
in my ~/.vimrc
.
-
2I came across that as a potential solution, which led to a question about the danger of
set exrc
. The risk outweighs the usefulness of the solution for me, unfortunately. Commented Oct 15, 2015 at 15:12
x.vim
as described in item 10 under:help :mks
?