<p>As I develop more with vim, I find myself wanting to copy in blocks of useful code, similar to "templates" in Eclipse. </p>

<p>I was thinking of making a separate file for each code chunk and just reading them in with</p>

<pre><code>:r code-fornext
</code></pre>

<p>but that just seems kind of primitive. Googling around I find vim macros mentioned and something about "maps" but nothing that seems straightforward.</p>

<p>What I am looking for are e.g. something like Eclipse's "Templates" so I pop in a code chunk with the cursor sitting in the middle of it.
Or JEdit's "Macros" which I can record doing complicated deletes and renaming on one line, then I can play it again on 10 other lines so it does the same to them.</p>

<p>Does vim have anything like these two functionalities?</p>

[{'answer_id': 54527, 'author': 'brian newman', 'author_id': 3210, 'author_profile': 'https://Stackoverflow.com/users/3210', 'pm_score': 4, 'selected': True, 'text': '<p>To record macros in Vim, in the command mode, hit the <code>q</code> key and another key you want to assign the macro to. For quick throw away macros I usually just hit <code>qq</code> and assign the macro to the <code>q</code> key. Once you are in recording mode, run through your key strokes. When you are done make sure you are back in command mode and hit <code>q</code> again to stop recording. Then to replay the macro manually, you can type <code>@q</code>. To replay the previously run macro you can type <code>@@</code> or to run it 10 times you could type <code>10@q</code> or <code>20@q</code>, etc..</p>\n\n<p>In summary:</p>\n\n<pre><code>+----------------------------------+-------------------------------------+\n| start recording a macro          | qX (X = key to assign macro to)     |\n+----------------------------------+-------------------------------------+\n| stop recording a macro           | q                                   |  \n+----------------------------------+-------------------------------------+\n| playback macro                   | @X (X = key macro was assigned to)  |\n+----------------------------------+-------------------------------------+\n| replay previously played macro   | @@                                  |\n+----------------------------------+-------------------------------------+\n</code></pre>\n\n<p>In regards to code chunks, I have found and started using a Vim plug-in called snipMate, which mimics TextMate\'s snippets feature. You can get the plug-in here:</p>\n\n<p><a href="http://www.vim.org/scripts/script.php?script_id=2540" rel="nofollow noreferrer">http://www.vim.org/scripts/script.php?script_id=2540</a></p>\n\n<p>And a short article on using snipMate (along with a short screencast showing it in use):</p>\n\n<p><a href="http://www.catonmat.net/blog/vim-plugins-snipmate-vim/" rel="nofollow noreferrer">http://www.catonmat.net/blog/vim-plugins-snipmate-vim/</a></p>\n\n<p>Hope you find this helpful! </p>\n'}, {'answer_id': 83345, 'author': 'Luc Hermitte', 'author_id': 15934, 'author_profile': 'https://Stackoverflow.com/users/15934', 'pm_score': 0, 'selected': False, 'text': '<p>On vim.wikia, you will find a <a href="http://vim.wikia.com/wiki/Category:Automated_Text_Insertion" rel="nofollow noreferrer" title="Automated Text Insertion category">category of tips</a> dedicated to snippets and abbreviations expansion. You will also see a list of plugins that ease the definition of complex snippets/templates-files.</p>\n\n<p>HTH,</p>\n'}]
['https://Stackoverflow.com/questions/54401', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4639/']