That article was strange... the "reason" why esc was used was because of its location? That's a specious argument if I've ever heard one. Esc was used, because that's the meaning if the esc key... to escape, or get out of something.
Esc is ASCII 27, or 00011011. [ is ASCII 91, or 01011011
Notice that they're almost exactly the same, except for bit 7. On very old teletype terminals the control key was actually a mask that masked the higher bits, so ctrl-[ actually became escape.
That's definitely why I like it. Pays off immensely every time I buy a new laptop or keyboard or switch to one i haven't used in a while. It's tedious every time I have to look at my fingers, which almost never happens with hjkl on any keyboard.
Actually, once you try hjkl you'll never ever even think about using the arrow keys again.
i use iBus often, and i gravely disagree with you. when you use an input method with word completion ( e.g. ibus-typing-booster which is beyond awesome for saving you keystrokes and helps with typing in foreign langauge), it interferes with some vim letter key commands, and arrows become preferable.
of course, usage of such tool is great when you type in lots of text, not edit one.
I dunno, I'm on Dvorak, and if I want to move just up and down, J and K work great since they're right next to each other, but if I want to move left and right as well, it's a lot more convenient to just use the arrow keys.
Whaaa-? Fellow dvoraker. Left is literally under your index finger at all times. Right is a tad inconvenient, but you shouldn't be using h/l all that often. bB/eE/wW are so much better ways to get around and they are easier to hit in Dvorak.
That's because it's more common to move up/down by line than it is to move left/right by character. If you're moving horizontally, you're more likely to be using w, e, b, t, or f. So, the more common movement is put under the index and middle finger.
If you get your hands on a programmable keyboard like the Pok3r or something you can remap Fn+HJKL to the arrow keys making it so that you're using HJKL everywhere :)
If by "highlighted" you mean visual mode then I believe when you hit the : it will drop the character sequence that I forget right now but translates to "from beginning of selection to end" at the beginning of the command and your s applies to that.
If by "highlighted" you just mean the line the cursor is on in normal mode, then that is behavior i didn't know about. Cool.
Also I don't think %s will replace every instance in the file unless you add g to the end of the expression.
By highlight I meant you keep the cursor on the line you want to substitute in and then you execute that command. It works the way I described I just tested it too.
And you are very right. If /g is not added at the end, it will only replace the first instance of the phrase in every line. Thanks for pointing it out as I didn't know that. :)
Once you've got that down, try unbinding HJKL in normal-mode to force yourself to learn some of the more advanced movement commands. I still catch myself spamming J and K to get to the correct line sometimes.
<C-n>: Go forward half a screen. ([n]ext)
<C-p>: Go backward half a screen. ([p]revious)
<C-f>: Go [f]orward a full screen.
<C-b>: Go [b]ack a full screen.
H: Go to the top of the screen.
M: Go to the exact middle of the screen.
L: Go to the bottom of the screen.
There's / and ? for searching for specific strings. Plus n and N to move through the matches. And f, F, t, T, ; and , for moving within a line. If you enter a number and then gg or G, it'll take you to that line number.
Also, the { and } commands do something involving "paragraphs"? I've never been able to figure them out. Plus there's ( and ) which are similarly mysterious to me. In normal text they move one sentence at a time, but in code they seem to just do whatever they feel like.
I don't use <C-n>, <C-p>, <C-f> or <C-b> because it's too easy to overshoot the line I'm going for, and then i'd have to spam j or k to fine-tune get there anyway. I actually use those { & } commands as my main source of movement, because they navigate by blocks (paragraphs that are separated by empty lines above and below) and code is usually structured around them.
^
This is
one paragraph
^
This
is
another paragraph
^
'^' denotes where your cursor would jump each time you press '{' or '}'
No problem! I really appreciate that. :) And remember that you can look up what any of those commands do with :help <command>, which is why I wasn't more specific on some of them.
I use H and L with zz to scroll through a file. zz puts the current line in the middle of the screen and is very convenient. To fine tune and get to the line I need, I use relative line numbers and j or k to jump to a line in 2 key strokes.
Hey that is a very good point. I didn't think of that. How do Vim veterans do it? Do they switch between insert and normal modes or do they use arrow keys?
I don't believe there is one right way to use it so sorry if I make it sound like I do. Just want some pointers.
Generally with vim you want to spend as little time as possible in insert mode, so the pros usually blink into normal for a bit to adjust their cursor.
insert mode really is just for inserting text. If I want to insert some text, move, and then insert more text, I'll generally go back to normal mode in between.
About the only exception is if I want to insert some text, move 1-2 characters, and then insert some more. In that case, I'll use the arrow keys.
Though, if I see it coming, I'll often just delete intervening text before entering insert mode and retype it. Lets say I have:
the dog lies
and I want
the bad dog lies badly
my approach to make this change will usually be:
wCbad dog lies badly<esc>
It may be more key strokes than some other solutions, but I can type words quickly, and it involves minimal cognitive overhead.
I much prefer this to, say:
wibad <esc>A badly<esc>
or:
wibad <end> badly<esc>
or even:
wibad <ctrl+o>$ badly<esc>
That last one is is nice and short, and gets the job done, but I still prefer to just retype some of the text.
EDIT: actually on reflection, for this particular example, I'd probably just retype the whole line. Reducing key presses is good, but for a short line like this, I'd rather just start from a clean slate. However, the same principle applies to longer lines. Better to retype a portion of a line than futz with interjecting text in several places.
I'm just going to go on record: vim user for 8-10 years; only some margin of zombie-fanatics actually avoid the arrow keys at all costs. Most of the time, there are plenty of occasions where you benefit from using the arrow keys for some vertical operation, or other small matter.
OK... we can play that game. I've been a vi, then vim user for 27 years and NEVER use the arrow keys. As /u/Gangsir said, insert mode is for INSERTING text. You only stay in insert mode while modifying text at the current cursor position, then exit the mode, use proper navigation commands to get where you want to go, then enter insert mode again. This is how vi (and later vim) were designed, this is how the most experienced users I've met all use it.
If you never use the arrow keys then how do you navigate while in command/completion mode? Also, the arrow keys are great as secondary direction buttons, I use them in normal mode to resize windows. Every unassigned shortcut is a wasted shortcut.
You're right, I should have been more clear, but was on mobile and didn't want to type :-) . I meant the second part about using <CTRL><F> or q: or q/ to get into the command history, which then gives you full vi style editing & navigation to edit your command/search or select/edit previous commands/searches.
I don't think that's true. I've been using vim for about 10 years as well and can say with quite a bit of confidence that I don't use the arrow keys at all. Granted, I've never totally removed them from my keyboard so I guess I can't say for sure but if I want to move around I jump back to normal mode (jk mapped to Esc) and do my movement there. And I certainly don't consider myself a zombie-fanatic for doing so.
Appreciate your insight and definitely agree with you. I just did it get in the habit of using HJKL. My hands gravitate towards arrow keys all the time right now.
I'll raise my hand too. Been using vim for 25 years, and vi before that. Never bothered with hjkl. Only ever used arrows (except maybe way back in the dark ages, but I don't remember back that far).
For me, Vim's navigation goodness is the various intelligent jumping around keys, not the location of the arrow keys.
Whether or not you should be using insert mode keys or command mode keys for movement is really the wrong discussion. How long you should be in insert mode has to do with controlling the length of an action. That is, "how much sense does it make to repeat this entire thing with ., or undo the entire thing with u?".
I will often switch back into command mode several times while writing a chunk of text so that I get more granular undo history.
If you disable hjkl then lateral movement will be your least concern. However, without j and k you'll be forced to use an extension like easymotion if you want to navigate "effectively". What else would be there?
What if you make a mistake while typing like swap 2 characters? Is there a more efficient way to correct it than hxp? Or what if you're recording a macro and you know the exact positions in certain lines but not the characters? Or how would you navigate in dense lines where there are only a few or no whitespace chars? Would you spam f and t until you get there? There are many scenarios where you need character-wise movement. And line-wise movement doesn't seem to be sane without j & k.
if u do f or t one time you can spam ; until you get to the letter. Still more efficient than spamming h or l... also why not just use search in that case?
Yeah, f and t are good - once. But you don't need to spam h or l - you can do stuff like 5l or $2h. /...<Enter> is not always comfortable, especially if it has more than one match at a line.
Nothing wrong with the arrow keys. "hjkl extremism" is about as useful as any extremism: not at all.
I use both the arrow keys and hjkl; I find it's much easier to hit the arrow keys with my pinky when I'm in insert mode and need to move a wee bit with the cursor. In other situations I find hjkl more convenient.
Of course, some folk may disagree and find other stuff easier. That's okay, but the idea that you've only "learned Vim properly" when you don't use the arrow keys is just wrong.
If you really want to "learn Vim properly" then learning about motions and text objects will be a much better way to spend your time.
After switching to Colemak, the hjkl became a lot less important. I used them more than arrows.
Fortunately my keyboard (Filco Minila) has function layer arrows on the esdf keys. Which is shifted one right from wasd, but is surprisingly convenient. The homing bump on f makes sure I'm in the right place.
After you get used to HJKL, download vim-hard-mode, which takes it to the next level. Completely disables single keystroke navigation (even HJKL and backspace).
Honestly I am just trying at this point and seeing what I like more. I have not been coding lately so I haven't been able to use this in Vim. But a ton of apps use the same keybindings (for me: CMUS, Ranger, Firefox with VimFX) so I have been finding it pretty convenient. I am not a touch typist either. I am like you but probably way slower.
To answer your question, I don't really know. You could unbind the arrow keys in Vim for a while and see how you like it. Though there is a curve of getting used to it so you wouldn't be able to tell immediately but it's about whether you feel like stepping out of your comfort zone or not.
119
u/alexpin Jun 24 '17
Slightly easier way:
Actually, once you try
hjklyou'll never ever even think about using the arrow keys again.7
u/-romainl- The Patient Vimmer Jun 24 '17
14
u/[deleted] Jun 24 '17
Once you've got that down, try unbinding HJKL in normal-mode to force yourself to learn some of the more advanced movement commands. I still catch myself spamming J and K to get to the correct line sometimes.
24
u/I_Print_CSVs Jun 24 '17
Apparently moving the cursor in insert mode is for casuals
6
u/SnowdensOfYesteryear Jun 25 '17
Meh hjkl is overrated.
8
u/[deleted] Jun 24 '17
don't post photos of keyboards on this sub bro
4
u/ragnar_graybeard87 Jun 24 '17
The funny thing being that the "elitist" vim users will even disable HJKL so that they are forced to use movements like <2> <w> or < f > < e >
3
u/[deleted] Jun 25 '17
Nothing wrong with the arrow keys. "hjkl extremism" is about as useful as any extremism: not at all.
I use both the arrow keys and hjkl; I find it's much easier to hit the arrow keys with my pinky when I'm in insert mode and need to move a wee bit with the cursor. In other situations I find hjkl more convenient.
Of course, some folk may disagree and find other stuff easier. That's okay, but the idea that you've only "learned Vim properly" when you don't use the arrow keys is just wrong.
If you really want to "learn Vim properly" then learning about motions and text objects will be a much better way to spend your time.
2
u/j_derpz Jun 24 '17
1
u/InkyandtheCerebellum Jun 24 '17
After switching to Colemak, the hjkl became a lot less important. I used them more than arrows.
Fortunately my keyboard (Filco Minila) has function layer arrows on the esdf keys. Which is shifted one right from wasd, but is surprisingly convenient. The homing bump on f makes sure I'm in the right place.
Plus I have arrows in all modes now.
1
u/VanLaser ggg?G... Jun 25 '17
The Horror, the Horror! :P
1
u/AIDS_Pizza Jun 24 '17
After you get used to HJKL, download vim-hard-mode, which takes it to the next level. Completely disables single keystroke navigation (even HJKL and backspace).
0
u/[deleted] Jun 25 '17
Yep, unmapping directional keys in all modes helps.
0
u/[deleted] Jun 24 '17
[deleted] — view deleted comment
0
u/[deleted] Jun 30 '17
[deleted] — view deleted comment
0
u/[deleted] Jun 24 '17
[deleted] — view deleted comment