Tip #630: usefull for programming
tip karma |
Rating 123/44, Viewed by 4594
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
January 2, 2004 19:59 |
|
complexity: |
|
basic |
author: |
|
Andrzej Cuber |
|
as of Vim: |
|
6.0 |
Hello,
I was looking for that feature for the very long time.
I use vim for programming and I always keep forgetting about closing the parents, quotes etc.
I wanted to remap the keyboard in insert mode in that way that when I open a quote or parent I will get the closing one and the cursor would be placed between these two characters.
here is the stuff I put in my ~/.vimrc file
<pre>
:imap ( ()<Left>
:imap [ []<Left>
:imap " <C-V>"<C-V>"<left>
</pre>
I had to use <C-V> to avoid recursive mapping of the " character.
Maybe there is the feature build in vim already but I couldn't find it :)
Every comment is welcome :)
<< After quitting VIM, comeback to the same file position where you were while quitting. |
Disabling IME input in Windows >>
Additional Notes
hermitte {at} free {dot} fr,
January 3, 2004 11:50
|
There exist several (many ?) plugins and tips focusing on this issue on this site.
For instance, check my set of plugins available here vimtip#50, and used in several ftplugins (see vimtip#336, and http://hermitte.free.fr/vim/) of mine.
Regarding the recursive definition of ", dont use :imap, but :inoremap. Actually, you'd better always use the :*noremap commands and reserve :*map for the cases you explicitely need them.
|
hermitte {at} free {dot} fr,
January 3, 2004 11:53
|
Oups ! I did,'t mean vimtip#... but vimscript#50 and vimscript#336.
|
fish=natter, aei.ca=school,
January 21, 2004 8:08
|
I love this one:
inoremap ; <C-O>A;
|
|