Wikia

Vim Tips Wiki

Changes: Quick way to insert opening and closing braces for programmers

Edit

Back to page

(Adjust previous/next navigation)
(Adjust previous/next navigation + minor manual clean)
 
Line 3: Line 3:
 
|id=677
 
|id=677
 
|previous=676
 
|previous=676
|next=679
+
|next=680
|created=March 15, 2004
+
|created=2004
 
|complexity=basic
 
|complexity=basic
 
|author=Yada
 
|author=Yada
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
This insert-mode map is fairly easy. It will save a lot of keystrokes for opening and closing braces when programming. It works best with cindent on (:set cindent) since vim will automatically indent to the right tabstop.
+
This insert-mode map is fairly easy. It will save a lot of keystrokes for opening and closing braces when programming. It works best with cindent on (:set cindent) since vim will automatically indent to the right tabstop. I mapped it to insert-mode Ctrl-F.
I mapped it to insert-mode Ctrl-F.
 
   
 
Example:
 
Example:
 
 
<pre>
 
<pre>
 
int main() Ctrl-F
 
int main() Ctrl-F
Line 21: Line 20:
   
 
will produce:
 
will produce:
 
 
<pre>
 
<pre>
 
int main() {
 
int main() {
Line 29: Line 27:
   
 
insert the following in your vimrc file
 
insert the following in your vimrc file
 
 
<pre>
 
<pre>
 
" Opening and closing braces
 
" Opening and closing braces

Latest revision as of 02:26, March 30, 2010

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 677 Printable Monobook Previous Next

created 2004 · complexity basic · author Yada · version 5.7


This insert-mode map is fairly easy. It will save a lot of keystrokes for opening and closing braces when programming. It works best with cindent on (:set cindent) since vim will automatically indent to the right tabstop. I mapped it to insert-mode Ctrl-F.

Example:

int main() Ctrl-F

will produce:

int main() {
    |
}

insert the following in your vimrc file

" Opening and closing braces
imap <C-F> {<CR>}<C-O>O

CommentsEdit

Around Wikia's network

Random Wiki