What is the best strategy for pieces of code and macros in vim?

As I develop more with vim, I am in a copy of the code of useful code, similar to the "templates" in Eclipse.

I was thinking of creating a separate file for each piece of code and just reading them with

:r code-fornext

but it just seems primitive. Googling around I find vim macros mentioned and something about "maps", but nothing seems simple.

What I'm looking for, for example, is something like Eclipse "Templates", so I insert a piece of code with the cursor sitting in the middle of it. Or JEdit "Macros", which I can write, doing complex deletions and renaming on one line, then I can play it again on 10 other lines so that it does the same with them.

Does vim have something like these two functions?

+5
source share
2 answers

To record macros in Vim in command mode, press the key qand another key to which you want to assign a macro. To quickly throw out macros, I usually just click qqand assign a macro to a key q. Once you are in recording mode, skip your strokes. When you're done, return to command mode and press again qto stop recording. Then, to play the macro manually, you can enter @q. To play back a previously executed macro, you can enter @@or run it 10 times, you can enter 10@qor 20@q, etc.

In short:

+----------------------------------+-------------------------------------+
| start recording a macro          | qX (X = key to assign macro to)     |
+----------------------------------+-------------------------------------+
| stop recording a macro           | q                                   |  
+----------------------------------+-------------------------------------+
| playback macro                   | @X (X = key macro was assigned to)  |
+----------------------------------+-------------------------------------+
| replay previously played macro   | @@                                  |
+----------------------------------+-------------------------------------+

, Vim, snipMate, TextMate. :

http://www.vim.org/scripts/script.php?script_id=2540

snipMate ( , ):

http://www.catonmat.net/blog/vim-plugins-snipmate-vim/

, !

+8

vim.wikia , . , / .

,

0

All Articles