Vim and EMACS are the two most popular editors.
Of all time.
Why?
They introduced new ideas about what an editor should be.
"An editor should be extensible."
This lesson has been learned and adopted.
"An editor should be composable."
Atom's API provides the following
deleteToBeginningOfLine() deleteToBeginningOfSubword() deleteToBeginningOfWord() deleteToEndOfLine() deleteToEndOfSubword() deleteToEndOfWord() deleteToNextWordBoundary() deleteToPreviousWordBoundary()
It has a small number of primitives that compose well together.
A motion moves you from one place to another.
hello, my foxy friend
l
hello, my foxy friend
hello, my foxy friend
e
hello, my foxy friend
hello, my foxy friend
w
hello, my foxy friend
hello, my foxy friend
W
hello, my foxy friend
hello, my foxy friend
tx
hello, my foxy friend
hello, my foxy friend
fx
hello, my foxy friend
hello, my foxy friend
$
hello, my foxy friend
(This example is
(a little more) complicated. See?)
)
(This example is
(a little more) complicated. See?)
(This example is
(a little more) complicated. See?)
])
(This example is
(a little more) complicated. See?)
(This example is
(a little more) complicated. See?)
/ated
(This example is
(a little more) complicated. See?)
All motions have a "backwards" version.
b ← w
( ← )
Unless there is an obvious subtitute, the backwards version is usually capitalized.
F ← f
? ← /
hello, my foxy friend
b
hello, my foxy friend
Additionally, motions can also take a count.
there are lots of 'e's here
fe
there are lots of 'e's here
4fe
there are lots of 'e's here
:help motion
for so many more.
You can also write your own!
We also have operators.
An operator is Vim's idea of a targeted side-effect.
It's a verb!
d→
"Delete something."
What is "something?"
there are lots of 'e's here
w
there are lots of 'e's here
dw
are lots of 'e's here
there are lots of 'e's here
4fe
there are lots of 'e's here
d4fe
's here
int x(bool foo, void* task) {
])
int x(bool foo, void* task) {
d])
int x(bool ) {
There are several other operators.
Delete some text and leave you in insert mode.
c→
Use it to replace text.
Copy some text into the clipboard.
y→
You can paste it later with
p
vim is very cool
ywP
vim is very very cool
Whenever you delete or change text, the text that disappeared is moved into your yank clipboard.
vim is very cool
dw4P
vim is very very very very cool
ys→⏣
Surround the text described by a motion with some character.
wulky wilkenson is a post-utopian
ys$"
wulky wilkenson is a "post-utopian"
10 - 6 - 4
ysf4)
10 - (6 - 4)
ysf4(
10 - ( 6 - 4 )
In general, the "open" character inserts spaces.
marvelous
ysw<span>
marve<span>lous</span>
=⏣
int blah() {
return 0;
}
=G
int blah() {
return 0;
}
Doesn't work super well for Haskell, unfortunately.
:help operators
for so many more.
You can also write your own!
Text objects are somewhere between motions and filetype-specific syntax.
They let you describe things like:
A text object is always contiguous text.
You can't move by a text object, but you can operate on one.
mconcat [a, b, c]
⨳aa
mconcat [a, b, c]
daa
mconcat [a, c]
Most text objects target inside (excluding) or around (including) some structure.
mconcat ["hello", "goodbye"]
⨳i"
mconcat ["hello", "goodbye"]
⨳a"
mconcat ["hello", "goodbye"]
mconcat ["hello", "goodbye"]
⨳i]
mconcat ["hello", "goodbye"]
⨳a]
mconcat ["hello", "goodbye"]
Text objects can help if your cursor isn't in the right position for a motion.
I will bring doom cookies
dw
I will bring docookies
daw
I will bring cookies
:help text-obj
for so many more.
You can also write your own!
Why? Composition!
.
Perform the last operation again.
fooBar fooBar
dtBiqux↑
quxBar fooBar
w.
quxBar quxfooBar
fooBar fooBar
civqux↑
quxBar fooBar
w.
quxBar quxBar
Do exactly what you need in insert mode, and no more.
(with some caveats)
data Enum = Foo
| Bar
| Baz
⒱f=l2j
data Enum = Foo | Bar | Baz
x
Foo
Bar
Baz
gv
Foo Bar Baz
I, ↑
, Foo
, Bar
, Baz
import Data.Map
import Data.List
import Control.Monad
-- don't touch me
Vip
import Data.Map import Data.List import Control.Monad -- don't touch me
:sort↵
import Control.Monad
import Data.List
import Data.Map
-- don't touch me
Registers are generalizations of the copy/paste clipboard.
They're "variables" you can stick text into.
Registers are named like this:
"a
"b
"c
There are lots of registers available!
They can be combined with operators:
"r⨳
three two one
"bdaw
three one
"adaw
three
0"aP"bp
onetwo three
Use registers to keep track of lots of pieces of text simultaneously!
There is an implicit, default register used if you do not specify one.
""
This is where autoyanked text goes.
You can work with registers in insert mode by pressing.
⒭
:help registers
for all of the magic registers (like automatic math evaluation!)
q⏣
Records your keystrokes and puts them into register ⏣.
Press q to exit again.
It's a code-to-data transformation.
Make the edits you want, and export/reuse them!
qziHello world!↑ddq
"zp
iHello world!↑dd
(it's not, on its own)
@⏣
The inverse transformation! Run data as vim commands!
99 bottles of beer on the wall!
qbyyp⒳q
99 bottles of beer on the wall!
98 bottles of beer on the wall!
98@b
99 bottles of beer on the wall!
98 bottles of beer on the wall!
97 bottles of beer on the wall!
...
1 bottles of beer on the wall!
0 bottles of beer on the wall!
Keep macros in mind when you're doing repetitive, mechanical yet non-trivial edits.
Space | Forward |
---|---|
Right, Down, Page Down | Next slide |
Left, Up, Page Up | Previous slide |
P | Open presenter console |
H | Toggle this help |