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?

  • 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 Oct 9 '15 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 – SnoringFrog Nov 9 '15 at 18:58
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.

  • 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. – SnoringFrog Nov 9 '15 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.

  • 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. – SnoringFrog Oct 15 '15 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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