
Learn Vim (the Smart Way): a book to learn the good parts of Vim - bwidlar
https://github.com/iggredible/Learn-Vim
======
rubyn00bie
Two things that helped me more than anything with "learning" vim and or ever
wanting to use it:

1\. Remap your "capslock" key to "escape." Vi was written using an ADM-3A
terminal and its keyboard, which you can see here: [https://catonmat.net/why-
vim-uses-hjkl-as-arrow-keys](https://catonmat.net/why-vim-uses-hjkl-as-arrow-
keys) has the escape-key in a sane place. On modern keyboards, if you can,
remap "capslock" to "escape" when pressed alone, and "ctrl" when pressed with
another key.

2\. Make your leader key something easy like the comma character "," E.g. to
make a horizontal split, I press (not including quotation marks) ",h" or ",v"
to make a vertical one.

Once I did those two things it all made so much more sense... It's also great
because most editors these days support vim bindings, so even if you don't
want to use vim you can still benefit from its really-awsome-once-you-figure-
it-out UX.

~~~
JoshMcguigan
When I was first learning Vim I remapped caps lock to escape, and it was a
huge improvement. But as I became more comfortable in Vim I realized I was
using the control key a lot.

I've since remapped caps lock to control, and use ctrl-[ as escape (this is
default behavior). I find having an easily accesible control key is very
useful, even outside Vim. You can see in your link that it is actually the
control key that used to be in the position we now put the caps lock key.

It does seem like remapping caps lock to escape when pressed alone and control
when pressed with another key would be nice, but that wasn't an option for me
(on wayland) as far as I know.

I bring this up only because there was a week or two transition period when I
made this change, and I probably would have been better off if I had mapped
caps lock to control from the start.

~~~
lmohseni
On Linux and Mac it’s possible to have caps be escape when pressed alone or
control when pressed with another key. On Linux the software is called xcape.
:)

~~~
kranner
On Mac, there is Karabiner-Elements.

