In this tips code block below, all template mappings are insert-mode only, while the "skip to next placeholder" (mapped as ;;) is both insert and normal mode enabled.
In this tips code block below, all template mappings are insert-mode only, while the "skip to next placeholder" (mapped as ;;) is both insert and normal mode enabled.
The following is an example code template for a "for loop" statement in C++ with 5 custom text input locations. When added to the vimrc file, it allows the user to type ";fo" in insert mode and add a "for loop" block into their code quickly.
The following is an example code template for a "for loop" statement in C++ with 5 custom text input locations. When added to the vimrc file, it allows the user to type ";fo" in insert mode and add a "for loop" block into their code quickly.
Add the following to your vimrc file to add the "skip to next placeholder" functionality which will move the cursor to the next %%% section:
Add the following to your vimrc file to add the "skip to next placeholder" functionality which will move the cursor to the next %%% section:
−
+
<pre>
−
:imap <buffer> ;; <C-O>/%%%<CR><C-O>c3l
+
:imap <buffer> ;; <C-O>/%%%<CR><C-O>c3l
−
:nmap <buffer> ;; /%%%<CR>c3l
+
:nmap <buffer> ;; /%%%<CR>c3l
+
</pre>
==Usage==
==Usage==
−
Whenever a C++ for block is needed type ";fo" and the following code will be placed in the file. The "_" signifies where the cursor will be in insert mode.
Whenever a C++ for block is needed type ";fo" and the following code will be placed in the file. The "_" signifies where the cursor will be in insert mode.
−
<pre>
<pre>
for( _; %%% ; %%%)
for( _; %%% ; %%%)
Line 38:
Line 35:
The user may now type in some statement where the first "%%%" was, like i=0.
The user may now type in some statement where the first "%%%" was, like i=0.
−
<pre>
<pre>
for( i=0_; %%% ; %%%)
for( i=0_; %%% ; %%%)
Line 47:
Line 43:
The user would then type ;; to place the cursor at the next "%%%" location, removing the "%%%" and putting Vim into insert mode.
The user would then type ;; to place the cursor at the next "%%%" location, removing the "%%%" and putting Vim into insert mode.
−
<pre>
<pre>
for( i=0; _ ; %%%)
for( i=0; _ ; %%%)
Line 56:
Line 51:
==See also==
==See also==
−
*{{script|id=222}} - Mu-Template, a script which has support for placeholders in templates.
*{{script|id=222}} - Mu-Template, a script which has support for placeholders in templates.
*{{script|id=336}} - A script which defines C/C++ abbreviations with placeholders.
*{{script|id=336}} - A script which defines C/C++ abbreviations with placeholders.
created 2002 · complexity basic · author lars_e_krueger · version 6.0
A number of scripts allow for text and code templates, even some which allow the user to put in placeholders. However, a script is not always needed to allow the user to quickly add a common code block or text block with place holding inserts. This template for inserts a code block with placeholders that are triple percent signs (%%%) where the user wants to enter custom text. The ;; command is mapped to find the next %%% and allow the user to change them to the custom text.
In this tips code block below, all template mappings are insert-mode only, while the "skip to next placeholder" (mapped as ;;) is both insert and normal mode enabled.
The following is an example code template for a "for loop" statement in C++ with 5 custom text input locations. When added to the vimrc file, it allows the user to type ";fo" in insert mode and add a "for loop" block into their code quickly.
Whenever a C++ for block is needed type ";fo" and the following code will be placed in the file. The "_" signifies where the cursor will be in insert mode.
for( _; %%% ; %%%)
{ // %%%
%%%
}
The user may now type in some statement where the first "%%%" was, like i=0.
for( i=0_; %%% ; %%%)
{ // %%%
%%%
}
The user would then type ;; to place the cursor at the next "%%%" location, removing the "%%%" and putting Vim into insert mode.