1. How to vim
author: Marcin Rogacki <mrogacki@nexway.com>, <rogacki.m@gmail.com>
experience in vim: 6 months
2. Why try?
1. Successfully used as IDE by others.
2. Don’t need X enviroment (Production quick fix? No problem!)
3. Lightweight & fast.
4. Able to edit large files 50MB, 100MB, 1GB (Ok... search the 1GB file is
an horror but still is openable).
5. Code is written faster (with enough vim experience).
6. Your keyboard skills will be improved.
3. place of new recruits is to the proving ground
run shell command: vimtutor
training
4. Now time for ‘Missions’.
They show practical tricks (at least I have hope
that they are practical) or just examples how to
fight with vim.
6. ● move: hjklweb$0gGf
● edit: aiorxdvc
● search: /nf
● undo and redo: u, ctrl+r
● copy & paste: ypdx
combine all of above into “advanced basics”
don’t use arrows or mouse!
Armory
7. output
input
Mission: delete from here to end
Accomplished: d,shift + g
line no. 1
line no. 2
line no. 3
line no. 4
line no. 5
line no. 1
line no. 2
8. output
input
Mission: delete from here to line 4
Accomplished: d,4,shift+g
line no. 1
line no. 2
line no. 3
line no. 4
line no. 5
line no. 1
line no. 5
9. output
input
Mission: copy & paste - line
Accomplished: yy,j,p
line no. 1
line no. 2
line no. 3
line no. 4
line no. 5
line no. 1
line no. 2
line no. 3
line no. 4
line no. 3
line no. 5
10. outputinput
Mission: cut & paste - text refactoring
Accomplished: v,w,d,p
$product->setName(‘Not so very long name’);
$name = ‘Not so very long name’;
$product->setName($name);
11. outputinput
Mission: cut & paste - text refactoring v2
Accomplished: v,f,’,d,p
$product->setName(‘Not so very long name’);
$name = ‘Not so very long name’;
$product->setName($name);
12. outputinput
Mission: cut & paste - text refactoring v3
Accomplished: d,f,’,p
$product->setName(‘Not so very long name’);
$name = ‘Not so very long name’;
$product->setName($name);
13. outputinput
Mission: cut & paste - text refactoring v4
Accomplished: c,f,’,p
$product->setName(‘Not so very long name’);
$name = ‘Not so very long name’;
$product->setName($name);
19. Armory
:edit <file> - open in current window
:newtab <file> - open new tab
:vsplit <file> - vertical split and open
:split <file> - horizontal split and
:r <file> - read content into current file
:! - execute shell command
:<text> - is a vim command
ctrl + ww - switch tab
gt - next window
20. output
input
Mission: copy & paste from other file
Accomplished: :r docs/beer-license.txt
License License
THE BEER-WARE LICENSE:
Can do whatever you want.
You can buy me a beer in return.
21. output
input
Mission: copy & paste shell console
Files list
Accomplished: :r !ls -l
Files list
code/file.php
lib/file.php
public/file.js
22. output
input
Mission: copy&paste between tabs/windows
Accomplished: g,t,y,y,g,t,p
Some text window 1
Some text window 2
Some text window 1
Some text window 2
Some text window 2
29. how to use macros
1. find some ‘regularities’
2. record macro by q and pick an <register> (e.g. ‘a’ key)
3. work as usual with vim
4. stop recording by q
5. set cursor at next ‘regularity’ <number of repeats>@<register>
30. output
input
Mission: add ‘irregular’ text
Accomplished: qakf(wyw0jf(pa,ESCF(wctrl+a0jq10@a
Before start ensure that cursor is set at 2-nd line, keys: ggj. Then just invoke this sequence.
INSERT INTO category VALUES(1,'Basics');
INSERT INTO category VALUES('Request');
INSERT INTO category VALUES('Render',);
INSERT INTO category VALUES('EAV');
INSERT INTO category VALUES(‘Admin');
INSERT INTO category VALUES('Catalog');
INSERT INTO category VALUES('Model');
INSERT INTO category VALUES('Helper');
INSERT INTO category VALUES('Config');
INSERT INTO category VALUES('System');
INSERT INTO category VALUES('Shell');
INSERT INTO category VALUES('Db');
INSERT INTO category VALUES(1,'Basics');
INSERT INTO category VALUES(2,'Request');
INSERT INTO category VALUES(3,'Render',);
INSERT INTO category VALUES(4,'EAV');
INSERT INTO category VALUES(5,‘Admin');
INSERT INTO category VALUES(6,'Catalog');
INSERT INTO category VALUES(7,'Model');
INSERT INTO category VALUES(7,'Helper');
INSERT INTO category VALUES(8,'Config');
INSERT INTO category VALUES(9,'System');
INSERT INTO category VALUES(10,'Shell');
INSERT INTO category VALUES(11, 'Db');
39. 1. Vim is not better than other IDE's. It is different. There is advantages
and disadvantages e.g. I think native IDE will alwasy have better code
autocomplete.
2. Before grabbing a mouse, early try do it with keyboard. Power of vim
is: to be always ready for text typing.
3. Beginnings are difficult, but after time will appear the conditioned
response, in the other words copy&paste/movement/refactor will take
milliseconds.