VIM asks for a variable when running a macro?

I find that I spend a lot of time closing and reopening sets of files, so I would like to improve my VIM macro to load and save a session to support multiple sessions.

I would like it to ask for a string value so that I can click on my shortcut and then type, for example, "foo" and save my macro in a .foo session (so I also need to make the base string concat on it). Then I would do the same for the download macro and manage sessions by topic (using the MVC environment, you usually have a lot of files to work with).

" Control-S to save and Shift F5 to load set sessionoptions=tabpages,winpos map <S-F5> :source ~/.vim/.session<cr> map <cs> :mksession! ~/.vim/.session<cr>\| :echo "Session saved."<CR> 

I have very little experience writing VIM. Is it possible to do this in one liner or, perhaps, in a small function?

Thanks.

+4
source share
2 answers
 map <s-f5> :execute "source ".input("session name: ", "~/.vim/session.", "file")<cr> 

Type "foo" to download "session.foo".

Instead, you can also:

 map <s-f5> :source ~/.vim/session. 

Note that <cr> does not exist, so you execute the command yourself and press enter - the same input as above, until the file name is completed.

However, I would look at a function call or something else in this matter.

+3
source

Here is a snippet that I have now if someone needs something like this (no need to vote). It saves sessions under .session.xyz , which are also excluded from my Git project. I like to store them in the Git project folder so that they are backed up.

I like the confirmation of the echo, because when you press enter after saving the session, otherwise you do not see that something happened. This is just for feedback.

  map <S-F5> :execute "source ".input("Load session: ", "~/Some/Project/.session.", "file")<cr> map <cs> :execute "mksession! ".input("Save session: ", "~/Some/Project/.session.", "file")\| :echo "Session saved."<CR> 

File completion makes this very convenient, thanks!

0
source

All Articles