[https://karabiner-elements.pqrs.org/](https://karabiner-elements.pqrs.org/)

~~~
deltron3030
Here's a Karabiner tutorial that worked for me:
[https://medium.com/@pechyonkin/how-to-map-capslock-to-
contro...](https://medium.com/@pechyonkin/how-to-map-capslock-to-control-and-
escape-on-mac-60523a64022b)

------
thesuperbigfrog
The best way to understand and use vim is to learn the "grammar" of vim and
then practice using it until you have muscle memory for common movement and
editing commands.

This stackoverfow post explains how the vi/vim "grammar" works:

[https://stackoverflow.com/questions/1218390/what-is-your-
mos...](https://stackoverflow.com/questions/1218390/what-is-your-most-
productive-shortcut-with-
vim#:~:text=Your%20problem%20with%20Vim%20is,want%20to%20cut%20whole%20lines.&text=If%20you%20only%20understand%20basic,of%20%22notepad%22%20for%20you).

A fun way to develop the muscle memory for the normal mode movement keys is to
play Nethack ([https://www.nethack.org/](https://www.nethack.org/)) with the
number_pad option set to 0 so that hjkl are used for movement, the same basic
keys for vi/vim normal mode
([https://nethackwiki.com/wiki/Options#number_pad](https://nethackwiki.com/wiki/Options#number_pad)).

~~~
ma2rten
Do you really? I've been using as my primary editor for last 10 years or so, I
rarely make use of the grammar. I sounds fancy and powerful in theory but I
don't end up using it that often (even though I'm aware of it).

That said I'm probably only an intermediate user, because I haven't put in the
time to really make things like markers and macros part of my editing habits.

~~~
mjbrownie
Thats fine. The main thing is not to confuse technique with repertoire.. like
a musical instrument, putting time in to mastering scales and finger technique
will get you a lot of finesse in tackling musical pieces but it's the quality
of your repertoire (in this context the algorithms/languages/higher problem
solving knowledge) is what will be what gets you the money. Still a practising
a few scales every now and then...

------
naveguese
About a month ago, I forced myself to try and use _nvi_ , an (almost) narrowly
compatible classic vi clone.

I thought of it as an exercise in constraint, with the aim of getting better
at vim. Like vanilla vim without plugins, but Nightmare Difficulty.

I've now completely fallen for it. It's missing most mainstream features and
still, I... like it more? I feel like a hipster typing this, but there really
is a difference in brainfeel between using a ''huge'' editor I'll never grasp
fully versus a tiny one I can learn completely. Tiny sparks joy.

Wikipedia entry on nvi:
[https://en.wikipedia.org/wiki/Nvi](https://en.wikipedia.org/wiki/Nvi)

Edits: grammar, punctuation.

------
semicolonandson
For the vim enthusiasts reading, I'd like to bring to your attention some
other resources released in the last few months

— ThePrimeagen (YouTube):
[https://www.youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw](https://www.youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw)

— Vim Tricks (newsletter/Twitter):
[https://vimtricks.com/](https://vimtricks.com/)

— and humbly, myself, Semicolon&Sons:
[https://www.youtube.com/watch?v=futay9NjOac&list=PLpkoC9yJXD...](https://www.youtube.com/watch?v=futay9NjOac&list=PLpkoC9yJXDKkm4MStIQoieUPwNjO4Rb_M)

~~~
sassyboy
+100 for ThePrimagen on Youtube. His videos are great for people looking to
get started with Vim.

------
hombre_fatal
I started Vim when the internet went out once and, bored, I finally tried
`vimtutor` on the debian command line.

It just opens vim to a txt file that incrementally explains how to make basic
edits. I was instantly hooked when I realized how much time "o" and "O" alone
would save me over.

I almost never use Vim these days because I was too lazy to port my .vimrc +
Vundle plugins to a new laptop at some point, but I use a Vim-mode in every
editor I use, even the browser.

~~~
mettamage
My vimtutor experience was redoing it in the subway for a week. That got some
muscle memory in :)

------
stevebmark
I'm sorry to say it, but don't bother with this. It's unfinished and not in
depth. The most important Vim resource is "Practical Vim" by Drew Neil. If you
haven't read it you shouldn't be using Vim.

------
wraithy
The name could be a reference to learnvimscriptthehardway.stevelosh.com, which
is an amazing resource.

~~~
WalterGR
Link:
[https://learnvimscriptthehardway.stevelosh.com/](https://learnvimscriptthehardway.stevelosh.com/)

------
Normille
I'm not a Vim master, but I use it a fair bit --mostly for writing server
admin, single doc coding, etc. I think I know enough to do the basics like
moving chunks of text around, copying/pasting etc. so that I feel fairly
productive in that I can do those things as fast [or faster] in Vim as I could
in a GUI editor..

But, any time I'm working on something more than a single doc [eg. a website,
or a coding project] I reach for something else. I've just never been able to
find a way to use Vim comfortably in a multi-document project, without feeling
like I'm being a lot less productive than I would be using a GUI, such as
TextMate with its built-in project file browser and excellent project wide
find/replace.

I'm learning Flutter at the moment and just got into using IntelliJ [in its
Android Studio guise] and, at first I installed the IdeaVim plugin, thinking
this would give me the best of both worlds; the speed of moving about within
single documents of Vim, combined with the project management & code
completion capabilities of a dedicated IDE. I ended up disabling it after a
couple of days. The mental context switching caused by jumping back and
forward between keyboard driven and menu driven operation was just slowing me
down, rather than speeding me up.

As an aside: I don't really get why the _" Vim saves you having to hunt for
menu items"_ mantra is still so prevalent in this day and age anyway. Maybe in
the past when people had to reach for their mouse to find a menu item, it was
a valid point in Vim's favour. But a lot of us are working on laptops these
days and, frankly, accessing a menu item by tapping on a trackpad right under
your fingers is hardly more hassle than recalling some arcane keyboard
incantation to do the same in Vim. Plus, most regularly used menu items have
keyboard shortcuts which pretty soon become muscle memory anyway. I've not
needed to use a menu to access an Open / Close / Save / Save As / Print / Copy
/ Cut / Paste / Find / Replace / Undo / Redo / Quit... etc. etc. command in
decades.

~~~
bpanon
ctrl-o/ctrl-i to move between buffers

list buffers w/ vim-buftabline

`nnoremap ; :Buffers<cr>`

------
wintorez
Ah Vim, one of the root causes of my imposter syndrome. (The others are CSS
Grid, and Kubernetes)

~~~
renewiltord
Kubernetes very easy to use, worth learning imho. One hour's worth effort
yields great advantage for work.

Vim not worth learning to use as adult. Time too valuable. Takes too long to
become extension of body. Best learned as child/teenager. Time worthless then.
Maybe if you can learn it fast. Took me years of teenage to get unthinking
proficiency.

~~~
zarkov99
I disagree, I learned Vim in my 40's after decades on emacs. For a month it
was awful, but I have since recouped the time lost many times over. Other
developers on my team went through the same.

~~~
renewiltord
Very interesting. Good to hear.

------
askvictor
I partially learnt Vim some 20 years ago, but at some point stopped taking in
new commands (possibly for lack of repetitive use), and am stuck in a sort of
'good enough' zone, but still awkward for certain things; the ctrl-c/v thing
always throws me as I use windows primarily, gvim makes it easy to cheat using
the GUI, so I do. Macros are amazing, but I feel there are probably easier
ways of achieving most of the things I use them for (they, and regex
search/replace are most if what I use Vim for outside of writing code).

~~~
svnpenn
You get over it if you use it enough. For me its now the opposite. For a while
I keep accidentally trying to do Ctrl+C/Ctrl+V, but now I find myself trying
to go into Visual mode or Normal mode in programs that dont support that.

I started off with a bunch of mappings, then you can remove them as you get
comfortable. Now I only really have mapped "nmap H :nohlsearch<CR>" and "xmap
S :sort<CR>".

Whats really tricky is using Vim without the Arrow keys. Normally I am on a
desktop so it doesnt matter, but when I use a laptop it makes more sense to
use HJKL. Again its just something that you need to force yourself to do or
you wont get comfortable with it.

~~~
Normille
HJKL makes no sense for me at all. It reminds me of the annoyingly designed
computer games I used to play on my Oric as a kid, where the various direction
keys to control my 'character' often bore no relation to their relative
positions on the keyboard.

H and L are just about OK for left and right, but up and down being another
left/right positioned key combo, nestled in between, just doesn't work with
the way my brain's wired, at all.

Conversely, on my MacBook Air keyboard, the arrow keys are nicely grouped
together in an inverted T formation at bottom right corner of the keyboard,
with some space around them. Piss-easy to find and piss-easy to feel which one
points in which direction, without even looking at the keyboard.

Strange that almost every tutorial on Vim I've ever read begins with _" Don't
be tempted to use the arrow keys instead of HJKL.."_ which, in my opinion is
just about the "worst advice evarrr!", especially given the rest of the
learning curve which awaits you.

*YMMV --depending on your own particular keyboard layout.

~~~
svnpenn
I agree that HJKL is really uncomfortable for a new user. I still reverse J
and K sometime, as my brain thinks "the first key should be Up".

I guess the thinking is, if you open up some existing document, youre already
at the top, so the more important key is going down, which the "J" sits right
under your index finger.

I totally agree that its awkward, but I also feel that if you can get good
with it, youll be way faster than using the arrow keys. Think about it like
this: with the arrow keys, you must move your hand. With HJKL, you dont have
to move your hand from the home row.

~~~
Normille
I think the "not moving your hands from the home row" is another relic of a
bygone era. It dates back to when people were taught to touch type and that
was the starting position. It also dates from a time when keys had to be
pressed with some force. Resting your fingers on the keys with a modern laptop
keyboard, you're in danger of accidentally typing characters you didn't want
to.

I can type pretty fast, though I've never actually measured my WPM speed. But
I'm not a touch typist --I still have to look at the keys-- and I don't type
'properly' using all my fingers. I seem to get by with the first three on each
hand. So there's no real advantage for me in having my fingers resting on the
home row. In pauses for thought [my equivalent of resting on the home row] I
usually find I'm waiting with the heels of my hands on the empty space below
the keyboard, either side of the trackpad and my fingers just kind of very
lightly touching the keys, wherever they happen to fall.

From that position, it really is far more convenient for me to just curl in
the fingers of my right hand , which puts the inverted T of the cursor keys
right under my finger tips and which I can do without looking, than it is for
me to look down at the keys to find HJKL.

------
JackMorgan
This book looks really cool, and I appreciate what they're doing.

If I could humbly add, one of the hardest things about learning Vim isn't
reading a list of commands, but rather _practicing_ them. So I wrote a list of
Vim exercises (or études for the musicians), files requiring various edits,
and a daily practice schedule that can be used to drill each distinct skill.
Once you've mastered it, you can drop it from your schedule. I found it was
really the only way to actually commit some of the more esoteric skills to
muscle memory.

Here's a sample for how to practice muscle memory around named registers for
yank and put, a skill almost no one I know regularly uses because it's hard to
learn just by reading. After writing this and working through the ten minute
exercise daily for a couple weeks, it became second nature, and now I can't
live without it.

[https://github.com/steveshogren/10-minute-vim-
exercises/blob...](https://github.com/steveshogren/10-minute-vim-
exercises/blob/master/book_sample_history_registers.md)

------
Scarbutt
FZF(and its vim plugins) really leveled up the game for Vim.

~~~
colordrops
As well as neovim and LSP.

~~~
unmole
I've had neovim installed for a while but really haven't found anything that
would make me want to switch. Sure, I get the meta Neovim competition driving
improvements in vim but I'd like to know what I'm missing out on.

~~~
colordrops
It's been quite a bit faster than Vim, but perhaps Vim has caught up. I
haven't checked it out in a while. Neovim supported asynchronous updates well
before Vim, so also much more responsive until recently.

In any case my config is compatible with both and I can use them
interchangeably.

------
racl101
I know it sounds like a joke but any book on Vim should have have as its first
lesson: how to quit Vim. That's the #1 question I get from vim beginners.

~~~
adembudak
Lol, I made kind of learning material on Vim, and that's exactly what I do.

[https://p1v0t.github.io/Doctor/](https://p1v0t.github.io/Doctor/)

------
AdmiralAsshat
Buffers are one of the few parts of vim I never really got the hang of.
Neither that nor windows are things I can ever remember how to do without
fudging it the first time, having to go look up the manual _again_ for how to
do it properly, realize I'm wasting more time than I'm saving by trying to
learn it, and give up.

~~~
gen220
Which part of it do you struggle remembering? maybe the wisdom of hn's vim
users can help :)

Personally, I can't imagine being productive without windows and buffers.
although when I have 3+ buffers open, I usually "cheat" by fzf-finding the
file (rather than `:bn`-ing my way there, or `:b` `:b x`).

------
haolez
In my opinion, the greatest benefit of using Vim, Emacs or even Acme is how
easy it is to create custom tools for your problem at hand, even for one-shot
tasks. VSCode is very capable, but it can't compete in this regard (and maybe
that's what they want and maybe it's a good call as well).

~~~
ectoplasmaboiii
I've tried using the vim plugin for VSCode many times, and every time I come
back to it, it just feels... off? The actual vim keybindings work fine _when
you 're editing the document_, but I find that when you want to use some of
the other features of the editor, it becomes a bit more tricky/hacky.

If MS made an official set of vim keybindings that had better editor support,
or even if there was some sort of kill switch that let me turn off vim key
bindings quickly, I would be 100% sold on VSCode, but until then, I'll stick
to the terminal.

~~~
scruple
Have you tried the neovim _integration_ VS Code extension? [0] It's not
perfect (I'm still in a terminal 95% of the time, but my current VSCode set up
is surprisingly not painful and I find myself using it more frequently) but it
gets a lot further along than VsVim did for me (which is probably not a far
comparison because I have not actually used VsVim in many years) or VSCodeVim
when I tried it recently. YMMV, of course.

A word of advice, though, if you plan to check this out... I'd recommend
maintaining a separate neovim install specifically for the VS Code integration
and make sure that it has fairly basic vimrc with limited plugins. You have to
take care with this because (neo)vim plugins don't always play nicely with VS
Code and vice versa.

[0]: [https://github.com/asvetliakov/vscode-
neovim](https://github.com/asvetliakov/vscode-neovim)

------
cecida
I'm not trying to be contrarian here, but why would someone continue to use
Vim and Emacs when all of its lovely features have been integrated into
products like VCode?

It just reminds me of serious men with beards working on mainframes and AIX
power systems when I started my career.

~~~
lalaithion
Sure, I use VSCode and Intellij and all the beautiful modern IDEs. But I use
them with Vim keybindings turned on. Because extremely common things that you
do while programming are extremely quick for me to do with vim commands.

ci" == delete everything within these quotes, and put me in insert mode.
vi{:%s/old_var_name/new_var_name/g == rename a variable within a block
qaI"<ESC>A",<ESC>jq == make a new macro to quote a line of text and add a
comma at the end. Great for taking a bunch of strings I've copied from a text
file and putting them into a list in code. But the point here is not this
specific macro; I can do all sorts of minor text processing macros for the
dumb thing I have to do, and not manually process 100 lines of text to turn it
into a piece of json.

~~~
jen729w
Just started doing this for RSI reasons. Not having to constantly reach down
to those arrow keys is _fabulous_.

~~~
test1235
That's funny - I'd have thought using arrow keys would help prevent RSI 'cos
you're having to move your whole arm out of a static position. (Or maybe you
don't? Do you just twist your wrist in an awkward position?)

------
DerSaidin
If you're new to vim, also consider
[https://kakoune.org/](https://kakoune.org/)

------
glouwbug
I recommend swapping your left CTRL and ALT keys when using vim, as well as
CAPS and ESC to avoid RSI.

Also, the dot operator is king.

~~~
49531
I was using vim for years before discovering the dot operator. Truly a game
changer.

~~~
wyclif
Yeah, I use combinations like 'dw...' and 'dd...' a lot. So simple, but a lot
of people don't know that's built in.

------
sergioro
Learn Vim (the builtin way):

    
    
      :help

~~~
gbrown_
Yup, ":help user-manual" sadly often overlooked.

------
pwinnski
As it is now, it seems to be a partial book.

------
bambam24
Over engineering

