6. Command Mode
• Certain keys perform certain
actions.
• Ie. hjkl are all used in command
mode.
• To enter command mode
simply press escape.
7. Insertion Mode
• In Insert mode, anything you
type is simply text in your file.
• To enter insertion mode
• i= insert
• a= append
• O = open new line
• Among others…
8. Sed Mode
• In Command mode type “:” to
enter Sed Mode.
• In sed mode any SED command
can be applied to your text.
• Ie. %s/t/ /g will substitute all
tabs with 4 spaces in your text
file.
9. Copy & Paste
• To copy paste you “yank” the
lines
• y[x]y will yank x number of lines
• To cut you delete the lines
• d[x]d will delete x number of lines
and store them in the buffer
• To delete lines simply cut them.
10. Copy and Paste
• To Paste use the P command
• p= insert line after current
position.
• P= insert line before current
position.
• Note: you can cut/paste in sed
mode as well as command mode.
12. MOST IMPORTANT CMD
• The most important command
for any newbie.
• U/u= undo
• It might just save your life….or
your code.
13. Searching for text.
• /Pattern will search for pattern
specified.
• /?Pattern will search for pattern
specified backwards.
• n= find next occurrence
• N = find prev occurrence
14. Open-Close-Save, etc.
• To Save a file:
• Sed Mode:
• w= writes changes
• x= writes and quits
• Cmd Mode:
• ZZ= writes and quits
• To Close a file:
• q= closes and quits program.
15. Open-Close-Save, etc.
• To override any command
• Ie. To exit without saving, to force
write on a read-only file, etc.
• Append ! To any command
• q!= quiets w/o saving
• w!= writes read-only
16. Coding uses.
• Assuming u’ve run ctags on your
program
• ]] advances to next function
• [[ advances to previous function
• :!make compiles program
• :!pgm-name runs program
• ALL within VIM.
17. Tips & Tricks
• :r !my_cmd
• Runs my_cmd and inserts output in
current session.
• :g/.*/m0
• File line reversal (line 1 = $, line $=
line1)
• :g/^/m0 – same as above
• :1,$s’^M”g
• Remoes dos r from text file, ie. Converts
to unix format
18. Tips n Tricks
• set number
• Display line numbering, useful for
sed use
• Set nonumber to disable
• set ts=4
• Sets tabspace to any number of
spaces desired.
19. Tips n Tricks
• :line-num will take u directly to
that line.
• Ie. Compiler error line 157
• Vim file 157 or….
• :157 while in vi
20. Folding
• set foldenable
• Move cursor over the magic
char pres %z, followed by zf
• zo opens folder
• zc fold close
21. Macros
• Press q to enable recording
mode, followed by the bound
key.
• Press q again to get out of
macro mode.
• Then call the macro using
%<bindkey>
22. Customized startup
• Create a .exrc (or .vimrc) file in
your $HOME dir to start vim the
way you like it.
• Setting tabspaces, behavior,
colors scheme, etc.
23. URLS of note.
• www.vim.org
• Scripts, themes, macros, and
goodies as well as tutorials
• Source file.vim
to load a script/macro.
• www.oreilly.com
• Some excellent e-books as well as
hardcover books on sed and vim