Posts Tagged ‘VIM’
VIM History
VIM is my most used editor and IDE, and I am excited with every new VIM versions. This is the VIM version history and the new features excited me:
VIM 7.0 (2006)
Spellcheck
Tabs
Omni completion
text-objects: at, it
VIM 6.0 (2001)
Folding
Plugins
Unicode support
VIM 5.0 (1998)
Syntax coloring/highlighting
basic scripting
VIM 4.0 (1996)
Graphical User Interface
Word completion
Text objects
VIM 3.0 (1994)
Support for multiple buffers and windows
Most Used VIM Scripts
These are my most used VIM scripts:
taglist (utility)
matchit (utility)
vcscommand (utility) (vim7)
xmledit (ftplugin)
snippetsEmu (utility) (vim7)
remote PHP debugger (utility)
PDV (phpDocumentor for Vim) (utility)
NERD tree (utility) (vim7)
LaTex-Suite (ftplugin)
vimcommander (utility)
tetris (game)
VIM TIPs
Move around quickly
/pattern - find the text.
* - find word under the cursor.
% - jump to it’s matching.
[{ - jump back to the start of the current code block.
gd - jump from the use of a variable to its local declaration.
CTRL-] : Jump to tag under cursor
Optoins:
set incsearch - increase search
set hlsearch - highlight all matches
Don’t type it twice
:s/pattern/string/ - substitute.
* cw n .
m{a-z} - set mark {a-z} at current position
‘{a-z} - Jump to the mark {a-z}
CTRL-N - expand word.
q{a-z} - Record typed characters into register {a-z}.
q - Stops recording.
@{a-z} - Execute the regiser {a-z}.
Fix it when it’s wrong
abbr lhs rhs
Setting and Configuration
:options - view and set options
:set - show all modified options
:let - list the values of all variables
Text Object
aw, aW - ambient word or WORD (see docs)
iw, iW - inner word or WORD (see docs)
as, is - ambient or inner sentence
ap, ip - ambient or inner paragraph
a{, i{ - whole { .. } block or text inside it
a(, i( - whole ( .. ) block or just text inside it
a<, i< - whole < .. > block or just text inside it
a’, i’ - single-quoted string or just the text inside
a”, i” - double-quoted string or just the text inside
at, it - whole tag block or just text inside (HTML and XML tags)
das - delete the sentence, including whitespace after
ci( - change text inside (..) block
yat - copy the entire closest tag block the cursor is
inside
gUi’ - uppercase text inside the single-quoted string
vip - select the paragraph in Visual mode, without whitespace after
Spellcheck
z= see suggestions
zg add a word to the dictionary
zug undo an addition to the dictionary
]s move to the next misspelled word
[s move to the previous one
Code Browser
:he C-editing
:ts : List the tags that match.
CTRL-T : Jump back to before a CTRL-]
gf : Go to file name under the cursor
Code completion
CTRL-P
Ctrl-x Ctrl-o
CTRL-X CTRL-] : Completing tags
CTRL-X CTRL-P
NERD tree
o - open/close folder, open file
Others
remove ^M: %s/r//
find next lines contains more than 80 characters: /\%81c
remove lines which contains more than 80 characters: :g/%81c/d
gf - go to file under cursor
“+y - copy to gui-clipboard
“+p - paste from gui-clipboard
[I and ]I - list lines with word under the cursor
]p, ]P - paste after/before but adjust the indent
Insert a ‘(’ character at the begin of every lines:
:%s/^/(/
PageDown: CTRL-F
PageUp: CTRL-B
Extracting a vimball:
:vim filename.vba
:so %
Convert code to html:
:TOhtml
Regular Expressions in VIM
Find all the lines which dos contains the “abc”:
/^%(%(abc)@<!.)*$
Search the date string such as “2005-07-12″:
/[0-9]{4}-[0-9]{2}-[0-9]{2}
or:
/v[0-9]{4}-[0-9]{2}-[0-9]{2}
Remove the 39th field of a CSV string:
:%s/(([^,]*,){38})[^,]*,/1/
Find all the lines has “aaa”, and find the fourth “,”, then insert a “‘bbb’, ” at there:
:%s/(^[^(]*aaa[^(]*([^,]*,[^,]*,[^,]*,[^,]*,)/1 ‘bbb’,/g
this command will replace:
REPLACE INTO `aaa` VALUES (107, 101, ”, ”, ‘Thomas’, ‘Rykaceski’, ‘249 Bear Creek Road’, ”, ‘16055′, ‘Sarver’, ”, 223, 51);
with
REPLACE INTO `aaa` VALUES (107, 101, ”, ”, ‘bbb’, ‘Thomas’, ‘Rykaceski’, ‘249 Bear Creek Road’, ”, ‘16055′, ‘Sarver’, ”, 223, 51);