4

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?

2
  • 1
    How about putting 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?
    – garyjohn
    Commented Oct 9, 2015 at 16:21
  • @garyjohn This is the solution I found most helpful (automatically loads the functions and ties them to that specific session). If you add it as answer I'll gladly accept it Commented Nov 9, 2015 at 18:58

3 Answers 3

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 a function in your .vimrc just to call :source /home/me/annoyingly/long/path/name/functionsfile.

1
  • 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
0

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.

1
  • 2
    I 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.