Vi: Difference between revisions
(→Plugins (installed): Patches for plugin trinity and taglist) |
|||
Line 37: | Line 37: | ||
=== Plugins (installed) === |
=== Plugins (installed) === |
||
<ul> |
|||
⚫ | |||
<li> [http://www.vim.org/scripts/script.php?script_id=2540 '''snipMate''' : TextMate-style snippets for Vim]</li> |
|||
<li> [http://www.vim.org/scripts/script.php?script_id=31 '''a.vim''' : Alternate Files quickly (.c --> .h etc)]</li> |
|||
<li> [http://www.vim.org/scripts/script.php?script_id=2347 '''trinity.vim''' : Build the trinity of srcexpl, taglist, NERD_tree to be a good IDE]</li> |
|||
* [http://www.vim.org/scripts/script.php?script_id=2179 '''Source Explorer (srcexpl.vim)''' : A Source code Explorer based on tags works like context window in Source Insight] |
|||
* [http://www.vim.org/scripts/script.php?script_id=273 '''taglist.vim''' : Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)] |
|||
* [http://www.vim.org/scripts/script.php?script_id= |
* [http://www.vim.org/scripts/script.php?script_id=1658 '''The NERD tree''' : A tree explorer plugin for navigating the filesystem] |
||
{{hiddenSourceFile| ~/.vim/plugin/|trinity.vim.diff|<source lang="diff" class="trinity.vim.diff"> |
|||
⚫ | |||
--- trinity.vim 2009-12-22 19:50:06.000000000 +0100 |
|||
⚫ | |||
+++ trinity-new.vim 2010-07-06 01:24:28.000000000 +0200 |
|||
⚫ | |||
@@ -90,7 +90,7 @@ |
|||
⚫ | |||
" Set the window width |
|||
let g:Tlist_WinWidth = 24 |
|||
" Sort by the order |
|||
- let g:Tlist_Sort_Type = "order" |
|||
+ let g:Tlist_Sort_Type = "name" |
|||
" Do not display the help info |
|||
let g:Tlist_Compact_Format = 1 |
|||
" If you are the last, kill yourself |
|||
@@ -100,7 +100,7 @@ |
|||
" Do not show folding tree |
|||
let g:Tlist_Enable_Fold_Column = 0 |
|||
" Always display one file tags |
|||
- let g:Tlist_Show_One_File = 1 |
|||
+ let g:Tlist_Show_One_File = 0 |
|||
endfunction " }}} |
|||
</source>}} |
|||
{{hiddenSourceFile| ~/.vim/plugin/|taglist.vim.diff|<source lang="diff" class="taglist.vim.diff"> |
|||
--- taglist.vim 2007-09-21 18:11:20.000000000 +0200 |
|||
+++ taglist-new.vim 2010-07-06 01:08:11.000000000 +0200 |
|||
@@ -3207,14 +3207,7 @@ |
|||
if a:win_ctrl == 'newwin' |
|||
split |
|||
endif |
|||
+ " 20100706 - MIP PATCH BEGIN - USE badd / buffer! so that we can |
|||
+ " switch files even when current buffer changes are not written ---- |
|||
+ if !bufexists(a:filename) |
|||
+ exe "badd " . escape(a:filename, ' ') |
|||
+ endif |
|||
+ exe "buffer! " . escape(a:filename, ' ') |
|||
+ " exe "edit " . escape(a:filename, ' ') |
|||
+ " 20100706 - MIP PATCH END ----- |
|||
- exe "edit " . escape(a:filename, ' ') |
|||
else |
|||
" Open a new window |
|||
if g:Tlist_Use_Horiz_Window |
|||
</source>}} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</ul> |
|||
=== Plugins (not yet installed) === |
=== Plugins (not yet installed) === |
Revision as of 23:28, 5 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
- 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
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
{{{content}}}
{{{content}}}
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>`"
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 restore the cursor position to the last edit session.
Keyboard Shortcuts
Graphical summary
See My custom cheatsheet (AZERTY) for a graphical summary.
Missing shortcuts in cheatsheet
Custom shortcuts are underlined.
Insert Mode
Copying
Marks and motion
|
Scrolling and multi-windowing
Ex commands (←)
Miscellaneous
|
Help
Shortcut | Description | Custom |
---|---|---|
C-] MouseL |
Jump to a subject. On azerty keyboard, do Ctrl-AltGr-] (but doesn't work with Synergy). The mouse shortcut requires :set mouse=a
|
|
C-O C-T gMouseR C-MouseR |
Back. |
Splitting windows
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 + Ctrl-W - |
Increase / decrease window height | |
{height}Ctrl-W _ | Set window height, or maximize it if no height specified | |
:qa[ll] :wa[ll] |
Quit all windows / Write change for all windows |
Tabs
Shortcut | Description | Custom |
---|---|---|
:tab {command} | Execute the command in a new tab | |
:tabonly | Close all tabs but the current one | |
:tabn[ext] C-PageDown gt |
Go to the next tab page | |
:tabp[ext] C-PageUp gT |
Go to the previous tab page |
Miscellaneous
! If keys HJKLM have been remapped to MHJKL, shortcut below must be changed accordingly !
Shortcut | Description | Custom |
---|---|---|
C-[ | Same effect as Esc, but a bit faster/easier to type. Works on AZERTY keyboard in Windows, but not on Linux. | |
C-C | Same effect as Esc, but a bit faster/easier to type. Also works on AZERTY keyboard | |
C-Space | Same effect as Esc, but a bit faster/easier to type (see [1]). | Yes |
C-N | Omni and keyword completion. | Yes |
* | Search next occurence of word under cursor (Here more like this...) | |
# | Search previous occurence of word under cursor | |
gd | Search first occurence of current search | |
^dBS | Concatenate current line at the end of previous lines (assuming <BS> does wrap-around. See option whichwrap) | |
J | Concatenate current line with next line | |
/Up | Recall previous search string | |
:Up | Recall previous command | |
. | Redo last command | |
C-O | Switch to normal mode for one command. Use | to execute more commands (see [2]) | |
:C-U | Remove the range that Vi may insert when entering normal mode (handy for defining maps - see :help omap-info
|
Block Indenting
(ref: [3])
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 (:help = 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 :help operator). They are used like diB (delete inner {} block)
iw | inner word | aw | a word | i[ | inner [] block | a[ | a [] block | i" | inner "" string | a" | a "" string |
iW | inner WORD | aW | a WORD | ib i( | inner () block | ab a( | a () block | i' | inner '' string | a' | a '' string |
is | inner sentence | as | a sentence | i< | inner <> block | a< | a <> block | i` | inner `` string | a` | a `` string |
ip | inner paragraph | ap | a paragraph | it | inner tag block | at | a tag block | ||||
iB i{ | inner {} block | aB a{ | a {} block |
Other
Window management
Plugin - taglist window (:help taglist-keys)
|
Plugin - tComment
Plugin - Surround
Plugin - MRU
|
Commands
Shortcut | Description | Custom |
---|---|---|
:s/search/replace/ | Search & replace - current line | |
:%s/search/replace/ | Search & replace - global scope |
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
[4]. 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 ([5])
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: