3

I try to make effective use of vim's copy buffers by assigning regularly used commands to each one; but there never seems to be enough of them. When editing an html doc for example I bind </li><br>\n\t<li> to the "l copy buffer, but when editing a bash script use the "l buffer for a bash specific command. So between sessions I continuously have to copy one command out for the other and re-save it in the buffer depending on what kind of file I am editing, never mind if I am editing one of each simultaneously, which is often enough to consider it a common occurrence.

Is there a way I can create profiles for different copy buffers and load them depending on what kind of file I am editing?

digiscripter
  • 309
  • 2
  • 6
  • 3
    You might want to look at a snippets plugin or insert mode abbreviations/mappings. Regardless look at ftplugins. – FDinoff Aug 06 '14 at 22:39
  • 1
    I do use snipmate with a crazy number of snippets defined and used regularly, but for entering the most common commands that occur many multiple times while editing a single file I seem to prefer using the copy buffers; they seem for me faster (perhaps mere illusion?) – digiscripter Aug 06 '14 at 23:00

2 Answers2

3

The file ~/.viminfo contains the copy buffers currently stored. I guess you could create a copy of it, say ~/.viminfo_html with all your html shortcuts, and another named ~/.viminfo_bash with all your scripting shortcuts and before you open vim you can set either one to be ~/.viminfo.

It looks like /.viminfo gets loaded into memory by vim when it starts up, and so if you wanted to edit an html and a .sh file simultaneously making use of your two ~/.viminfo files you could (I tried it and it works, even if you add new data to some previously assigned copy buffers, the data in other buffers of the previous ~/.viminfo file loaded at vim startup but since changed are still available, but I did not test much or for long enough to see whether or not copy buffer data unchanged remains stable for the duration of a vim session) simply swap out the current ~/.viminfo file for the alternate and open the document in a new vim session in a separate terminal session.

If the .viminfo file you need from one session to another is totally sporatic and unpredictable, then you could whip up a little script to prompt you to select which .viminfo file to rename before starting vim.

scriptz
  • 515
  • 2
  • 10
  • 2
    @scripts just about does what I want. I don't plan to run different vim terminals though to have different copy buffer/register profiles. But it is a big help that before firing up vim I can at least assign one saved configuration or the other depending on what kind of file I will start to edit. – digiscripter Aug 07 '14 at 01:38
  • 1
    The blind leading the blind. – romainl Aug 07 '14 at 07:15
2

They are called "registers", not "copy buffers".

You really should use a proper snippet expansion plugin like the original Snipmate, the forked Snipmate, the fashionable UltiSnips or the venerable XPtemplate.

I explain two less "advanced" methods over there.

Community
  • 1
  • 1
romainl
  • 186,200
  • 21
  • 280
  • 313