Lecture 3: Editors (Vim)
Modal editing
Operating modes:
- Normal: for moving around a file and making edits;
<ESC> - Insert: for inserting text;
i - Replace: for replacing text;
R - Visual (plain, line, or block): for selecting blocks of text;
v,Vfor line,<C-v>for block - Command-line: for running a command;
:
Basics
Buffers, tabs, and windows
- buffers: set of open files
- tabs: collection of one or more windows
- windows: each window shows a single buffer
Command-line
:qquit (close window),:qato close all windows,q!to discard changes:wsave (“write”):wqsave and quit:e{name of file} open file for editing:lsshow open buffers:help{topic} open help:help :wopens help for the:wcommand:help wopens help for thewmovement
:sp: split window:tabnew
Vim's interface is a programming language
Movement (nouns)
- Basic movement:
hjkl(left, down, up, right) - Words:
w(next word),b(beginning of word),e(end of word) - Lines:
0(beginning of line),^(first non-blank character),$(end of line) - Screen:
H(top of screen),M(middle of screen),L(bottom of screen) - Scroll:
Ctrl-u(up),Ctrl-d(down) - File:
gg(beginning of file),G(end of file) - Line numbers:
:{number}<CR>or{number}G(line {number}) - Misc:
%(corresponding item) - Find:
f{character},t{character},F{character},T{character}- find/to forward/backward {character} on the current line
,/;for navigating matches
- Search:
/{regex},n/Nfor navigating matches
Selection
- Visual:
v - Visual Line:
V - Visual Block:
Ctrl-v
Edits (verbs)
ienter Insert mode- but for manipulating/deleting text, want to use something more than backspace
o/Oinsert line below / aboved{motion}` delete {motion}- e.g.
dwis delete word,d$is delete to end of line,d0is delete to beginning of line
- e.g.
c{motion}change {motion}- e.g.
cwis change word - like
d{motion}followed by i
- e.g.
xdelete character (equal dodl)rreplace characterssubstitute character (equal tocl)- Visual mode + manipulation
- select text,
dto delete it orcto change it
- select text,
uto undo,<C-r>to redoyto copy / “yank” (some other commands likedalso copy);yyline,ywwordpto paste/for next matchnfor next match.repeats previous editing commandAappend to end of line- Lots more to learn: e.g.
~flips the case of a character
Counts
3wmove 3 words forward5jmove 5 lines down7dwdelete 7 words
Modifiers
ci(change the contents inside the current pair of parenthesesci[change the contents inside the current pair of square bracketsda'delete a single-quoted string, including the surrounding single quotes
Customizing Vim
- customize through
~/.vimrc
Extending Vim
- create the directory
~/.vim/pack/vendor/start/ - put plugins in there (e.g. via
git clone)
Exercises
TO-DO
vimtutor- install anid configure a plugin
- advanced vivimm