Slides Workshop vi
Hier klicken, um die Datei herunterzuladen
Dateiinhalt
/-------------------------------------------------------------------------\
| |
| |
| LUGBZ Workshop VI(M) |
| |
| |
| ## ## |
| # # # # # # # |
| # # # # ## ## # |
| # # # # # ## # # |
| # # # # # # # |
| # # # # # # # |
| ## # ## # # ## |
| |
| |
| |
| |
| |
| |
| |
| 2007-09-04 - Chris Mair - http://www.1006.org |
| |
| |
\-------------------------------------------------------------------------/
history
* vi stands for visual
* screen-oriented text editor written by Bill Joy in 1976 for BSD
* optimized to edit files over slow / high-latency lines
(mimizes number of key-strokes to get something done)
* optimized for touch-typing
(doesn't require lots of strange CTRL-SHIFT-ALT-whatever combos)
* part of POSIX: every *nix comes with vi in the default install
availability
* OpenBSD 4.1:
vi == nvi
vim is available as optional package
* Mac OS X 10.4:
vi == vim
* Solaris 10:
vi == some ancient version of vi
* GNU/Linux (Ubuntu 7.04 "Feisty Fawn"):
vi == vim-tiny (mimimal vim package compiled to be small)
vi == vim, after installing the optional package vim-full
two editing modes
* start in command mode
* hit 'i' to go to insert mode
-> can edit text there
-> use cursor keys, backspace, etc (unless you have a 1976' vi)
* hit ESC to go back to command mode
* YOU SHOULD STAY IN COMMAND MODE MOST OF THE TIME
* just hit ESC when you stop editing or when you're in doubt
* NEK: vi called as view -> read only mode
get the hell out of it
* so you decided this workshop was boring...
... then at least get this:
:wq -> save and quit
:q! -> exit without saving
* NEK: ZZ is the same as :wq
inserting is i, right?
* there's more!
i -> insert at cursor
I -> insert at begin of line
a -> insert after cursor (append)
A -> insert after the end of the line
o -> insert new line after cursor and insert
O -> insert new line before cursor and insert
move around quickly
* does a feisty fawn move quickly?
* try these:
h j k l -> cursor (vi was invented before cursor keys!)
b e -> move to begin/end of word
0 ^ -> start of line / first non-blank char in line
$ -> end of line
G -> end of file
* YOU CAN PREFIX ANY OF THESE WITH A NUMBER!
G is often used:
100G -> move to line 100
delete things
* deleting chars when DEL or BACKSPACE don't cut it:
x -> del
X -> backspace
* YOU CAN PREFIX ANY OF THE MOVEMENT COMMANDS WITH d!
d$ -> delete rest of line
etc...
* more:
dd -> delete line
* everything is prefixable with numbers, example
4dd -> delete 4 lines
changing, replacing, undo
* c is like d, but it switches to insert mode immediately
* replacing:
r -> replace single char under cursor
R -> overwrite mode
* undo / redo
u -> undo
CTRL-R -> redo
* POWER-NEK: . repeats last insertion
copy & paste
* copy
y works like d
yy -> copy whole line
20yy -> copy 20 lines
3ye -> copy 3 words (e -> end of word)
* paste
P -> paste before cursor
p -> paste after cursor
* NEK: xp -> easiest way to exchange 2 chars!
* NEK: J -> join lines
searching
* search:
/findme -> find next
?findme -> find previous
n/N -> redo find / redo find other direction
% -> find matching parens
# / * -> find prev / next word under cursor
* :set ic -> set case insensitive search mode
* SUPER-POWER-NEK[VIM]: CTRL-p -> complete word (inverse search)
* search and replace:
: where s / from / to / [g]
where == % -> the whole file
help!
* vim has a built-in tutorial:
vimtutor
vimtutor de
vimtutor it
* there's online help:
:help
* google for "vim cheat sheet" or "vi reference guide"!
example:
http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
colours / visual selection [VIM]
* you might need (bash): export TERM=xterm-color
* :syn on
* I usually limit colours (see my .vimrc)
* visual selection:
1: v -> start selection
2: do stuff
3: x or y
programming support
* auto identation (I don't use it :)
* manual identation
> -> indent
< -> unindent
= -> autoindent selected block
* ctags (= external program you need to run)
CTRL-] -> open function definition
CTRL-t -> go back
* macros
q a-z do stuff q -> record as name a-z
@ a-z -> play back a-z
* merge file
:r filename
my .vimrc
" show tabs as 4 spaces long (instead of 8)
set tabstop=4
" indent 4 spaces (instead of 8)
set shiftwidth=4
" put spaces instead of tabs (warning: Makefiles don't like that)
set expandtab
" use syntax hilighting, but not too many colours
syn on
hi clear Normal
hi Constant ctermfg=Black
hi Special ctermfg=Black
hi Statement ctermfg=Black
hi Identifier ctermfg=Black
hi Type ctermfg=Black
hi PreProc ctermfg=Black
hi Comment ctermfg=DarkBlue
hi String ctermfg=DarkRed
license
* This work is licensed under the Creative Commons Attribution-ShareAlike 2.5
Italy License - see
http://creativecommons.org/licenses/by-sa/2.5/it/