Why are h,j,k,l recommended over using arrow keys for vim? - vim

I am a vim user (not a beginner not advanced). I use the arrow keys.
I have repeatedly read that it is highly recommended to use the h,j,k,l keys for increased productivity.
I have tried to use them but I can not see how they help in being more productive.
Because if I am to use the h,j,k,l keys to move up/down/right/left I need to press the ESC first to exit the insert mode.
But that defeats the purpose doesn't it? Since the original idea is that you don't need to move your fingers away.
If I am to press ESC I might as well be using the arrow keys and save a keystroke.
Perhaps I am doing something wrong here?

Old terminal keyboards like the ADM-3A terminal didn't have arrow keys.
The keyboard layout looked like this and it already had the arrows for hjkl. (By the way, also note the relation between ~ and Home key)
I think it is mainly for historical reasons that vim still uses it (and many are used to it). Perhaps also because many sysadmins are nostalgic about stuff from the 70/80's, and because they can brag about how they can type faster (like typing is the cause of slow coding...).

The distinguishing feature of vi / Vim is that it's mode-based. That means:
you only stay in insert mode for short bursts of typing
in the other modes (mostly normal mode), you have all key [combinations] available for powerful editing commands (which are highly regular in Vim, and can be combined to great effect)
So, it's crucial that you can switch modes easily. For many users, that means remapping the Esc key to a more convenient location (replacing Caps Lock or Ctrl). Then, using H J K L for navigation (note those are only the basics, and it's often better to use more specific motions like w or f{char}) is quicker, because your fingers can stay on the home row (assuming you're a touch typist, which you should invest in if you spend considerable time with a computer). The cursor keys are located so far off that switching there takes too much time (using the mouse is even worse), and isn't good for your wrists, neither.

The problem with the arrows is not that they are too far: the problem is that they only allow you to move character-by-character and line-by-line. And guess what? That is exactly what hjkl do. The only benefit of hjkl over the arrows is that it saves that slight movement of the arm to and from the arrows. Whether you think that benefit is worth the trouble is your call. In my opinion, it isn't.
hjkl are only marginally better than the arrows while Vim's more advanced motions, bBeEwWfFtT,;/?^$ and so on, offer a huge advantage over the arrows and hjkl.
FWIW, I use the arrows for small movements, in normal and insert mode, and the advanced motions above for larger motions.
mouse-using sucker everyone laughs at: (move)↓↓↓↓↓↓↓↓↓↓→→→→→(move)
hjkl-obsessed hipster: jjjjjjjjjjlllll
efficient vimmer: /fo<CR>

h, j, k, and l are on the home row. If you move your hand to use the arrow keys, you have to readjust when you're done with the arrow keys. This is only a problem for touch typists (which everyone back in the day was).

If you like using the arrow keys, by all means, use them. There is one advantage I see over hjkl: arrow keys work in insert mode. Others prefer to move their fingers only minimally. That's a good argument if you are a touch typist and need to type lots of text. At least for me, my thinking is always slower than my editing, so typing speed and minimal finger movement are not so much an issue to me.
In the end, it's a pretty subjective matter. Use what works for you but try to look around and extend your horizon now and then.

h j k l are a stepping stone to more powerful features. Do you really think that left, right, up, down is as advanced as moving the cursor gets in the 21st Century (or 1976)?

Please note that arrow keys are not recorded while using "q" macros, and bring a lot of sheanigans when you are using some esoteric options because arrows interrupt them. The idea with vim is to end up using composable actions as often as possible and arrows are not.
Besides it doesn't make much of a difference anyway. I had the same strule as a kid switching arrows for WASD, once you get used to it it's just another way, closer to where your hand already is.
And it's not just vim, you would not believe how convenient it is to go the extra mile and learn the terminal shortcuts for movement, copy-paste, history, etc. My laptop's arrows broke last year and I couldn't find the time to solve the issue (Amazon reach the space, but not the island where I live). It was a blessing. Now I rarely use arrows anymore, because ctrl-p/ctrl-n/ctrl-b/ctrl-f/etc. it's just more ergonomic. I just lay my hands on top of the keyboard and don't move them anymore. Ironically now the fartest I move my hands from standard position is to press ESC, wich happens quite often in vim.
A few times I've heard "wait, your terminal/editor can do what!?" when doing fancy things with public. Probably their toolset can do it too, but they haven't go the extra mile of truly learning them. Trust me, it's worthwhile to do so. These tools have been designed this way for a reason.

Related

VIM hjkl navigation keys, aganist existing muscle memory of arrow keys

I recently migrated to Vim.
But I am having diffuculty making use of "hjkl" keys for navigating because of my existing muscle memory of arrow keys.
1. Is there a way to effectively use other keys like "ijkl" ( near
to Arrow key layout ) without causing much conflict to other
functionality in VIM
, For ex: http://vim.wikia.com/wiki/Use_ijkl_to_move_the_cursor_and_h_to_insert
and http://ergoemacs.org/misc/on_vi_keybinding.html
2. Is it worth the efforts to retrain the muscle memory with "hjkl" ? But the problem is, I have to use arrow keys again with
Web-Browser, Outlook, and word processors ( So,the shift is causing the conflict) .
Can you suggest ( More interested to know about #2) , How did you deal with this ?
I have been using Vim for five years (after many more years of computer usage) without ever doing any conscious or unconscious effort to use HJKL for navigation.
I don't touch-type so the "home row" means nothing to me.
Even if I did, jkl; would make a lot more sense anyway.
I hit the arrows with the side of my right hand so there's not much cost in "reaching for the arrows" for me.
hjkl are just as bad as the arrows because both only move character-by-character and line-by-line unless you use modifiers (numbers for hjkl and Ctrl/Shift/Alt/Cmd for the arrows). Vim has vastly better means of transportation than either hjkl or the arrows and that's what you should spend time learning:
wW jump to next word/WORD
bB jump to beginning of word/WORD
eE jump to end of word/WORD
fx jump to next x on the line
tx jump to character just before next x on the line
Fx jump to previous x on the line
Tx jump to character just before previous x on the line
/foo<CR> jump to next foo
?bar<CR> jump to previous bar
} jump to next blank line
and so on… :h navigation will blow your mind.
So my answer is: don't bother forcing yourself to use hjkl, it's not worth the hassle.
It's a good idea to train your hand for hjkl. You could try playing rogue for a while on a daily basis until it's comfortable. It comes pretty quick.
Arrows are awful for taking your hand so far out of position. Even <Enter> is too far. I usually get away with Ctrl-J instead (a comfortable Ctrl is really important too!).
Using custom overrides for hjkl will only "help" your vim, but not other vim-like tools. In vim, remapping i will cause other issues, like what to use instead of i/I, which are very common. And you might not want to take over ; for this since right-pinky is prime real estate which I (and I think many others) map to the very frequent : (at the OS level so as not to ever be confused).
Learning hjkl will also help when you're in other places: You probably want to start using vi-mode in bash (or hopefully zsh). Gmail/mutt will be more natural. REPLs with readline support also support vi-mode. Maybe you'll do less word processing if you can replace it with text editing in vim.
Sometimes it's useful to remap things, but it's rare and often to more obscure keys/sequences. It can cause problems when you work in multiple environments, and can make sharing/pairing difficult. It can break macros and other mappings, and make recipes and articles harder to interpret. Try learning the vim-native ways first, and then deviate with experience when really justified.

Time to relearn touch typing? (Is this a Emacs / VIM thing?)

As a kid, I learned to type on a German keyboard1?. And even though my mom tried to make me use a "learn how to type with ten fingers" program I never did. My hands have their very own muscle memory about how to type. I found out that I use the index fingers most to reach many characters, while my hands are moving over the keyboard.
Now, here's the kicker (no flame intended!): I use and used emacs a lot and I've never really had an issue with the way I type, or at least it never felt too awkward. From time to time I like to explore VIM (and other editors) to see what has changed and which features are the new and hot features.
I came to the conclusion that, while my fingers /rest close/ to the home row, my hands move a lot and the default keyboard command layout in vim seems to prefere the fingers resting on the home row with little movement of the hands.
I don't consider myself to be a slow touch typist, but could a formal touch type education increase speed and accuracy? Furthermore is this a Emacs / VIM thing?
UPDATE: I headed over to http://typeracer.com/ :)
1: These days I type on US keyboards while switching between different layouts as needed.
Yes, you're a keyboard worker, learn to use a keyboard properly. No, it's not an Emacs / Vim thing.
If you are using emacs, makeing Caps_Lock another Ctrl key will ease strain on your little finger, when your hands are "locked" in the home row position.
for ubuntu
System->Preferences->Keyboard->
-->Layouts->Layout-Options-Ctrl key position->Make CapsLock an additional Ctrl
or for windows
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
You don't need a formal education, but a lot of discipline, concentration, dedication and hard work will make you a touch typist in a few months.
Touch typing will greatly assist you in your life, if you plan to work with computers as your day job.
Force yourself to move your hands as little as possible and use all of your fingers all of your time.
Rest your left fingers on ASDF, your right fingers on HJKL and start typing. While typing, optimize your reach for every key pressed.
If you plan to be a computer professional, touch typing should be a rite of passage, although it isn't required. But just imagine what would it look like if a master pianist didn't know all keys on piano by heart?
Not really. Especially if you are going to alt-tab to google/read documentation a lot.
Touch typing as it is good only if you are not going to use mouse and F1-F12 which is never true in modern environment.
If you are going to use them, you'll eventaually switch to some form of mutant of touch-typing.
(also whoever thouGHT that typing H with riGHT hand is briGHT idea should be shot in THe face. Left hand do it more naturally in huge amount of cases)
I'd say don't worry about it. You're not a secretary or someone who is having to take down dictated speech. It's far more important for a programmer to spend more time thinking about what they're writing rather than how they write it. If speed of typing is your biggest concern over how productive you are I think you're probably productive enough.
Do you really care? If you do, use the editor that you are more comfortable with. If are you looking for alternative, use M-x viper or learn other emacs extensions that helps you type faster.

Inefficiency in Vim

I consider myself somewhat familiar with Vim,
hate the arrow keys (let alone the mouse),
regularly look up tips and plugins to get the most out of this tool,
use it daily to manage my cloud servers, etc.
However, I always find myself doing the same mistakes probably inherited from the GUI-world:
too often switching to visual mode to see what piece of code I'm about to manipulate,
undoing changes to retrieve lost statements because I forget to utilize registers (and pasting code on temporary lines just to grab it after other edits),
relying on Ctrl-C & Ctrl-V when working with operating system's clipboard,
keep pressing j button to browse through lengthy files to find certain functions.
Probably my Hungarian keyboard layout prevents me from being faster as most of the special characters (/, [, etc.) are only available as a key combination (with Shift or Alt Gr).
Given this specific situation, what pieces of advice could you give me? Have you faced similar bad habits when you were a Vim-novice? I'd like to see my productivity skyrocket (who wouldn't?). Thanks in advance.
I've found a simple, effective strategy. Choose one action, one task or one set of keys that you think is unnecessarily slow. Figure out a better way of doing this using the vim manual or googling or a plugin etc. Force yourself to use this every time. Rinse, and repeat. The path to efficiency is one-by-one elimination of the slow parts.
I'd also recommend just reading the vim manual from time to time - even if you don't remember everything, knowing something's out there is very helpful.
This probably applies well beyond vim, but
something that worked for me was finding a specific feature that I knew would
be more efficient and concentrate on using that for a week or two.
Just one feature at a time, and possibly using it excessively.
After a couple of weeks it becomes automatic and you can move on to the
next thing.
I learn programming tricks the same way. eg. I'll have a month of using lambda expressions for everything, then a month of mapping and filtering.
(not on production code though)
Probably my Hungarian keyboard layout prevents me from being faster as most of the special > characters (/, [, etc.) are only available as a key combination (with Shift or Alt Gr).
I'm sitting in front of german keyboards all day long and know this problem very well. Some keyboard layouts are simply not very suited for programming / using vim. I think its safe to assume that most programming languages and keyboard shortcuts were designed with the us-layout in mind.
My advice: reset your keyboard layout to us-english and practive touch-typing on that layout (typing without looking at the keys). It won't matter that the keyboard labels are wrong and you'll be much more comfortable using vim hotkeys.
The only problem that still remains for me is to produce language specific characters (german umlauts such as ä,ö,ü) wich i assume will also be a problem for hungarian. For that I use a combination of vim-digraphs, linux window manager digraph-key and windows layout-switching hotkeys.
just keep using it. The more you use it, the better you become at it. VIM isn't too bad. The main thing is you just have to remember that it isn't always in edit mode.

Colemak keyboards with Emacs or VIM [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I've been crossing things out on my TODO list. I've recently picked up Colemak. Next I wanted to learn Vim or Emacs. I was leaning towards Vim, however one of its benefits are sticking to the home row. With Colemak, the home row has been changed. I realize that I could remap the keys, but assigning the functionality to different letters is not extremely appealing to me (if there is any relation between letters and their function. I know movement is not correlated but I'm not sure on all the rest.)
I don't want to start an argumentative post about text editors, but rather receive comments from Colemak (or Dvorak) users about alternative keymappings and these two editors.
Thanks
I'm using a similar set up to Graham (up, down, left, right, is hkjl (Qwerty hnyu)) but instead of using noremap, remap using langmap in my .vimrc:
set langmap=hk,jh,kj
This has the added advantage of changing other commands that use these movement keys (e.g. g, z and C-w) without having to redefine all these commands manually, i.e. C-wh moves up a window, C-wk moves down a window, etc.
I have recently switched to Colemak and I also use Vim as my main editor.
I can tell you that there is no need to remap the movement keys - or any other Vim keys for that matter. Your brain will quickly learn the new positions of the movement keys. For the mnemonic keys there is definitely no need to remap - you want to keep the mnemonic meanings behind the keys.
If you remap the Vim movement keys you will be in the unfortunate position of not being able to operate a vanilla Vim with any real efficiency - for example if you need to SSH to a server. I argue that for most people that will be much more common than having to use someone's computer that does not have Colemak.
As well, there are Vim plugins you may get one day that will clash with your remappings, or you will read a Vim tip one day about a feature which you can't now use because you have remapped things.
It will be a real pain for you, so I wouldn't bother with any remappings.
Glad to see another Colemak user :)
For Emacs there really isn't a need to remap, since the initial "shortcuts" aren't designed to be close to each other. If anything, you're gonna be more comfortable using Emacs on Colemak than on Qwerty (at least I was).
In Vim it's a lot trickier since hjkl will be completely messed-up. Then again, I've always felt that hlkl was broken and should have instead been jkj; or ijkl, so a remap is probably a good thing. Here's a broader discussion about Colemak+Vim on the Colemak forum: http://forum.colemak.com/viewtopic.php?id=50
This in your .vimrc will change the cursor movement for Colemak without affecting other vim mappings, because it only affects the h/j/k letters.
up = h (labelled as "h" on the keyboard)
down = k (labelled as "n" on the keyboard)
left = j (labelled as "y" on the keyboard)
right = l (labelled as "u" on the keyboard)
Here is the mapping:
noremap h k
noremap j h
noremap k j
I've run with Dvorak for a number of years now (probably ~4). I have also used vim for all of the standard reasons you have to use vim like things (less, config edits that have their own editors (visudo, etc.), etc.). Emacs was actually the first Unix program that I learned (I'm a native to the Apple world) and I currently picked it back up after being castigated by Yegge's ramblings about how ridiculously awesome it is.
From a strictly keyboard layout stance, I would say that Emacs is probably the winner here because no remapping is required. Other than swapping the Caps-Lock key for a Control key (which should really be done period, the Caps-Lock key is like every keyboard's high-school hickey), I would say that every keybinding is more comfortable to use with Dvorak than with Qwerty. I especially find the constantly used C-x and M-x bindings to be very comfortable to type.
However, vim is really no big deal. 'j' and 'k' are still right next to each other. 'h' and 'l' are at least conveniently on one hand and are on and above the home row. Other than that, it's simply about remapping the keys in your mind for doing things in the editor that you want to hae happen. I personally don't see any reason to remap anything, and I'm high risk for RSI (hence the switch to Dvorak). For keyboard centric apps like vim and emacs, the fact that I can use them comfortably unaltered should be fairly impressive. :)
Good luck!
I'm using Ryan Heise's solution for Vim:
I came up with the "NEST" navigation bindings which preserve the physical
location of the up/down navigation
keys (left/right are different but
still on the home row):
N = down E = up S = left T = right
The commands for setting this up are
on my Colemak page at the bottom:
http://www.ryanheise.com/colemak/
Mostly, these bindings allow you to
use a regular vim cheat sheet to learn
the commands, except for navigation of
course.
Of the 4 keys assigned in N-E-S-T, the
"N" ("n"ext search result) and "E"
(move "e"nd of current word) were
frequent but gobbled up. I remapped
them back to their original QWERTY
positions and so they are the only two
commands that don't have their
original logical names.
Taken from https://forum.colemak.com/topic/50-colemak-vim/p2/#p2514
I'm a vim+qwerty user (I've tried learning dvorak, but it turns out typing speed is not my rate limiting factor and I don't have RSI issues). Only the hjkl cursor movement keys in vi(m) are position dependent, everything else is mnemonic. I see on the Colemak layout, that h/l are vaguely left/right, but j/k are down/up. Nevertheless, I doubt that would be a significant stumbling block. You could either use the arrow keys instead, or continue to use hjkl and deal with the funny positions.
I wouldn't be inclined to try to remap the vim functions depending on the keyboard layout. That seems like too much potential confusion for me.
Here is a previous post that should help you some. There is some discussion on there, some users don't remap. Some do.
I am going to remap over the weekend actually. I have for the past year used the default mappings, with Dvorak.

Is it worth swapping Ctrl and Caps Lock for windows users that don't use Emacs

I've been aware of Steve Yegge's advice to swap Ctrl and Caps Lock for a while now, although I don't use Emacs. I've just tried swapping them over as an experiment and I'm finding it difficult to adjust. There are several shortcuts that are second nature to me now and I hadn't realised quite how ingrained they are in how I use the keyboard.
In particular, I keep going to the old Ctrl key for Ctrl+Z (undo), and for cut, copy & paste operations (Ctrl+ X, C and V). Experimenting with going from the home position to Ctrl+Z I don't know which finger to put on Z, as it feels awkward with either my ring, middle or index finger. Is this something I'll get used to the same way I've got used to the original position and I should just give it time or is this arrangement not suited to windows keyboard shortcuts.
I'd be interested to hear from people who have successfully made the transition as well as those who have tried it and move back, but particularly from people who were doing it on windows.
Will it lead to any improvement in my typing speed or comfort when typing.
Do you have any tips for finger positions or typing training to speed up the transition.
I actually don't swap control and caps and just make caps ANOTHER control key. I can't think of a single time in my life when I have ever hit caps-lock on purpose, so I haven't missed it.
That way, you get used to using it, but if you slip up and use the old control, things still work. It's worked out very well for me.
There's a .reg file to do this here.
I've done it for quite a while now, and it's natural to me, even though I'm not an Emacs user either (I'm in the Vim camp of that particular war :) ). In fact, it's so natural that moving to other machines (coworkers, family members, etc.) causes me grief because Ctrl isn't where it 'ought' to be.
For emacs ctrl should be at caps lock - for vim the escape key should be on the caps lock. I really feel that the caps lock button should be renamed "free parking" and OSes should make a system tray utility to quickly change the free parking button from escape, to control, to anything you need to type over and over again.
I ended up taking the advice in Zach's answer, but I also made Caps Lock behave as an ESC key if it was held and released on it's own using the AutoHotKey script in this gist: CapsLockCtrlEscape.ahk
I also bound Ctrl+Shift+Caps Lock to Caps Lock for the rare occasions when I might need it using this AutoHotKey script:
#IfWinActive
^+Capslock::Capslock ; make CTRL+SHIFT+Caps-Lock the Caps Lock toggle
return
I switched the Caps Lock and Ctrl keys a couple of months ago and after the initial learning period, ~ 1 week, my biggest problem is when I use a computer that hasn't switched the keys.
I first did some registry hack but I can't remember where I found the information on how to do it. Now I'm using a small utility called Remapkey which is included in the Windows Server 2003 Resource Kit Tools even though I think I'm using an older version.
I had no problem making the transition. I use keyboards with both configurations without issue. Perhaps having it as a hardware solution (and the labels properly printed) makes it easier than doing it through software and having to remember how each machine/keyboard is setup.
I think what's best to put on caps depends on your physical keyboard.
At home I type on a Kinesis Ergo Elan where my ctrl keys are under my thumbs, along with 2*alt, space, enter, backspace, delete, pgup, pgdn, home and end; the rest of the keyboard is fairly normally laid out, except the board is split.
With the ctrl keys ready at hand, it really makes the most sense to put escape on caps lock (and caps lock on esc, for the few times I need it). Even if you're an emacser, hey... it doubles as a spare "prefix alt key", and you probably ask your browser to stop what it's doing a few times every day.
On the other hand, if I'm typing on my laptop where the lower left corner key is Fn rather than ctrl (ffs...) and I can't hold down shift+ctrl with one finger, it might make sense to put ctrl on caps (such that I can hold them with a single finger). At least if you're not a vi'er, or you don't mind the escape key being further away (or have some crazy system).
What's really interesting is putting some funky key on shift+shift (yep, both shift keys). This can be done with xmodmap fairly straightforwardly; I put my compose key there. If you don't need compose, you may want to put something else (like, say, esc).
Copy the following code into a file called caps-ctrl-swap.reg, execute the file, agree to allow registry to be changed, log out and back in and your caps-lock and left-ctrl keys will be swapped. I've used this script for whatever version of Windows was current in 2005 and every version in between. I needed it today since Windows 10 updated overnight and it still works great.
REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00

Resources