Hacker News new | past | comments | ask | show | jobs | submit login
Vim: Spacebar as leader key, CapsLock as Esc (karmanebula.com)
39 points by normalocity on Dec 16, 2013 | hide | past | favorite | 43 comments



Perhaps I have spent so much time on Mac that pressing the Ctrl key for things feels unnatural vs. the Command key

Argh. OS X is the last significant platform that gets this right by not trying to use Control for menu shortcuts out of the box. When I'm in a terminal, or editor, or browser text box, it's perfectly common and reasonable to want to distinguish Control-V (literal) from Command-V (paste), Control-Z (suspend) from Command-Z (undo), and so on.

Pre-Linux X Window software typically managed this, using Meta or some other keysym for GUI operations, but current ‘desktops’ seem dead set on imitating MS Windows. Damn kids get off my screen.


I think this is one of the main reasons I went with space in this case. Hitting a shortcut starting with a key that either thumb can reach felt more like the Command key, which is part of why I like it. It seems that my thumb is more nimble (and has a much higher range of motion) than my pinky.


I basically do this, but I use "," (comma) as my leader, and I make capslock do double duty as ctrl and esc using KeyRemap4MacBook (https://pqrs.org/macosx/keyremap4macbook/). The trick is first remap capslock to Ctrl in keyboard system preferences, then use KR4MB to remap Control_L (the left control key, which is to say, what capslock now signals) to Control_L, but if you type ONLY Ctrl_L it sends esc. so when i need escape, it sends that. when i want to use it for Ctrl-modified combos, it does that. Works fantastically for Vim, i've been doing this for a couple years now. Also nice for emacs keyboard shortcuts in other apps that respond to them.


This is what I do too: Caps Lock sends either Escape (when pressed alone) or Control (with something else). I cribbed it from Steve Losh: http://stevelosh.com/blog/2012/10/a-modern-space-cadet/.


For linux people, this can be accomplished with: https://github.com/cmatheson/super-caps

That said, I don't use this anymore because I found that I rarely release escape (er, caps lock) before moving on to the next key. So I was getting a lot of control-n instead of <Esc>n.


I also use KR4MB, but I found that I'm migrating toward a multi-system (more than one keyboard on more than one OS) situation. This introduced some peculiarities to my workflow where it means I can't rely on KR4MB always being available. I originally thought I might use KR4MB a lot more, but I've had to minimize its use to get that cross-platform consistency in my particular case.


To the many of you using Macbooks: be aware the that the caps lock key is deadened/delayed in order to prevent mistaken pressing, and that this is a hardware feature that can't be changed. This may be the case for Mac keyboards and other new systems as well.


I use <space> as my Easymotion leader..

https://github.com/Lokaltog/vim-easymotion

it's well worth a look, gives you super quick fine grained movement

similarly

    inoremap jj <ESC>
to take you from INSERT mode to NORMAL mode is nice


I've been using

    inoremap jk <ESC>
for a long time now, and it works like a charm.


Likewise. Started with 'jj', but 'jk' is significantly faster. Only downside is that you can't actually type 'jk'. Now everybody thinks I'm serious all the time.


twiddle with the timing settings (I forget). So typing 'jk' only very quickly indeed will register as ESC.


jj is great, I also use ; as : to save a key press on a very common command


I used `;` remapped to `:` for some time as well, but native functionality of `;` is just too awesome!


I like the jj trick as well.


I use CapsLock as escape but had I not gotten so used to that by now I would probably have used it for control instead and mapped escape to jk or something. I, like many people, use `,` for my <leader> and with Clever-F[0] I don't lose the original functionality which is just remapped to consecutive presses of 'f'.

[0]: https://github.com/rhysd/clever-f.vim


Love spacebar as the leader key, but not a fan of CapsLock as Esc. CapsLock as Ctrl is better. For one, you never have to stretch for the real Ctrl, and two, you can use it for escape as well: Ctrl-[


> and two, you can use it for escape as well: Ctrl-[

Sadly, not (sanely) with a Norwegian keyboard layout. We "only" have one key left of z, namely "<" (and with shift ">") -- and not really any keys right of "l" and "p" -- right home-row is "jklø" followed by "æ", and "å" is right of "p".

Way out in the cold by the enter key we have "'" (shift for "*"), and the not-so-useful composing '"' (and "^~" with shift/alt-gr respectively).

If only we could stick to something like romaji'zed Japaneze, we'd have plenty of keys left over! ;-)


I do the same, and caps lock as control works great. After speaking with a colleague of mine who has worked with Unix from way back before my time, I learned to do this. This was actually where the control key was on old keyboards -- http://i.imgur.com/MyL0F8q.jpg


You know, I've heard a lot of people go this route, and they like it a lot.

I tried it for a couple of days, maybe not long enough, and I guess a lot of this comes down to feel, which comes down to previous typing experience and personal preference, which seems that it may be highly personal (though I don't have data to back that up).


I broke things down by priority. I notice that I jump around in documents by searching through them, rather than by navigation keys. Spacebar is the biggest key on the keyboard, so, spacebar is mapped to "?" in normal mode. I also find that I need to search through a project regularly, so ctrl-spacebar is mapped to the ack/ag command.

Control is mapped to caps lock at the os level for me. There are also too many useful commands in vim that use control (visual block mode is huge). I tried mapping jj to escape as well, but ctrl-c is just as easy.

Leader is mapped to comma. Most of my leader commands are comma + "some letter I can type with my left hand".


> I jump around in documents by searching through them

You might want to try vim-sneak.

https://github.com/justinmk/vim-sneak


I prefer remapping capslock to control for easier use of commands like <C-f>, <C-b>, <C-e>, <C-h>, and <C-l> (all of which were absent in the example vimrc posted). Using the leader key makes total sense for dealing with splits and buffers or plugins you might want to look into some of the other Control based commands that Vim supports.


I use Ctrl-f and Ctrl-b (as well as Ctrl-e and Ctrl-y) pretty often, and you're right that there are no shortcuts for it in the provided example. Perhaps I should look into those as possible next targets. I guess I'm not entirely eliminating the Ctrl key from my vim usage (not that there's anything wrong with Ctrl, really), but you have a point.

I'm guessing I use Ctrl-e more often than :e - perhaps I should change that up.

There seems to be a lot of ringing endorsements for CapsLock as Ctrl in the comments.


Thanks for the easy-to-understand take on the leader key. Not using the leader key is one of my known vim weaknesses I've been meaning to fix. I found your explanation and usage a great push into actually putting it in my .vimrc


I end up using Ctrl for a bunch in vim: visual block, ctrlp (and <C-b> for buffer mode), window nav, and most importantly, imported emacs keybindings. The emacs line motion commands (specifically <C-a>, <C-e>, and <C-d>) are extremely useful because they work in every app on my mac, so not having to lose flow when I'm in vim or a browser is nice.

https://github.com/CGamesPlay/dotfiles/blob/master/files/vim...


If I am going to have to relearn where some of the keys are in vim then I might as well go the whole hog and get a Dvorak keyboard whilst I am at it!


lol - well, it's just an option. Certainly less invasive than changing the keyboard layout, but I understand the muscle memory element of it.

I definitely stuck with the default vim bindings (and for the most part can switch back to them quickly) until I wanted to customize the experience to my preferences. There's definitely something to be said about keeping the stock bindings unchanged, if that's one's preference.


I've been using this since [~2010](https://github.com/sethwoodworth/dotfiles/commit/801f4a7163d...). I highly recommend leader as space.


Why not map caps lock key to both escape AND control? I've been doing this successfully for a long time and couldn't live without it. You can use Autohotkey on windows and similar tools on other systems to interpret caps lock pressed by itself as escape, and caps lock pressed + another key as control.


The is a way of minimizing the frequency of having to reach esc (be it at esc or caps lock) " jj For Quicker Escaping between normal and editing mode. inoremap jj <ESC>


What is a leader key? How much typing class did I miss?!


I think he means instead of using a colon to begin Vim commands, he begins by typing a space.

I started using Caps Lock as an extra Ctrl a couple months ago. It's great, except now I can't use other people's computers because I end up in caps-lock shout mode.

E.g. instead of "ctrl+l" in my browser to visit a site, it ends up:

    CTRL+SHOUT+L BROWSER TAKE ME TO FACEBOOK I COMMAND THEE


Leader is actually a different key than the colon in Vim. Here's a nice description of it: http://learnvimscriptthehardway.stevelosh.com/chapters/06.ht...


colon is used to enter Ex mode. Leader is a separate key (used as an extra modifier like the Meta key in Emacs) http://stackoverflow.com/questions/1764263/what-is-the-leade...


lol - yeah, I have the same problem. I recently did some pairing on someone else's computer and it took me a good 20 minutes to start reaching for the intended key instead.


Sorry, I guess I didn't describe that in the article. I've updated the article to include this link:

http://learnvimscriptthehardway.stevelosh.com/chapters/06.ht...

I also fixed the display of the .vimrc file so you can see the "<Leader>" entries.


In vim, you can use the leader key to set up shortcuts, e.g.:

:map <Leader>W :w [some things you want to tack onto w]

The leader key is by default '\', so that's effectively mapping \W to :w [some things ...]

He's replacing his leader key with space.


I use ',' and my leader; but have been considering remapping 'esc' ... any suggestions other than CapsLock?


jj is what I use and is also pretty common. Some other suggestions: http://vim.wikia.com/wiki/Avoid_the_escape_key


I love this idea, I never thought of using the spacebar as anything other than a space.


Nobody said it yet, so I have to do it: Happy Hacking Keyboard


i have capslock as my backspace key. where do i put escape now?


i use my caps as control key.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: