
The Compositional Nature of Vim (2014) - thangngoc89
http://ismail.badawi.io/blog/2014/04/23/the-compositional-nature-of-vim/
======
jasode
_> What I’m trying to get at is that I never really took the time to learn how
vim worked. I had no clue about the big picture. I didn’t know any concepts.
[...] , really I was just getting by on ad-hoc memorization. [...]_

 _> Composition: The magic of vim is that it’s comprised of lots of small
primitives that compose well together. Among these primitives are motions,
operators, and text objects._

This popular Stackoverflow answer also explains vim's concepts of "verb +
noun":
[https://stackoverflow.com/a/1220118](https://stackoverflow.com/a/1220118)

Also, a lot of beginners are perplexed why vi uses "hjkl" keys for cursor
movement. It's because the 1976 ADM-3A terminal didn't have any dedicated
arrow keys like the 1986 IBM PC 101-key layout:

[https://catonmat.net/why-vim-uses-hjkl-as-arrow-
keys](https://catonmat.net/why-vim-uses-hjkl-as-arrow-keys)

[https://en.wikipedia.org/wiki/IBM_PC_keyboard#Keyboard_layou...](https://en.wikipedia.org/wiki/IBM_PC_keyboard#Keyboard_layouts)

The "hjkl" overloaded with arrow movements is also related to why vi requires
a "insert/append mode" that more modern text editors don't need. In vi, you're
initially in "command mode" and you have to press 'i' or 'a' to insert or
append text. In contrast, if you develop a new text editor after the
introduction of keyboard hardware that has dedicated
arrows/PgUp/PgDn/Home/End/Ins/Del/Fn1-Fn12, you no longer need to architect
the editor software to have 2 special modes. Overloading the A-Z alphabet keys
with non-text commands is what motivates having to switch between 2 modes.
This leads to vi users _repeatedly pressing the Esc key multiple times to
really make sure_ they're no longer in text input mode. Instead of
"<Esc>:wq<Enter>", the vi "wrong mode by accident" paranoia leads to
"<Esc><Esc>:wq<Enter>".

(EDIT ADD: the Esc key double-tap as reflexive muscle-memory may also be
related to _timeoutlen_ which many vi users are unaware of and don't change:
[https://stackoverflow.com/questions/15550100/exit-visual-
mod...](https://stackoverflow.com/questions/15550100/exit-visual-mode-without-
delay))

~~~
chongli
You had a really nice, informative comment about the history of vi and the
weird keyboard of the ADM-3A terminal and then you had to take a cheap shot at
vi users. Why?

I've been using vi/vim/nvim for nearly two decades now and I only press escape
(actually C-[, since I mapped caps to control) once each time I need to get
out of insert mode. I don't have "wrong mode paranoia" because I can see at a
glance what mode I'm in by the appearance of the cursor. When I finish
inserting, the cursor moves one place to the left and highlights the last
character I inserted. In vim it's even easier because the cursor changes
appearance in insert mode.

~~~
jasode
_> you had to take a cheap shot at vi users. Why?_

You misinterpreted. I wasn't taking a cheap shot at vi users. When _I_ use vi,
I press Esc multiple times. My behavior is common and this is apparently
somewhat of an "in joke" among vi users.

It's a behavior similar to pressing 'C' _multiple times_ on calculators to
_really really_ clear out the entry. Pointing out that common behavior is not
"taking a cheap shot at calculator users". Out of habit, I also press C
multiple times on calculators and I don't know why I do that even though my
brain's logic says it's redundant.

[https://www.reddit.com/r/Showerthoughts/comments/a7qeye/the_...](https://www.reddit.com/r/Showerthoughts/comments/a7qeye/the_unspoken_rule_for_using_a_phones_calculator/)

EDIT ADD: related HN thread about the _" :wq"_ string accidentally being saved
in source files because some vi users didn't realize they didn't escape text
insert mode:
[https://news.ycombinator.com/item?id=7798529](https://news.ycombinator.com/item?id=7798529)

~~~
addicted
I’ve never heard of Esc Esc being an in joke amongst Vim users. And I rarely
(never?) hit ESC twice, because it’s obvious when I just tapped ESC, and
because of VIM’s speed I can immediately see when things changed.

Is this a GVim/MacVim thing maybe? Is that slower? Or do all these people
hitting ESC twice somehow have bad keyboards which don’t often transmit the
ESC key signal?

Also, the reason you hit C on calculators twice is because there is actually a
reason to hit it in many calculators, and has no connection with Vim, and the
difference between the 2 modes isn’t obvious. Hitting C once only clears the
current result, but doesn’t clear the previous results. So if you type in 45+
the calculator after hitting C once (assuming you had 46 typed in), the
calculator will add 45 to whatever you had originally. OTOH if you hit it
twice, in many calculators it will also additionally clear out the previous
results, so the 45+ only adds to 0.

~~~
jasode
_> , because it’s obvious when I just tapped ESC,_

I learned vi (not vim) on old DEC and IBM AIX machines via Telnet (not local
GUI). With those more primitive console emulators, the cursor change for
different modes wasn't obvious.

 _> Or do all these people hitting ESC twice somehow have bad keyboards which
don’t often transmit the ESC key signal?_

The Esc-double-tap was a very common way to make sure you're not in text
insert mode:
[https://www.google.com/search?q=vi+"press+esc+twice"+command](https://www.google.com/search?q=vi+"press+esc+twice"+command)

For whatever reason (e.g. possibly unawareness of timeoutlen delay causing Esc
to behave in unexpected ways), many vi users end up redundantly pressing Esc
twice.

 _> Hitting C once only clears the current result, but doesn’t clear the
previous results. _

I thought the newer calculators with dedicated "C" (clear) and "CE" (clear
entry) didn't require pressing "C" multiple times. (I just tested this on a
Texas Instruments desk calculator with dedicated C & CE buttons and it only
requires pressing C once to clear out everything. (But I still press C
multiple times out of habit.))

~~~
addicted
Good to know about the timeoutlen.

Also newer calculators have a distinction. But I’ve definitely used older ones
where both keys were on the same button (separated by a slash?) but I know I
habitually press C twice and it’s likely because the calculator I used most
growing up needed you to press C twice for CE.

------
jamesrcole
It provides a keystroke-based language for working with textual information.
That language embodies concepts that we think of the information and
operations relating to it in terms of -- words, sentences, code blocks, etc,
and deleting, changing, etc these. This allows us to directly translate our
thoughts "I want to delete this sentence" into actions "das".

------
mruts
I use Emacs and have been wanting to try spacemacs or evil because I suspect
that modal editing is more efficient. Moreover my fingers hurt a lot and Emacs
definately isn’t helping.

The only thing preventing me from switching to evil (I would never switch to
vim because it honestly just seems strictly inferior) is that I use Dvorak on
a Kinesis keyboard. I’m not sure how well vim keybindings work on Dvorak, but
I suspect not very well (atleast the hjkl part). Does anyone have experience
with Dvorak and vim/evil? Is it acceptable?

~~~
linsomniac
I've heard a lot of speculation, from the vi camp, that Gosling and Stallman
have RSI that emacs caused. Again, speculation. Google search for it, I can't
find anything worth linking, all speculation.

I do know people who have had wrist problems and found vi more comfortable. I
know when I have to type control sequences I find it painful if I do too much.

I'd say just try it and see if you find it more comfortable. Spend a couple
weeks suffering through a bit less productivity and see where you are at. I
did that a few years ago and am super happy with the results. In my case it
was ditching some bad touch-typing habits and switching to a custom keyboard
layout to optimize for my environment.

As far as Dvorak, I've heard of people typing in Dvorak but doing command-mode
in qwerty. That seems crazy to me, but would definitely work. I can't imaging
switching layouts that frequently in my head, but I guess once you got used to
it it'd be no big deal.

~~~
dmortin
Using emacs doesn't mean you have to use the default keys. I don't, because I
find the defaults bad. I use the arrow keys and other bindings changed to my
taste and my hands don't hurt.

Emacs is only a bunch of defaults which you should adapt to your needs.

