190 likes | 375 Views
VIM: The basics. Tang Wai-Chung, Matthew (MaFai) 29/12/2006. Contents. Why VIM? Basic Editing Searching Copy & Paste Programmers’ Tools Configuration. Why VIM?. VIM is one of the most powerful text editor in which you can enter the most letters with less number of keystrokes.
E N D
VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006
Contents • Why VIM? • Basic Editing • Searching • Copy & Paste • Programmers’ Tools • Configuration
Why VIM? • VIM is one of the most powerful text editor in which you can enter the most letters with less number of keystrokes. • Reader’s Choice of “Linux Journel” in 2003. • Highly configuarable • Strong support community, including me.
Modes in VIM • In normal mode of VIM, you issue commands instead of inserting letters. • You can enter to insert mode by pressing <i>, <a> ,<o>, etc .. • Insert mode, you can type as you do in notepad. • Return to normal mode by pressing <ESC> • Visual mode will be explained later.
Move around • You can use cursor keys or <h> = left; <l> = right; <j> = down; <k> = up • <Ctrl-u> = up half page<Ctrl-d> = down half page<Ctrl-b> = back 1 page<Ctrl-f> = forward 1 page
Move around (cont...) • <$>: end of line; <^>: beginning of line; <0>: first position. • <{no}G>: go to line {no} • <gg>: beginning of file • <G>: end of file
To Insert Mode ... • <i>: insert at current position. • <a>: insert ONE letter after current position. • <I>: insert at beginning of line. • <A>: insert at end of line. • <o>: insert in a new line down. • <O>: insert in a new line up.
Save & Quit • <ZZ>: write file and exit (time to sleep!) • <:w>: save with same name • <:q>: quit • <:wq>: save and quit • When you add ‘!’ at the end of w or q, you force to execute the command. • <:sav {filename}>: save as.
Deleting ... Undo / Redo • <d{type}>: delete 1 object of {type} • <dd>: delete a line • <dw>: delete one word • <dl>: delete one letter = <x> • <c{type}>: change 1 object • <s{type}>: substitute 1 object • <u>: undo • <Ctrl-r>: redo
Counting in Commands • Actually you can put numbers in most commands in VIM, e.g. <o>, <d>, <c> • <d3w>: delete 3 words • <3dw>: delete 1 word 3 times • <10x>: delete 10 letters • Also, you can repeat the last commands by <.> • <x..> will delete 3 letters.
Searching • </{key}>: search the word {key} in the file • <n>: next match • <N>: last match • <?>: Change direction • </.>: any single char (wildcard)e.g. </.a>: search *a • <*>: search the word under the cursor (forward) • <#>: search the word under the cursor (backward)
Copy & Paste • Copy is called yank in VIM • <y{n}{type}>: yank {n} object • <y2006y>: yank 2006 lines • <y2020l>: yank 2020 letters • <p>: paste down / after • <P>: paste up / in front of • How about CUT? use <d{n}{type}>
Editing More Files • You can edit several files in one instance of VIM • <:split>: split the window and get one more editing space • <:new {filename}>: edit the file in new space • <Ctrl-w> + <n>: Open a new horizontal space • <Ctrl-w> + <v>: split vertically • <Ctrl-w> + <h,j,k,l> (or cursors): move around space • File browser: <:e {directory name}> you can get a file listing • O: open in last space
Programmers’ Tools • Syntax Highlighting: automatically loaded(if you have a good .vimrc)<:syn on> or <:syn off> • Auto-indentation: <:ai> or <:noai>indentation style for C, C++, Java<:set cindent> • Finding out variable declaration: <gd>, <gD> • Checking pairing brackets: <%>
Configuration • VIM reads .vimrc from home directory (or installation directory in M$) whenever it starts. • .vimrc contains all basic mapping, declaration and setting. • Initialize the editing environment. • You can use my .vimrc freely and edit to suit your own needs. • See the contents!
Finding Help • http://www.vim.org/Download, install, documentation, plugin, tips …much more • Tutorialhttp://www.newriders.com/books/opl/ebooks/0735710015.htmlin which this presentation based on • Vi Lovers:http://www.thomer.com/vi/vi.html • <:help {feature}>: show the help content built in.
Q & A • You may ask anything you want to know about vim. • I will try to answer as far as I know the solution. • Finally thank you once again your attendance.