6 ms·
Vim: Spacebar as leader key, CapsLock as Esc
- kps 13y agoPerhaps 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.
- normalocity 13y agoI 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.
- jagger27 13y agoWhat is a leader key? How much typing class did I miss?!
- ryanthejuggler 13y agoI 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
- normalocity 13y agolol - 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.
- publicfig 13y agoLeader is actually a different key than the colon in Vim. Here's a nice description of it: http://learnvimscriptthehardway.stevelosh.com/chapters/06.html http://learnvimscriptthehardway.stevelosh.com/chapters/06.ht...
- ChronosKey 13y agocolon 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-leader-in-a-vimrc-file http://stackoverflow.com/questions/1764263/what-is-the-leade...
- toki5 13y agoIn 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.
- normalocity 13y agoSorry, 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.html http://learnvimscriptthehardway.stevelosh.com/chapters/06.ht... I also fixed the display of the .vimrc file so you can see the "<Leader>" entries.
- q_revert 13y agoI use <space> as my Easymotion leader.. https://github.com/Lokaltog/vim-easymotion 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
- normalocity 13y agoI like the jj trick as well.
- eridius 13y agoI've been using inoremap jk <ESC> for a long time now, and it works like a charm.
- thenmar 13y agojj is great, I also use ; as : to save a key press on a very common command
- daGrevis 13y agoI used `;` remapped to `:` for some time as well, but native functionality of `;` is just too awesome!
- sethish 13y agoI've been using this since [~2010](https://github.com/sethwoodworth/dotfiles/commit/801f4a7163db017c0be7edaee2e358b7f3d4bf50#diff-4e12c6a37ff2cbb2c93d1b33324a6051R77 https://github.com/sethwoodworth/dotfiles/commit/801f4a7163d...). I highly recommend leader as space.
- knodi 13y agoi use my caps as control key.
- Theodores 13y agoIf 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!
- normalocity 13y agolol - 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.
- harryovers 13y agoi have capslock as my backspace key. where do i put escape now?
- jfft 13y agoLove 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-[
- normalocity 13y agoYou 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).
- sgloutnikov 13y agoI 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 http://i.imgur.com/MyL0F8q.jpg
- e12e 13y ago> 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! ;-)
- SmileyKeith 13y agoI 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 https://github.com/rhysd/clever-f.vim
- karmajunkie 13y agoI 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/ 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.
- normalocity 13y agoI 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.
- theOnliest 13y agoThis 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/ http://stevelosh.com/blog/2012/10/a-modern-space-cadet/.
- xiaomai 13y agoFor linux people, this can be accomplished with: https://github.com/cmatheson/super-caps 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.
- munger 13y agoThanks 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
- glynch 13y agoI 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.
- normalocity 13y agoI 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.
- etanazir 13y agoI use ',' and my leader; but have been considering remapping 'esc' ... any suggestions other than CapsLock?
- ChronosKey 13y agojj is what I use and is also pretty common. Some other suggestions: http://vim.wikia.com/wiki/Avoid_the_escape_key http://vim.wikia.com/wiki/Avoid_the_escape_key
- CGamesPlay 13y agoI 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/vimrc#L152 https://github.com/CGamesPlay/dotfiles/blob/master/files/vim...
- svermeulen 13y agoWhy 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.
- erikb 13y agoNobody said it yet, so I have to do it: Happy Hacking Keyboard
- 97-109-107 13y agoThe 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>
- ryan-thompson 13y agoI love this idea, I never thought of using the spacebar as anything other than a space.
- rc4algorithm 13y agoTo 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.
- jdonaldson 13y agoI 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".
- justinmk 13y ago> I jump around in documents by searching through them You might want to try vim-sneak. https://github.com/justinmk/vim-sneak https://github.com/justinmk/vim-sneak