1 / 19

VIM: The basics

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.

mimis
Download Presentation

VIM: The basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VIM: The basics Tang Wai-Chung, Matthew (MaFai) 29/12/2006

  2. Contents • Why VIM? • Basic Editing • Searching • Copy & Paste • Programmers’ Tools • Configuration

  3. 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.

  4. 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.

  5. 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

  6. 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

  7. 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.

  8. 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.

  9. 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

  10. 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.

  11. DEMO TIME!

  12. 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)

  13. 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}>

  14. 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

  15. 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: <%>

  16. DEMO TIME!

  17. 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!

  18. 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.

  19. 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.

More Related