Reputation: 57
I have some code on a server.
I need to keep repeating the same edit around pieces of existing code.
E.g existing code:
int hello = 1;
I need to edit this
#ifndef X
int hello = 1;
#else
#endif
Is there a way to be able to create a wrapper to autocomplete?
#ifndef X
{existing code}
#else
#endif
Thanks.
Upvotes: 1
Views: 190
Reputation: 11810
Use vim Ultisnips with VISUAL selection option:
snippet wrap "inserts text around visual selection" w
#ifndef X
${0:${VISUAL}}
#else
#endif
endsnippet
After installing Ultisnips set a mapping to edit the snippets:
map <Leader>u :UltiSnipsEdit<cr>
Now you can copy the snippet seen above and change it accordingly your needs. The UltiSnips default trigger is Tab but you can change it easily:
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
Select the line you want to "wrap" with other text, press Tab, then type wrap
and finally Tab. NOTE: I am using the word wrap because my choice during the snippet creation, but you can also change it.
Upvotes: 2
Reputation: 4476
If you have the same complex edition to do, I would make a macro (:help q
) for it.
Upvotes: 2