Welcome
Basic Vim
ACM Student Chapter
Radford University
November 9, 2011
Presentation Plan
- Today
- Introduction
- The basics: vimtutor
- Essentials for day to day use
- Installing
- A few more hints
- Next time
- More commands
- More configuration
- Some scripting
- Have Fun!
Benefits of Vim
- fast: keep fingers on keys
- fast: powerful commands use minimal keystrokes
- powerful editing features (eg column operations)
- highly configurable (eg smartcase - ignores case in searches unless ...)
- extensible: scripting language built in, can also use perl, ruby, python
- ubiquitous: available on virtually any system
- use same environment for programming in any language
History
- vi: visual editor - Bill Joy - 1976 - BSD Unix
- Vim ex mode gives an idea of life before visual editors: Q, p, #p, #, -3,.+3p, z#=
- Q: Enter ex mode
- vi: Exit ex mode and return to normal mode
- Display current line: p, #p, #
- Display range of lines without moving: z#=
- Display range of lines and move: -3,.+3p
- Move: -3 [relative], 3 [absolute]
- Substitute old to new: s/old/new/
- Change line to new lines: c [enter lines; enter . to stop]
- Undo: u
- Vi was a HUGE improvement!
- Vi-IMitation - Bram Moolenaar - 1991
- Vi-IMproved - Bram Moolenaar - 1992
- Vim 5 - 1998
- Syntax highlighting
- Scripting language
- Vim 6 - 2001
- Folding
- Vertical splits
- Diff mode
- File Browser
- Command Window
- Vim 7 - 2006
- spell checking
- Dictionary in scripts (ie objects lite)
- Omni completion (ie intellisense)
- Tabbed editing
- Current: Vim 7.3 on windows (7.3 on Ubuntu)
Important for Newcomers
- vim uses modes
- To shift for regular mode to insert mode, press i (or other commands)
- To shift from insert mode to regular mode, press escape
- to exit without saving changes: esc :q! enter
- to exit and save changes: esc :wq enter
Vimtutor
- A special session of vim that directs you to learn as you read
- To run vimtutor
- Windows: Select Programs/COST/Editors/Vim 7.x/vimtutor
- Linux command line: vimtutor
- We will do first 4 lessons or so
Vimtutor Command Listing
1. hjkl, :q!, x, i, esc, A, wq
[modes, status line, case sensitive, muscle memory]
2. dw, d$, d motion, count motion, d number motion, dd, u, U, ^r
3. p, r, ce, cw, c$, c count motion, esc
4. ^G, G, gg, number G, /, ?, n, N, ^o, ^i, %,
4.4 :s/old/new/, :s/o/n/g, :#,#s/o/n/g, :%s/o/n/g, :%s/o/n/gc
5. :!, :!ls, :w fname, v move :w fname, :r fname, :r !ls
6. o, O, esc, a, R, v move y, yw
6.5 :set ic, hlsearch, incsearch, hls, is, noic, /foo\c
7. , :help, ^W^W, :q, vimrc, :anything^D,
Vim Essentials
Installation
- Vim.org: The main vim page
- Download gvim73.exe to install on windows
- Two versions:
- Command line: vim
- GUI: gvim
- On Windows, you will probably want to choose the batch files option to get a
command line version of vim
- Note for students in ITEC 320: Vim ada make command requires a project file
- fixes are described in the 320 pages
Online References and Other Stuff
- Vim.org: The main vim page
- My Reference Page (lots of commands, operators, motion, objects)
- Other cool things:
- Vimperator
- shell vi key bindings put bindkey -v in .cshrc
(works in tcsh; don't know about others)
- Dr. Chip's Vim Page has lots of nice stuff
- User Manual and other documentation is
here
- From within vim, get User Manual with :h user-manual
- From within vim, get Quick Reference with :h quickref
- Google
- Wikipedia
- Some reference pages:
Books
Advice
- Use help, vimtutor, online manuals, and the web
- Learn frequently used operations until they are muscle memory:
- Basic movement - character, line, word, screen, top, bottom: hjkl, w, e, ^F, ^B, gg, G
- Input: i, a, A, o, O, r, R
- Changing characters (r, R), words (cw), lines (cc, C)
- Delete: x, dw, dd
- Search: /foo, ?, n, N, f, F, t, T
- Substitute: :s/old/new, :%s/old/new/gc
- Yank and paste: yy, Y, p, P
- Swap lines and characters: ddp, xp
- Use counts
- Undo, redo: u, ^R
- Help: :help
- Ranges/blocks: v, V, ^V
- Use operators with movement, text blocks, ranges
- <TAB> completion (supertab plugin may be required)
- Add new commands as needed
- The more you learn, the easier it is to learn (because it's well designed)