17
March 20, 2009 What Every Vi User Should Know about Vim

What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

What Every Vi User Should Know about

Vim

Page 2: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Getting Started

• Microsoft Windows users – Get Vim from http://www.vim.org

• Linux users, check to see that the advanced version of the Vim package is installed.

• Bleeding edge user, get the source at http://www.vim.org

Page 3: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Unix Vim Starts in Vi mode unless you tell it different

• Create a .vimrc file to turn on many of Vim’s nicer features.$ touch ~/.vimrc

• Starting Vim with it’s own window.$ gvim {file}

Page 4: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

First Differences

• The undo (u) command handles multiple levels. (Use CTRL-R to redo a command.)

• Vim has a help system that is mostly complete and actually useful::help

Page 5: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Help System

• Normal commands:help d:help CTRL-D:help :s

• Help for options:help 'sw'

• Insert mode commands:help i_CTRL-D

• Help for visual mode commands:help v_d

Page 6: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Splitting Windows

• Open a new window:split {file}

• Close a window:q

ZZ

• Up / Down windowsCTRL-Wj CTRL-Wk

Page 7: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Vertical Windows

• Vertical Spliting:vsplit {file}

• Any command which opens a window can be preceeded by::vertical

• Left / Right windowsCTRL-Wh CTRL-Wl

Page 8: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Building Programs

• Start a build:make

• Current, next, previous error:cc:cn:cp

• Open a window with the list of errors:copen

Page 9: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Searching Options

• Highlight searches:set hlsearch

• Turn it off (for now):nohl

• Incremental searches:copen

Page 10: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Visual Mode

• Character visual modev (lower case)

• Line visual modeV (upper case)

• Block visual modeCtrl-V

Page 11: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Indenting

• Setting the indent size:set sw=4

• Turning on C Style Indentation:set cindent

• Indenting a block of text (from { to } )=%

v%=

Page 12: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Spelling

• Turn on spell checking:set spell

• Word correctionz=

Page 13: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Tabs

• Change tabs into spaces (on insert):set expandtabs

• Changing tabs into spaces (in a file)1g!Gexpand

• Do not turn expandtabs for Makefiles.

Page 14: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Seeing Tabs

• Seeing the invisible:set list

• Seeing normal:set nolist

Page 15: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Autocommands

• In your .vimrc:autocmd FileType *.[ch]

\ set cindent,expandtabs

Page 16: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Keyboard Macros

• Starting a keyboard macroqa

• Ending a macroq

• Executing macro@a

Page 17: What Every Vi User Should Know about Vimoualline.com/talks/vim/vim-for-vi.pdf · 2009-03-21 · March 20, 2009 Unix Vim Starts in Vi mode unless you tell it different • Create a

March 20, 2009

Abbreviations and Mappings

• Defining an abbreviation:define #i #include

• Defining a keyboard mapping:map <F7> =%