Vi: Difference between revisions
Line 155: | Line 155: | ||
Use the mappings {{kb|A-Up}} / {{kb|A-Down}} to switch the current window to the next/previous file. These mappings simply move and center the cursor in the ''TagList'' window to the previous/next file, open the file and put the cursor to its last position. |
Use the mappings {{kb|A-Up}} / {{kb|A-Down}} to switch the current window to the next/previous file. These mappings simply move and center the cursor in the ''TagList'' window to the previous/next file, open the file and put the cursor to its last position. |
||
== Keyboard Shortcuts == |
== Keyboard & Mouse Shortcuts == |
||
* <font color="red">''! If keys HJKLM have been remapped to MHJKL, shortcut below must be changed accordingly'' !</font> |
|||
* Mouse shortcuts requires <code>:set mouse=a</code>. |
|||
* Customer shortcuts are <u>underlined</u> |
|||
=== Custom Cheatsheets === |
=== Custom Cheatsheets === |
||
* [[Media:Visio-Vim graphic cheatsheet-AZERTY-MIP.pdf|Custom graphical keyboard cheatsheet (AZERTY)]] |
* [[Media:Visio-Vim graphic cheatsheet-AZERTY-MIP.pdf|Custom graphical keyboard cheatsheet (AZERTY)]] |
||
* [[Media:Vim quick reference card.pdf|Vim quick reference card (PDF)]] |
* [[Media:Vim quick reference card.pdf|Vim quick reference card (PDF)]] |
||
** [[Media:MIP Vim quick reference card.pdf|Custom version (PDF)]] |
|||
* |
|||
=== Cheatsheet & plugin summary === |
=== Cheatsheet & plugin summary === |
||
<table> |
<table> |
||
<tr valign="top"> |
<tr valign="top"> |
||
Line 172: | Line 176: | ||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
{{ |
{{kbctrl|W}}_<br/> |
||
{{ |
{{kbctrl|W}}h<br/> |
||
{{ |
{{kbctrl|W}}j<br/> |
||
{{ |
{{kbctrl|W}}k<br/> |
||
{{ |
{{kbctrl|W}}l<br/> |
||
{{ |
{{kbctrl|W}}p<br/> |
||
{{ |
{{kbctrl|W}}o |
||
| |
| |
||
Maximize current window<br/> |
Maximize current window<br/> |
||
Line 194: | Line 198: | ||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
[[ ''or'' {{ |
[[ ''or'' {{kbname|BS}}<br/> |
||
]] ''or'' {{ |
]] ''or'' {{kbname|Tab}}<br/> |
||
{{ |
{{kbname|Space}}<br/> |
||
- ''or'' zc<br/> |
- ''or'' zc<br/> |
||
+ ''or'' zo<br/> |
+ ''or'' zo<br/> |
||
Line 202: | Line 206: | ||
=<br/> |
=<br/> |
||
x<br/> |
x<br/> |
||
{{ |
{{kbname|CR}} ''or'' {{kbname|LMouse}}*2<br/> |
||
o<br/> |
o<br/> |
||
P<br/> |
P<br/> |
||
Line 226: | Line 230: | ||
Change the sort order |
Change the sort order |
||
|} |
|} |
||
</td> |
|||
<td> |
|||
'''Plugin - tComment''' |
'''Plugin - tComment''' |
||
Line 244: | Line 247: | ||
|} |
|} |
||
</td> |
|||
<td> |
|||
'''Plugin - Surround''' |
'''Plugin - Surround''' |
||
Line 272: | Line 277: | ||
|width="140px"| |
|width="140px"| |
||
<nowiki>:MRU</nowiki><br/> |
<nowiki>:MRU</nowiki><br/> |
||
<nowiki>:MRU</nowiki> |
<nowiki>:MRU</nowiki> ''p''<br/> |
||
{{kb|CR}}<br/> |
{{kb|CR}}<br/> |
||
o<br/> |
o<br/> |
||
Line 279: | Line 284: | ||
| |
| |
||
Open MRU file list<br/> |
Open MRU file list<br/> |
||
Open MRU file list, only files |
Open MRU file list, only files containing ''p''<br/> |
||
Open file in previous window if possible<br/> |
Open file in previous window if possible<br/> |
||
Open file in a new window<br/> |
Open file in a new window<br/> |
||
Line 291: | Line 296: | ||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
{{ |
{{kbname|leader}}dcd<br/> |
||
{{ |
{{kbname|leader}}dcp |
||
| |
| |
||
DiffChangesDiffToggle<br/> |
DiffChangesDiffToggle<br/> |
||
Line 298: | Line 303: | ||
|} |
|} |
||
'''Mouse''' |
|||
</td> |
|||
</tr> |
|||
</table> |
|||
=== Missing shortcuts in cheatsheet === |
|||
Custom shortcuts are <u>underlined</u>. |
|||
<table> |
|||
<tr valign="top"> |
|||
<td> |
|||
'''Insert Mode''' |
|||
{| class="wikitable" width="100%" |
{| class="wikitable" width="100%" |
||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
{{ |
{{kbname|MouseL}}<br/> |
||
g{{kbname|MouseR}} {{kbctrl|{{kbkey|MouseR}}}} |
|||
{{kb|C-x}}{{kb|C-k}}<br/> |
|||
<nowiki>:</nowiki>set dictionary=<span style="color:green;">''f''</span> |
|||
| |
| |
||
Jump to tag<br/> |
|||
Return from tag |
|||
Dictionary completion<br/> |
|||
Set dictionary |
|||
|} |
|} |
||
''' |
'''Insert''' |
||
{| class="wikitable" width="100%" |
{| class="wikitable" width="100%" |
||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
<u>{{kbctrl|{{kbname|Space}}}}</u> |
|||
"* "+<br/> |
|||
"_<br/> |
|||
<nowiki>:</nowiki><span style="color:green;">''r ''</span>y<span style="color:green;">''x''</span><br/> |
|||
<nowiki>:</nowiki>%y+ |
|||
| |
| |
||
Same as {{kbname|Esc}}, but more finger friendly (see [http://vim.wikia.com/wiki/Avoid_the_escape_key]) |
|||
Use system clipboard<br/> |
|||
Use black hole register<br/> |
|||
yank range <span style="color:green;">''r ''</span> to register <span style="color:green;">''x''</span><br/> |
|||
yank whole file to clipboard |
|||
|} |
|} |
||
''' |
'''Miscellaneous''' |
||
{| class="wikitable" width="100%" |
{| class="wikitable" width="100%" |
||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
<nowiki>:</nowiki>{{kbctrl|U}} |
|||
`` <u>²²</u><br/> |
|||
|Remove the automatically inserted range (see <code>:help omap-info</code>) |
|||
`" <u>²"</u><br/> |
|||
`.<br/> |
|||
`^ |
|||
| |
|||
Go to position before jump<br/> |
|||
Go to position at last edit<br/> |
|||
Go to last modification<br/> |
|||
Go to last position after insert mode was stopped |
|||
|} |
|} |
||
</td> |
|||
'''Tags''' |
|||
</tr> |
|||
</table> |
|||
=== Operator & motion === |
|||
{| class="wikitable" width="100%" |
|||
''Operators'' in Vim acts |
|||
|- |
|||
* on ''the current selection'' (visual mode like {{kbkey|v}}, {{kbkey|V}} or {{kbctrl|v}}) when there is such a selection, |
|||
|width="140px"| |
|||
* or must be followed by a ''motion'' indicating which part of the text must be modified. |
|||
{{kb|C-W}}i<br/> |
|||
{{kb|C-W}}d<br/> |
|||
<nowiki>:tn :tp</nowiki> |
|||
| |
|||
Split window and jump to declaration<br/> |
|||
Split window and jump to definition<br/> |
|||
Jump to next / previous matching tag |
|||
|} |
|||
< |
<table> |
||
<tr valign="top"> |
|||
<td> |
<td> |
||
'''Scrolling and multi-windowing''' |
|||
'''Operators''' |
|||
{| class="wikitable" width="100%" |
|||
|- |
|||
|width="140px"| |
|||
{{kb|C-w}}_<br/> |
|||
{{kb|C-w}}gf {{kb|C-w}}gF<br/> |
|||
{{kb|C-w}}+ {{kb|C-w}}-<br/> |
|||
{{kb|C-w}}> {{kb|C-w}}<<br/> |
|||
<nowiki>:</nowiki>ls''[''!'']''<br/> |
|||
<nowiki>:</nowiki><span style="color:green;">''n ''</span>b |
|||
| |
|||
Maximize current window<br/> |
|||
New tab + go to file, file & line<br/> |
|||
Increase / decrease window height <span style="color:green;">''n ''</span> lines<br/> |
|||
Increase / decrease window width <span style="color:green;">''n ''</span> columns<br/> |
|||
list buffer [incl. unlisted]<br/> |
|||
edit buffer <span style="color:green;">''n ''</span> |
|||
|} |
|||
'''Ex commands (←)''' |
|||
{| class="wikitable" width="100%" |
{| class="wikitable" width="100%" |
||
|- |
|- |
||
|width="140px"| |
|width="140px"| |
||
c<br/> |
|||
<nowiki>:</nowiki>wqa<br/> |
|||
d<br/> |
|||
<nowiki>:</nowiki>qa<br/> |
|||
y<br/> |
|||
<nowiki>:</nowiki>e# {{kb|C-^}} |
|||
~<br/> |
|||
g~<br/> |
|||
gu<br/> |
|||
gU<br/> |
|||
<nowiki>!</nowiki><br/> |
|||
=<br/> |
|||
gq<br/> |
|||
g?<br/> |
|||
><br/> |
|||
<<br/> |
|||
zf<br/> |
|||
g@ |
|||
| |
| |
||
change<br/> |
|||
Write all changed buffers and quit<br/> |
|||
delete<br/> |
|||
Quit and confirm all buffers<br/> |
|||
yank into register (does not change the text)<br/> |
|||
Edit alternate buffer, even if has no filename |
|||
swap case (only if 'tildeop' is set)<br/> |
|||
swap case<br/> |
|||
make lowercase<br/> |
|||
make uppercase<br/> |
|||
filter through an external program<br/> |
|||
filter through 'equalprg' or C-indenting if empty<br/> |
|||
text formatting<br/> |
|||
ROT13 encoding<br/> |
|||
shift right<br/> |
|||
shift left<br/> |
|||
define a fold<br/> |
|||
call function set with the 'operatorfunc' option |
|||
|} |
|} |
||
'''Miscellaneous''' |
|||
{| class="wikitable" width="100%" |
|||
|- |
|||
|width="140px"| |
|||
{{kb|C-d}}<br/> |
|||
{{kb|C-l}} |
|||
| |
|||
List all possible completions<br/> |
|||
Paste char under cursor |
|||
|} |
|||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table> |
</table> |
||
The ''motion'' is either one of the ''motion key'' (like {{kbkey|>%}} for ''shift right until match'') or an ''operator motion'' (like {{kbkey|diB}} for ''delete inner {} block''). See <tt>[http://vimdoc.sourceforge.net/htmldoc/motion.html#operator :help operator]</tt>. |
|||
=== Help === |
|||
{| class="wikitable" |
|||
!Shortcut |
|||
!Description |
|||
!Custom |
|||
|- |
|||
|{{kb|C-]}}<br/>{{kb|MouseL}} |
|||
|Jump to a subject. On azerty keyboard, do '''Ctrl-AltGr-]''' (but doesn't work with Synergy).<br/>The mouse shortcut requires '''<code>:set mouse=a</code>''' |
|||
| |
|||
|- |
|||
|{{kb|C-O}}<br/>{{kb|C-T}}<br/>g{{kb|MouseR}}<br/>{{kb|C-MouseR}} |
|||
|Back. |
|||
| |
|||
|} |
|||
'''Frequently-used operator motion''' |
|||
=== Splitting windows === |
|||
{| class="wikitable" |
|||
!Shortcut |
|||
!Description |
|||
!Custom |
|||
|- |
|||
|''':{height}split ''[filename]''''' |
|||
|Split the screen into two windows, optionally opening another file (with the optional specified height) |
|||
| |
|||
|- |
|||
|''':new''' |
|||
|Open a new window on a new empty file |
|||
| |
|||
|- |
|||
|''':close''' |
|||
|Close the current windows |
|||
| |
|||
|- |
|||
|''':only''' |
|||
|Close all other windows |
|||
| |
|||
|- |
|||
|'''Ctrl-W w''' |
|||
|Switch between windows |
|||
| |
|||
|- |
|||
|'''Ctrl-W +'''<br/>'''Ctrl-W -''' |
|||
|Increase / decrease window height |
|||
| |
|||
|- |
|||
|'''{height}Ctrl-W _''' |
|||
|Set window height, or maximize it if no height specified |
|||
| |
|||
|- |
|||
|''':qa[ll]'''<br/> ''':wa[ll]''' |
|||
|Quit all windows / Write change for all windows |
|||
| |
|||
|} |
|||
=== Tabs === |
|||
{| class="wikitable" |
{| class="wikitable" |
||
|- valign="top" |
|||
!Shortcut |
|||
|<tt>'''iw'''</tt><br/> |
|||
!Description |
|||
<tt>'''iW'''</tt><br/> |
|||
!Custom |
|||
<tt>'''is'''</tt><br/> |
|||
|- |
|||
<tt>'''ip'''</tt> |
|||
|inner word<br/> |
|||
|Execute the command in a new tab |
|||
inner WORD<br/> |
|||
| |
|||
inner sentence<br/> |
|||
|- |
|||
inner paragraph |
|||
|''':tabonly''' |
|||
|<tt>'''aw'''</tt><br/> |
|||
|Close all tabs but the current one |
|||
<tt>'''aW'''</tt><br/> |
|||
| |
|||
<tt>'''as'''</tt><br/> |
|||
|- |
|||
<tt>'''ap'''</tt> |
|||
|''':tabn[ext]'''<br/>'''C-PageDown'''<br/>'''gt'''<br/> |
|||
|a word<br/> |
|||
|Go to the next tab page |
|||
a WORD<br/> |
|||
| |
|||
a sentence<br/> |
|||
|- |
|||
a paragraph |
|||
|''':tabp[ext]'''<br/>'''C-PageUp'''<br/>'''gT'''<br/> |
|||
|<tt>'''i['''</tt><br/> |
|||
|Go to the previous tab page |
|||
<tt>'''ib'''</tt> <tt>'''i('''</tt><br/> |
|||
| |
|||
<tt>'''i<'''</tt><br/> |
|||
|} |
|||
<tt>'''it'''</tt><br/> |
|||
<tt>'''iB'''</tt> <tt>'''i{'''</tt> |
|||
=== Miscellaneous === |
|||
|inner [] block<br/> |
|||
inner () block<br/> |
|||
<font color="red">''! If keys HJKLM have been remapped to MHJKL, shortcut below must be changed accordingly'' !</font> |
|||
inner <> block<br/> |
|||
inner tag block<br/> |
|||
{| class="wikitable" |
|||
inner {} block |
|||
!Shortcut |
|||
|<tt>'''a['''</tt><br/> |
|||
!Description |
|||
<tt>'''ab'''</tt> <tt>'''a('''</tt><br/> |
|||
!Custom |
|||
<tt>'''a<'''</tt><br/> |
|||
|- |
|||
<tt>'''at'''</tt><br/> |
|||
|{{kb|C-[}} |
|||
<tt>'''aB'''</tt> <tt>'''a{'''</tt> |
|||
|Same effect as '''Esc''', but a bit faster/easier to type. Works on ''AZERTY'' keyboard in Windows, but not on Linux. |
|||
|a [] block<br/> |
|||
| |
|||
a () block<br/> |
|||
|- |
|||
a <> block<br/> |
|||
|{{kb|C-C}} |
|||
a tag block<br/> |
|||
|Same effect as '''Esc''', but a bit faster/easier to type. Also works on ''AZERTY'' keyboard |
|||
a {} block |
|||
| |
|||
|<tt>'''i"'''</tt><br/> |
|||
|- |
|||
<tt>'''i<nowiki>'</nowiki>'''</tt><br/> |
|||
|{{kb|C-Space}} |
|||
<tt>'''i`'''</tt> |
|||
|Same effect as '''Esc''', but a bit faster/easier to type (see [http://vim.wikia.com/wiki/Avoid_the_escape_key]). |
|||
|inner "" string<br/> |
|||
|Yes |
|||
inner <nowiki>''</nowiki> string<br/> |
|||
|- |
|||
inner `` string |
|||
|{{kb|C-N}} |
|||
|<tt>'''a"'''</tt><br/> |
|||
|Omni and keyword completion. |
|||
<tt>'''a<nowiki>'</nowiki>'''</tt><br/> |
|||
|Yes |
|||
<tt>'''a`'''</tt> |
|||
|- |
|||
|a "" string<br/> |
|||
|<tt>*</tt> |
|||
a <nowiki>''</nowiki> string<br/> |
|||
|Search next occurence of word under cursor (Here [http://vim.wikia.com/wiki/VimTip1 more] like this...) |
|||
a `` string |
|||
| |
|||
|- |
|||
|<tt>#</tt> |
|||
|Search previous occurence of word under cursor |
|||
| |
|||
|- |
|||
|<tt>gd</tt> |
|||
|Search first occurence of current search |
|||
| |
|||
|- |
|||
|<tt>^d</tt>{{kb|BS}} |
|||
|Concatenate current line at the end of previous lines (assuming <tt><BS></tt> does wrap-around. See option ''whichwrap'') |
|||
| |
|||
|- |
|||
|<tt>J</tt> |
|||
|Concatenate current line with next line |
|||
| |
|||
|- |
|||
|<tt>/</tt>{{kb|Up}} |
|||
|Recall previous search string |
|||
| |
|||
|- |
|||
|<tt>:</tt>{{kb|Up}} |
|||
|Recall previous command |
|||
| |
|||
|- |
|||
|<tt>.</tt> |
|||
|Redo last command |
|||
| |
|||
|- |
|||
|{{kb|C-O}} |
|||
|Switch to normal mode for one command. Use <tt>|</tt> to execute more commands (see [http://vim.wikia.com/wiki/VimTip459]) |
|||
| |
|||
|- |
|||
|<tt>:</tt>{{kb|C-U}} |
|||
|Remove the range that Vi may insert when entering normal mode (handy for defining maps - see <code>:help omap-info</code> |
|||
| |
|||
|} |
|||
=== Block Indenting === |
|||
(ref: [http://stackoverflow.com/questions/235839/how-do-i-indent-multiple-lines-quickly-in-vi]) |
|||
{| class="wikitable" |
|||
!Shortcut |
|||
!Description |
|||
!Custom |
|||
|- |
|||
|'''>>''' |
|||
|Indent current line |
|||
| |
|||
|- |
|||
|'''5>>''' |
|||
|Indent 5 lines |
|||
| |
|||
|- |
|||
|'''Vjjjj>>''' |
|||
|Indent 5 lines - same as above but using ''visual'' mode |
|||
| |
|||
|- |
|||
|'''>%''' |
|||
|''(while cursor is on a curly brace)'' Indent a curly-braces block |
|||
| |
|||
|- |
|||
|''']p''' |
|||
|paste & indent block based on surrounding text |
|||
| |
|||
|- |
|||
|'''={''' |
|||
|''(C-indenting)'' Auto-indent the current block (<tt>:help =</tt> for more info) |
|||
| |
|||
|- |
|||
|'''==''' |
|||
|''(C-indenting)'' Auto-indent the current line |
|||
| |
|||
|- |
|||
|'''gg=G''' |
|||
|Intends everything! |
|||
| |
|||
|} |
|||
=== Operator & motion === |
|||
List of available operators: |
|||
'''c ''' change |
|||
'''d ''' delete |
|||
'''y ''' yank into register (does not change the text) |
|||
'''~ ''' swap case (only if 'tildeop' is set) |
|||
'''g~''' swap case |
|||
'''gu''' make lowercase |
|||
'''gU''' make uppercase |
|||
'''! ''' filter through an external program |
|||
'''= ''' filter through 'equalprg' or C-indenting if empty |
|||
'''gq''' text formatting |
|||
'''g?''' ROT13 encoding |
|||
'''> ''' shift right |
|||
'''< ''' shift left |
|||
'''zf''' define a fold |
|||
'''g@''' call function set with the 'operatorfunc' option |
|||
List of frequently used ''operator motion'' (see <tt>[http://vimdoc.sourceforge.net/htmldoc/motion.html#operator :help operator]</tt>). They are used like <tt>diB</tt> (''delete inner {} block) |
|||
{| class="wikitable" |
|||
|- |
|||
|<tt>'''iw'''</tt>||inner word |
|||
|<tt>'''aw'''</tt>||a word |
|||
|<tt>'''i['''</tt>||inner [] block |
|||
|<tt>'''a['''</tt>||a [] block |
|||
|<tt>'''i"'''</tt>||inner "" string |
|||
|<tt>'''a"'''</tt>||a "" string |
|||
|- |
|||
|<tt>'''iW'''</tt>||inner WORD |
|||
|<tt>'''aW'''</tt>||a WORD |
|||
|<tt>'''ib'''</tt> <tt>'''i('''</tt>||inner () block |
|||
|<tt>'''ab'''</tt> <tt>'''a('''</tt>||a () block |
|||
|<tt>'''i<nowiki>'</nowiki>'''</tt>||inner <nowiki>''</nowiki> string |
|||
|<tt>'''a<nowiki>'</nowiki>'''</tt>||a <nowiki>''</nowiki> string |
|||
|- |
|||
|<tt>'''is'''</tt>||inner sentence |
|||
|<tt>'''as'''</tt>||a sentence |
|||
|<tt>'''i<'''</tt>||inner <> block |
|||
|<tt>'''a<'''</tt>||a <> block |
|||
|<tt>'''i`'''</tt>||inner `` string |
|||
|<tt>'''a`'''</tt>||a `` string |
|||
|- |
|||
|<tt>'''ip'''</tt>||inner paragraph |
|||
|<tt>'''ap'''</tt>||a paragraph |
|||
|<tt>'''it'''</tt>||inner tag block |
|||
|<tt>'''at'''</tt>||a tag block |
|||
| || |
|||
| || |
|||
|- |
|||
| || |
|||
| || |
|||
|<tt>'''iB'''</tt> <tt>'''i{'''</tt>||inner {} block |
|||
|<tt>'''aB'''</tt> <tt>'''a{'''</tt>||a {} block |
|||
| || |
|||
| || |
|||
|} |
|} |
||
Revision as of 22:38, 14 July 2010
Related Pages
This page is about the editor vim itself. The other related pages are
- Vimrc, which is dedicated to vim configuration settings and to the file ~/.vimrc.
External Links
General
- My links on vim on del.icio.us.
- Official vim homepage.
- Vim Tips Wiki
- Vim documentation: help
- Vim documentation: map
- List of all commands for each mode:
:help index
Other General
- Vi Lovers home page
- Good post explaining why vi is superior and defeating common misconception (with examples).
- Vi would not be vi without a bit of fun...
Cheat sheets
- Very good graphical keyboard cheatsheet
- Another compact & complete cheatsheet (as folded reference card).
- Real Short Vim Normal-Mode List of Commands (from Dr Chip's)
Guides & Cheat sheets
- New To Vim
- Quick Tips
- Avoiding the ESC key
- Vim map tutorial
- Dr Chip's Vim Page — A tremendous amount of Vim treasures from an expert user
- Efficient editing with vim
- C editing with VIM HOWTO
- Using vim as an IDE all in one
- Browsing programs with tags
- Using Bash completion with ctags and Vim
- Alternative tab navigation
- Seven habits of effective text editing (from author of Vim)
Plugins (installed)
- snipMate : TextMate-style snippets for Vim
- a.vim : Alternate Files quickly (.c --> .h etc)
- trinity.vim : Build the trinity of srcexpl, taglist, NERD_tree to be a good IDE
- Source Explorer (srcexpl.vim) : A Source code Explorer based on tags works like context window in Source Insight
- taglist.vim : Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)
- The NERD tree : A tree explorer plugin for navigating the filesystem
- AutoTag : Updates entries in a tags file automatically when saving
- surround.vim : Delete/change/add parentheses/quotes/XML-tags/much more with ease
- tComment : An extensible & universal comment plugin that also handles embedded filetypes
- mru.vim : Plugin to manage Most Recently Used (MRU) files
- Smart Tabs : Use tabs for indent, spaces for alignment
- See also Indent with tabs & align with spaces
- cpp.vim: General C++ Settings (no indentation for namespace...) (disabled highlight of leading tabs, line length overruns, unit test header test + nice
- diffchanges.vim : Show changes made to current buffer since the last save
{{{content}}}
{{{content}}}
AlterColour
function that computes new colour...)
Plugins (not yet installed)
- OmniCppComplete : C/C++ omni-completion with ctags database
- c.vim : C/C++ IDE -- Write and run programs. Insert statements, idioms, comments etc.
- CScope with the tutorial here
- winmanager : A windows style IDE for Vim 6.0 (Referenced in TagList plugin help)
- bufexplorer.zip : Buffer Explorer / Browser
- neocomplcache : Ultimate auto completion system for Vim
- FuzzyFinder : buffer/file/command/tag/etc explorer with fuzzy matching
- matchit.zip : extended % matching for HTML, LaTeX, and many other languages
- LustyExplorer : Dynamic filesystem and buffer explore
- project.tar.gz : Organize/Navigate projects of files (like IDE/buffer explorer)
Some videos that illustrates those plugins:
- Top Vim Plugins (YouTube), showing Surround, SnipMate, TComment, MRU, FuzzyFinder, NerdTree, MatchIt
Plugins (uninstalled)
- easytags.vim : Automated tag file generation and syntax highlighting of tags in Vim
- Replaced by AutoTag — syntax highlighting of tags is limited to c files; moreover AutoTag has a clever way to look for the tags file in project hierarchy.
- minibufexpl.vim : Elegant buffer explorer - takes very little screen space
- No real tab support. Seems to interfere with trinity plugin. Interesting key bindings inside though. To reassess...
Invocation
vi -p file1.txt file2.txt # Open each file in a different tab
vi -t tagname # Open file and move cursor at specified tag (requires ctags)
view file.txt # View file in vim, with syntax highlighting... (read-only)
vimdiff file1.txt file2.txt # View differences in vim
Simple IDE using plugin TagList
Thanks to plugin TagList, it is possible to turn Vim into a simple yet efficient development IDE. The basic idea is to use the TagList window as a simple file explorer. We use a session file to add all files in the project to the TagList window. Also we define 2 mappings to ease navigation between files.
Here an example session file Session.vim:
set tags=/win/d/projects/noekeon64/nk_fasttrails/src/tags
TlistAddFiles *.cpp
TlistAddFiles *.h
TrinityToggleTagList
nmap <A-Up> <C-W><Left>[[zz<CR>`"
nmap <A-Down> <C-W><Left>]]zz<CR>`"
Create the tag file:
ctags -R .
Then start the IDE session with:
gvim -S
Use the mappings A-Up / A-Down to switch the current window to the next/previous file. These mappings simply move and center the cursor in the TagList window to the previous/next file, open the file and put the cursor to its last position.
Keyboard & Mouse Shortcuts
- ! If keys HJKLM have been remapped to MHJKL, shortcut below must be changed accordingly !
- Mouse shortcuts requires
:set mouse=a
. - Customer shortcuts are underlined
Custom Cheatsheets
Cheatsheet & plugin summary
Window management
Plugin - taglist window (:help taglist-keys)
Plugin - tComment
|
Plugin - Surround
Plugin - MRU
Plugin - diffchanges
Mouse
Insert
Miscellaneous
|
Operator & motion
Operators in Vim acts
- on the current selection (visual mode like v, V or ^v) when there is such a selection,
- or must be followed by a motion indicating which part of the text must be modified.
Operators
|
The motion is either one of the motion key (like >% for shift right until match) or an operator motion (like diB for delete inner {} block). See :help operator.
Frequently-used operator motion
iw iW |
inner word inner WORD |
aw aW |
a word a WORD |
i[ ib i( |
inner [] block inner () block |
a[ ab a( |
a [] block a () block |
i" i' |
inner "" string inner '' string |
a" a' |
a "" string a '' string |
Commands
:s/search/replace/g Search & replace - current line :%s/search/replace/g Search & replace - global scope :set {option}=70 Set Vim option (here textwidth) :echo &{option} Show value of {option} :set {option}? Show value of {option}
Miscellaneous Tips and Tricks
- Inserting only a single character (http://vim.wikia.com/wiki/Insert_a_single_character).
- Macro
- qq to start recording a macro q. End macro with q again.
- @q to replay macro, followed by . to replay it again.
- Visual Block
- Ctrl-v to start VISUAL BLOCK mode.
- Shift-I to insert some text at the start of each line of selected block.
- wrap-around
- Set option whichwrap or ww that allows specified keys that move the cursor left/right to move to the previous/next line when the cursor is on the first/last character in the line.
- In Vim, <space> and <backspace> are set to wrap-around by default.
- Read-only viewer (with syntax highlighting):
$ vi -R sensitive_file
$ view sensitive_file
- Retab
- To convert tabs in current file to current tab settings, use command
:retab
[2]. For instance to convert tabs into space
:set expandtab :retab
- View differences in vim
vimdiff file1.txt file2.txt
- Interaction with X Clipboard
- vim can use the X clipboard if it has been compiled with the clipboard feature (run
vim --version
and see if you have +clipboard in the output). In that case, yanking to the+
register, or simply selecting with the mouse, will actually copy in the X clipboard, hence allowing other applications, or even other instances of vim to exchange text snippets. Also, it will ease the copy-paste of indented text, since in that case, vim will first disable autoindentation before pasting the text (see optionpaste
). - On system like Ubuntu, you need to install an instance of gvim (like package vim-gnome or vim-gtk) to have feature
+clipboard
turned on (i.e. installing package vim is not enough). - When
set mouse=a
, use shift-mouse to still use the xterm copy/paste (see mouse-using).
set incsearch
, moves cursor as search pattern is typed. Ctrl-L to type letter under cursor, Ctrl-R Ctrl-W to type current word.- References:
- type
:help ctrl<C-D>
, to get a list of all ctrl sequence. Type <C-D> in command line for auto-completion. - Support 256 colors in gnome-terminal: add
set t_Co=256
in ~/.vimrc ([3]) - Use
:make
and:grep
instead of:!make
or:!grep
. Then use:cwin
or:copen
to view the results of either make or grep in a coloured list (from [4]). - (from [5]), The
:g
command is useful to apply a command to all lines matching a search.
" delete all lines matching pattern
:g/pattern/d
" delete all lines *NOT* matching pattern (:v same as :g!)
:g!/pattern/d
:v/pattern/d
- Write the following in files ~/.vim/after/syntax/c.vim and ~/.vim/after/syntax/cpp.vim (or symlink) to highlight C/++ delimiters (see [6]):
syn match cDelimiter "[&\.!^,;:<>=|+%*-]"
syn match cParenDelimiter "[][(){}]"
hi def link cDelimiter Delimiter
hi def link cParenDelimiter Delimiter
Plugins
SnipMate
C
main main() inc #include <...> Inc #include "..." Def #ifndef ... #define ... #endif def #define ifdef #ifdef ... #endif #if #if ... #endif once #ifndef HEADER_H .... # define HEADER_H ... #endif (Header Include-Guard) if If (...) { ... } el else { ... } t ... ? ... : ... (tertiary conditional) do do ... while ( ... ) wh while (...) { ... } for for (... = 0; ...; ...) { ... } forr for (... = ...; ...; ...) { ... } fun ... function(...) { ... } fund ... function(...;) td typedef st struct tds typedef struct tde typedef enum pr printf fpr fprintf . [ ... ] un unsigned
CPP
readfile snippet for reading file map std::map<... , ...> map... vector std::vector<...> v... ns namespace ... { ... } cl class { public: ... private: };
To Do
- Done Find a way to prevent vim to mess up with my register when deleting text.
- Auto-complete, use cursor keys instead of up/down to search in the drop down list.
- Look at Virtual-edit (see http://vim.wikia.com/wiki/Add_trailing_blanks_to_lines_for_easy_visual_blocks)
- Other links: