Vim snippets, no snippet / template added

I use vim a lot, but my workflow tends to force me to interact with other IDEs, so I'm not a god-like vim poweruser and I'm not trying to be anytime soon. Vim is not an IDE for me, and I don't want to. It's a fast and lightweight editor that doesn't get in my way.

I am looking for ease in both use and configuration, not uber power or gold stars in efficiency.

I've preloaded several registers with my snippets so far and then save a cheat sheet for which the register has what text block. But I'm running out of registers and a single letter letter letter doesn't immediately remind me of what I preloaded.

What is the simplest way to save any number of raw text blocks and then retrieve them with one keyword and one hotkey (in any order: keyword <> hotkey).

  • I don't need phrases available for the language (smart keywords will be my solution)
  • I don't want snippets that are context sensitive or smart in any way.
  • I am not planning on using a mini-template language to optimize my fragments, this is overkill.
  • My snippets should literally embed in the source they were defined with and nothing else.

I think I could just start writing named functions that simply print a block of text into the current buffer. Thats pretty much everything I need, but I was hoping for a slightly easier way to save / update my collection of fragments.


Are there some minimalist plugins out there that cover my use case, or should I just stick with my .vimrc / python-commands approach?

Minor update I didn't realize that you can link so many letters with clover, it might provide the magic I need. Then I still have to list another set of functions (maybe use python to define commands).

0


source to share


1 answer


If you want free solutions, you can use:

  • abbreviations

    :iabbrev obj    var foo = {};<Left><Left>
    :iabbrev func   function foo() {<CR><CR>}<Up><Tab>
    :iabbrev lipsum Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer diam augue, egestas quis, aliquam ut, venenatis ut, quam. Quisque ut augue. Integer non neque a lectus venenatis fermentum. Morbi quis eros nec elit molestie vehicula. Integer nunc lacus, sodales posuere, rutrum quis, blandit at, mi. Vivamus imperdiet wisi vel mauris. Morbi mattis ante non metus. Sed turpis dui, fermentum ut, aliquam eget, vulputate ullamcorper, pede. Nam non dolor. Etiam lobortis, urna id bibendum convallis, ligula augue auctor eros, a dictum sapien mi a tellus. Proin vel justo. Nunc malesuada turpis a sapien.
    
          

    You can expand them with help <Space>

    if you don't mind finite space or with help <C-]>

    if you do.

    See :help abbreviations

    .

  • display insert in mode

    You can create any complex mapping you want using <leader>

    or not.

    The key (no pun intended), here, is just pick a rarely used key and use that as the namespace for your mappings. For example, on my French AZERTY keyboard, I have a key §

    that is completely useless (not used in Vim, not used in French, not used in any programming language I work with). If I wanted to create a mapping library, I would use it as a "leader" for these snippets:

    :inoremap §obj    var foo = {};<Left><Left>
    :inoremap §func   function foo() {<CR><CR>}<Up><Tab>
    :inoremap §lipsum Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer diam augue, egestas quis, aliquam ut, venenatis ut, quam. Quisque ut augue. Integer non neque a lectus venenatis fermentum. Morbi quis eros nec elit molestie vehicula. Integer nunc lacus, sodales posuere, rutrum quis, blandit at, mi. Vivamus imperdiet wisi vel mauris. Morbi mattis ante non metus. Sed turpis dui, fermentum ut, aliquam eget, vulputate ullamcorper, pede. Nam non dolor. Etiam lobortis, urna id bibendum convallis, ligula augue auctor eros, a dictum sapien mi a tellus. Proin vel justo. Nunc malesuada turpis a sapien.
    
          

If you choose abbreviations or collations, you can save them all in a separate file:

~/.vim/snippets.vim

      

and put it in your ~/.vimrc

:

runtime snippets.vim

      

If you choose to place this file somewhere outside of your directory ~/.vim/

, you can specify it with:

source ~/path/to/snippets.vim

      

change

Oh <leader>

...



<leader>

is not really special: you can usually treat it like a variable, but like an insert $foo

into a database, a value is inserted $foo

, the registration <leader>something

will be logged {current value of mapleader}something

.

Let's assume you have created a custom mapping <leader>

:

let mapleader = ","
map <leader>b :bnext<CR>

      

Vim registers ,b

. If you decide to change you <leader>

later in the current session:

:let mapleader = "%"

      

you will still have ,b

. Only further mappings will use the new one <leader>

:

map <leader>b :bnext<CR>

      

You get both ,b

, and %b

.

<leader>

means something only when creating a mapping. When used, it is simple ,b

or %b

.

+3


source







All Articles