He keeps italicizing vim and every time I read vim I get a little spooked, like he’s saying it all serious-like
Part of me wants to snarkily “improve” all of his commands by showing how to do them more optimally, but part of me is also like “don’t try to show off how much better you are, just be happy he’s finding stuff that’s helping him.” The latter part is wiser.
Part of me wants to snarkily “improve” all of his commands by showing how to do them more optimally
Why does it have it to be snarky? When I am learning any language, I love being shown more optimal ways to do things by experts. It’s a power boost to the learning process.
For half a second or so, while the page loaded on my mobile browser, only the italicised text rendered and it looked like a surreal art piece about vim.
Okay, that’s a few less keystrokes, but a harder mental load. I’d rather press F3 to go to the next result (or even, re-hit ctrl+f and enter) than remember if I’m in the “search” mode and hit some random button that has a different meaning in a different context.
When programming, you already have to juggle so many different things in your mind - why complicate it further? I feel like all those vim/emacs articles are just written to justify the time spent learning all those keystrokes and quirks, and all the time setting up the plugins.
I get that concern, but the truth is that after a couple weeks of using vim all the commands and things you use daily become second nature. I’ve had times where I couldn’t tell someone how to do something in vim without having my fingers on the keys so I see what my movements were. It’s pretty amazing how many shortcuts you can keep in your head.
I’m able to mostly do that by playing the air-qwerty- keyboard. Definitely keeping most of my vim knowledge in my muscles, leaving my brain free for how I want the text to change.
You’re actually looking at it the wrong way around. F3 is the random key here. Nobody would ever figure out that key without help. On the other hand, in VI most keys are part of a logical pattern, even though some of those are historical. For example: n is the key you’d press to get to the next search result.
So while most shortcuts in modern day GUI have to be memorized without much context to help*, Vim commands are a language built out of related patterns.
*) That’s of course not the full story. All those shortcuts have a history as well and some are an abbreviation for the action as in ctrl+f(ind) or ctrl+c(opy). But there’s no “copy a word and paste it to the next line” or anything similar one could express with those.
People figure out the F3 key by seeing it in the IDE’s menus - which vim doesn’t have. With vim, you have to put in the effort and actively learn the shortcuts. But even then, I said you can just hit Ctrl+F and enter again to get the same behavior, which is obvious because most software has the same shortcuts, and work the same way.
But there’s no “copy a word and paste it to the next line” or anything similar one could express with those.
Ctrl+Shift+Right to select the word, then Ctrl+C, Down arrow, Ctrl+V, am I missing something?
Yes, if you use GVim you get those little helpers in menus as well. That’s a different interface. But the topic should be about concepts. VIM commands are a concept, a language, rather than a list of unrelated commands.
Of course you can do everything that you can do in VIM in any other editor as well. I’m referring to concepts and I might not be very good in conveying that. Sorry.
In the end you can express pretty much anything in any editor with enough keystrokes: the arrow keys exist, after all.
Modal editing tends to be a lot more efficient than non-modal though, and the keystrokes don’t require you to move your hands much e.g. to the arrow keys (way off the home row) or to use modifiers like Ctrl that require stretching your hands. Modal editors allow you to use the keys that are the easiest to reach: the letter keys, since the modal editor knows whether you’re intending to write vs intending to issue commands. These days I mostly use VSCode, rather than Vim, but I always have Vim emulation turned on because it’s much faster than non-modal editing once you’re familiar with it. Vim is particularly nice because it has a mini language for expressing edits; for example, w means “word,” and can be combined with deletion to delete a word (dw), selection to select a word (vw), “yank” to copy a word (yw), etc — or it can be used alone without a prefacing action, in which case it simply jumps to the next word after the cursor position. And there are many other “motion” nouns like w, and those can also be combined with the action verbs in the same manner — to copy letters, paragraphs, etc, or even more complex ideas such as letter search terms. Command sequences are first-class and your last command can be replayed with a single keystroke, and there’s even a built-in macro definition verb q, which stores up indexable lists of command sequences you issue and can replay the entire lists for executing complex but tedious refactors.
Sure — the bottleneck in programming is typically not between your hands and the keyboard; it’s typically thought. But once you know what you want to express, it’s a very pleasant experience to be able to do it with such efficiency of motion. And since we do ultimately spend quite a while typing, it’s not irrational to spend some time learning a new system to have that time feel nicer.
I don’t see it as much for programming, but for writing prose a modal editor is great for forcing me to separate writing from editing. When I write an article / book chapter in vim, I try to write the first draft and then go back end edit. At worst, I try to write entire paragraphs or sections and then edit. I find this produces much better output than if I use an editor that makes it easy to edit while I’m writing.
This is something that the article comes close to saying, but doesn’t actually say: Vim doesn’t just provide a bunch of shortcuts and keybindings for arbitrary operations, instead it provides a fairly well thought out programming language for dealing with text, that happens to also be bound to convenient keys. Crucially, operations in this language can be composed such as in the examples that the article gives, so you can build up your own vocabulary of operations even if the developers didn’t account for them. Does this take longer to learn than looking up the? Yes, probably. But I suspect that for most vim fans, there comes a “aha moment” where the power of this approach becomes apparent, and once you get used to it, you can’t live with it.
The mental load goes away after a while and it just becomes muscle memory. Each saving by itself is small, but they all add up over time. One I used recently was %g/^State \d/norm! f:lD: “On every line that starts with State followed by a number, delete everything after the first colon. Would have taken several minutes without that, with it it’s just a couple of seconds. When I’m constantly getting savings like that, it’s worth it.
I’ve used vim regularly for 15 years, and somehow I always learn something from introductory articles. A few years ago it was variations of yi". And now I see I’ve been needlessly repeating f<x> when I could have been using ; and , all this time. I like vim, but sometimes its lack of intuition still makes me feel dumb. I guess I should spend more time reading the manual.
I love vim, but it has really bad discoverability. Finding out what normal commands do isn’t too bad, but finding out the definitions of commands in other modes is surprisingly tricky.
My approach was to play some vimgolf earlier while getting used to the editor. You get to see what the people just a bit better than you did, and that often gives you clues as to what’s available. Repeat, and then go back to your regular life and see what you retain.
For me, the killer feature of vim that made me stick with it (on n-th try) was the “Quickfix list”, and in particular :cex system('some-bash-pipeline'), which lets me easily jump between lines found by any complex Linux pipeline I want. In particular, this typically starts with git grep and goes e.g. like this: :cex system('git grep -n some-regexp \| grep -v something-else') | copen (with the | copen being a shortcut to immediately show the quickfix list and let me move through it and “jump” by hitting Enter). I also have git grep -n as my set grepprg=, and recently learnt that git grep allows selecting/excluding file names, i.e.: git grep -n some-pattern -- ':*.go' to only grep Go files, or ... -- ':!*_test.go' to exclude Go test files.
Fast forward to a couple of months ago when I decided to learn how to touch type, which is a story for another day, and realized that touch typing aligned very well with vim
I can really relate to this. I think touch typing is a joy enhancer for VI. I don’t know if I actually would use VI without touch typing.
I find it somewhat surprising that someone can sit in front of a computer all day writing code and not know how to touch-type. Kudos to them for making a conscious decision to learn it.
My father has been a programmer for 40 years and he still hunt and pecks with two fingers. I’ve been touch-typing for 20 years. The difference between us is that I also played computer games since I was little, and the impetus to learn to type quickly came from needing to both type out information and heal my party at the same time.
I like to think I can type fast (85-90 wpm) and type a bit wonky, not by hunting and pecking but definitely not touch typing. What would you say is the best way to learn how to actually touch type properly?
If you’re just using muscle memory and not looking at the keyboard, I think it’s still touch-typing. It’s harder to unlearn years of muscle memory, but what they had us do when I was in school was put a blind over the keyboard and do typing tests. There’s a bunch of simple games out there to help you practice typing, those help.
Thanks, yeah I guess I hadn’t thought of it that way. I occasionally look at the keyboard but I’d wager 95% of the time I don’t, so that’s good enough in my book. I basically just want to learn real touch typing for use with Vim, but I should probably actually start using Vim regularly first.
I don’t do “real” touch-typing either, technically. I rarely use the right ctrl/shift/alt keys and still have to glance at my keyboard for the top number row and some symbols on occasion.
When I was 17, I broke my right wrist and so had to type everything for a bit. I learned to type quite quickly using only my left hand. I am now completely uncapable of using any split keyboards, because I use my left hand for anything to the left of the j key, though some thing in the middle I will type with either hand, depending on which hand typed the previous character. It makes people who learned to touch type properly very uncomfortable if they watch.
On the other hand I have never understood why movement keys are HJKL. They’re one key off from the rest position of the right hand, which is JKL: and feels much more natural to me, so… I doubt that these keys were choosen by an experienced touch typist.
Newsflash! The thousands (maybe even millions?) of people who’ve been using vim for decades are actually not stupid, lying or even just wasting their own time! Thank goodness that’s been cleared up!
He keeps italicizing vim and every time I read vim I get a little spooked, like he’s saying it all serious-like
Part of me wants to snarkily “improve” all of his commands by showing how to do them more optimally, but part of me is also like “don’t try to show off how much better you are, just be happy he’s finding stuff that’s helping him.” The latter part is wiser.
Why does it have it to be snarky? When I am learning any language, I love being shown more optimal ways to do things by experts. It’s a power boost to the learning process.
For half a second or so, while the page loaded on my mobile browser, only the italicised text rendered and it looked like a surreal art piece about vim.
I use Viiiiim
Okay, that’s a few less keystrokes, but a harder mental load. I’d rather press F3 to go to the next result (or even, re-hit ctrl+f and enter) than remember if I’m in the “search” mode and hit some random button that has a different meaning in a different context.
When programming, you already have to juggle so many different things in your mind - why complicate it further? I feel like all those vim/emacs articles are just written to justify the time spent learning all those keystrokes and quirks, and all the time setting up the plugins.
I get that concern, but the truth is that after a couple weeks of using vim all the commands and things you use daily become second nature. I’ve had times where I couldn’t tell someone how to do something in vim without having my fingers on the keys so I see what my movements were. It’s pretty amazing how many shortcuts you can keep in your head.
I’m able to mostly do that by playing the air-qwerty- keyboard. Definitely keeping most of my vim knowledge in my muscles, leaving my brain free for how I want the text to change.
You’re actually looking at it the wrong way around. F3 is the random key here. Nobody would ever figure out that key without help. On the other hand, in VI most keys are part of a logical pattern, even though some of those are historical. For example: n is the key you’d press to get to the next search result.
So while most shortcuts in modern day GUI have to be memorized without much context to help*, Vim commands are a language built out of related patterns.
*) That’s of course not the full story. All those shortcuts have a history as well and some are an abbreviation for the action as in ctrl+f(ind) or ctrl+c(opy). But there’s no “copy a word and paste it to the next line” or anything similar one could express with those.
People figure out the F3 key by seeing it in the IDE’s menus - which vim doesn’t have. With vim, you have to put in the effort and actively learn the shortcuts. But even then, I said you can just hit Ctrl+F and enter again to get the same behavior, which is obvious because most software has the same shortcuts, and work the same way.
Ctrl+Shift+Right to select the word, then Ctrl+C, Down arrow, Ctrl+V, am I missing something?
Yes, if you use GVim you get those little helpers in menus as well. That’s a different interface. But the topic should be about concepts. VIM commands are a concept, a language, rather than a list of unrelated commands.
Of course you can do everything that you can do in VIM in any other editor as well. I’m referring to concepts and I might not be very good in conveying that. Sorry.
In the end you can express pretty much anything in any editor with enough keystrokes: the arrow keys exist, after all.
Modal editing tends to be a lot more efficient than non-modal though, and the keystrokes don’t require you to move your hands much e.g. to the arrow keys (way off the home row) or to use modifiers like Ctrl that require stretching your hands. Modal editors allow you to use the keys that are the easiest to reach: the letter keys, since the modal editor knows whether you’re intending to write vs intending to issue commands. These days I mostly use VSCode, rather than Vim, but I always have Vim emulation turned on because it’s much faster than non-modal editing once you’re familiar with it. Vim is particularly nice because it has a mini language for expressing edits; for example,
w
means “word,” and can be combined with deletion to delete a word (dw
), selection to select a word (vw
), “yank” to copy a word (yw
), etc — or it can be used alone without a prefacing action, in which case it simply jumps to the next word after the cursor position. And there are many other “motion” nouns likew
, and those can also be combined with the action verbs in the same manner — to copy letters, paragraphs, etc, or even more complex ideas such as letter search terms. Command sequences are first-class and your last command can be replayed with a single keystroke, and there’s even a built-in macro definition verbq
, which stores up indexable lists of command sequences you issue and can replay the entire lists for executing complex but tedious refactors.Sure — the bottleneck in programming is typically not between your hands and the keyboard; it’s typically thought. But once you know what you want to express, it’s a very pleasant experience to be able to do it with such efficiency of motion. And since we do ultimately spend quite a while typing, it’s not irrational to spend some time learning a new system to have that time feel nicer.
Real gain is in reduced load on one’s muscles and tendons. Moving to vim bindings has helped me overcome pain in my wrists.
I don’t see it as much for programming, but for writing prose a modal editor is great for forcing me to separate writing from editing. When I write an article / book chapter in vim, I try to write the first draft and then go back end edit. At worst, I try to write entire paragraphs or sections and then edit. I find this produces much better output than if I use an editor that makes it easy to edit while I’m writing.
This is something that the article comes close to saying, but doesn’t actually say: Vim doesn’t just provide a bunch of shortcuts and keybindings for arbitrary operations, instead it provides a fairly well thought out programming language for dealing with text, that happens to also be bound to convenient keys. Crucially, operations in this language can be composed such as in the examples that the article gives, so you can build up your own vocabulary of operations even if the developers didn’t account for them. Does this take longer to learn than looking up the? Yes, probably. But I suspect that for most vim fans, there comes a “aha moment” where the power of this approach becomes apparent, and once you get used to it, you can’t live with it.
I’m not sure “n” for next is “some random key”? And “N” (shift-n[ext]) for previous.
And slash/question mark for search might be a bit arbitrary, but slash sorta-kinda “means” pattern/regex (as in /^something/).
Ed: ok, I’m not sure why op is exited about “find” - I generally “search”.. . Or move by word (w) beginning/end of line (| and $). See also: https://stackoverflow.com/questions/12495442/what-do-the-f-and-t-commands-do-in-vim#12495564
Move by word - hold ctrl, works in any textarea in any operating system.
Move to beginning/end of line - press “home” or “end” keys, works in any textarea in any operating system.
n is “some random key” on every other software with a text box on your computer. Vim is inferior in that aspect, not superior.
)
moves by sentence and}
moves by paragraph. I miss that all the time while writing prose outside of vim.Since they’re motions, you can combine them with delete/yank/replace/whatever. So
di)
deletes the whole sentence.Option up/down moves by paragraph.
I’m on Windows
The mental load goes away after a while and it just becomes muscle memory. Each saving by itself is small, but they all add up over time. One I used recently was
%g/^State \d/norm! f:lD
: “On every line that starts withState
followed by a number, delete everything after the first colon. Would have taken several minutes without that, with it it’s just a couple of seconds. When I’m constantly getting savings like that, it’s worth it.I’ve used vim regularly for 15 years, and somehow I always learn something from introductory articles. A few years ago it was variations of
yi"
. And now I see I’ve been needlessly repeatingf<x>
when I could have been using;
and,
all this time. I like vim, but sometimes its lack of intuition still makes me feel dumb. I guess I should spend more time reading the manual.I love vim, but it has really bad discoverability. Finding out what normal commands do isn’t too bad, but finding out the definitions of commands in other modes is surprisingly tricky.
My approach was to play some vimgolf earlier while getting used to the editor. You get to see what the people just a bit better than you did, and that often gives you clues as to what’s available. Repeat, and then go back to your regular life and see what you retain.
For me, the killer feature of vim that made me stick with it (on n-th try) was the “Quickfix list”, and in particular
:cex system('some-bash-pipeline')
, which lets me easily jump between lines found by any complex Linux pipeline I want. In particular, this typically starts with git grep and goes e.g. like this::cex system('git grep -n some-regexp \| grep -v something-else') | copen
(with the| copen
being a shortcut to immediately show the quickfix list and let me move through it and “jump” by hitting Enter). I also havegit grep -n
as myset grepprg=
, and recently learnt thatgit grep
allows selecting/excluding file names, i.e.:git grep -n some-pattern -- ':*.go'
to only grep Go files, or... -- ':!*_test.go'
to exclude Go test files.I can really relate to this. I think touch typing is a joy enhancer for VI. I don’t know if I actually would use VI without touch typing.
I find it somewhat surprising that someone can sit in front of a computer all day writing code and not know how to touch-type. Kudos to them for making a conscious decision to learn it.
My father has been a programmer for 40 years and he still hunt and pecks with two fingers. I’ve been touch-typing for 20 years. The difference between us is that I also played computer games since I was little, and the impetus to learn to type quickly came from needing to both type out information and heal my party at the same time.
I like to think I can type fast (85-90 wpm) and type a bit wonky, not by hunting and pecking but definitely not touch typing. What would you say is the best way to learn how to actually touch type properly?
If you’re just using muscle memory and not looking at the keyboard, I think it’s still touch-typing. It’s harder to unlearn years of muscle memory, but what they had us do when I was in school was put a blind over the keyboard and do typing tests. There’s a bunch of simple games out there to help you practice typing, those help.
Thanks, yeah I guess I hadn’t thought of it that way. I occasionally look at the keyboard but I’d wager 95% of the time I don’t, so that’s good enough in my book. I basically just want to learn real touch typing for use with Vim, but I should probably actually start using Vim regularly first.
I don’t do “real” touch-typing either, technically. I rarely use the right ctrl/shift/alt keys and still have to glance at my keyboard for the top number row and some symbols on occasion.
When I was 17, I broke my right wrist and so had to type everything for a bit. I learned to type quite quickly using only my left hand. I am now completely uncapable of using any split keyboards, because I use my left hand for anything to the left of the j key, though some thing in the middle I will type with either hand, depending on which hand typed the previous character. It makes people who learned to touch type properly very uncomfortable if they watch.
On the other hand I have never understood why movement keys are HJKL. They’re one key off from the rest position of the right hand, which is JKL: and feels much more natural to me, so… I doubt that these keys were choosen by an experienced touch typist.
Edit: Looks like HJKL is even older than vi: https://catonmat.net/why-vim-uses-hjkl-as-arrow-keys
He’s also missed out on netrw, which is a pretty good file interface built into vim https://shapeshed.com/vim-netrw/
Newsflash! The thousands (maybe even millions?) of people who’ve been using vim for decades are actually not stupid, lying or even just wasting their own time! Thank goodness that’s been cleared up!