Hacker News new | past | comments | ask | show | jobs | submit login

Two things that helped me more than anything with "learning" vim and or ever wanting to use it:

1. Remap your "capslock" key to "escape." Vi was written using an ADM-3A terminal and its keyboard, which you can see here: https://catonmat.net/why-vim-uses-hjkl-as-arrow-keys has the escape-key in a sane place. On modern keyboards, if you can, remap "capslock" to "escape" when pressed alone, and "ctrl" when pressed with another key.

2. Make your leader key something easy like the comma character "," E.g. to make a horizontal split, I press (not including quotation marks) ",h" or ",v" to make a vertical one.

Once I did those two things it all made so much more sense... It's also great because most editors these days support vim bindings, so even if you don't want to use vim you can still benefit from its really-awsome-once-you-figure-it-out UX.




When I was first learning Vim I remapped caps lock to escape, and it was a huge improvement. But as I became more comfortable in Vim I realized I was using the control key a lot.

I've since remapped caps lock to control, and use ctrl-[ as escape (this is default behavior). I find having an easily accesible control key is very useful, even outside Vim. You can see in your link that it is actually the control key that used to be in the position we now put the caps lock key.

It does seem like remapping caps lock to escape when pressed alone and control when pressed with another key would be nice, but that wasn't an option for me (on wayland) as far as I know.

I bring this up only because there was a week or two transition period when I made this change, and I probably would have been better off if I had mapped caps lock to control from the start.


On Linux and Mac it’s possible to have caps be escape when pressed alone or control when pressed with another key. On Linux the software is called xcape. :)


There's also caps2esc, which works even on the tty. https://gitlab.com/interception/linux/plugins/caps2esc


On Mac, there is Karabiner-Elements.

https://karabiner-elements.pqrs.org/


Here's a Karabiner tutorial that worked for me: https://medium.com/@pechyonkin/how-to-map-capslock-to-contro...


I recently learned this trick since getting a new MacBook pro with the touch bar esc key. I couldn't stand the lack of travel and didn't want to remap keys, now I use the ctrl-[ combo on all keyboards out of habit


Relevant to the other conversations going on in this thread, how simple is it to re-map that ctrl-[ to work globally? I'm assuming I'd have to install something for this. I am also using a Mac and use the caps-lock-as-escape to, say, close my spotlight search bar after activating it using the command+space shortcut.


In theory at least Ctrl-[ "is" Escape and is already universal. Reason: simultaneously pressing Ctrl is the ASCII -> ASCII mathematical transformation "subtract 0x40" for keys that represent a single ASCII character. So for example Ctrl-M is 0x4d - 0x40 = 0x0a. M is 0x4d ASCII and carriage return (aka '\r', aka Enter) is 0x0d ASCII. Ctrl-M is, or at least should be, universally the same as Enter. Similarly '[' is 0x5b in ASCII, so Ctrl-'[' is 0x1b in ASCII which is the ASCII code for, you guessed it I hope, Escape. Phew that was tough on a phone.


that's funny - I'm currently trying the jj remap, but I keep going for esc out of habit


This is what I do on both Linux and macOS. I like remapping Caps Lock to Ctrl/Command because it's the UNIX-style key layout I'm used to on the old IBM Model M keyboards, and my left and right pinky fingers are used to the Ctrl-[ combination, it's burned into muscle memory.


I remap my right Alt to Ctrl. The best thing I have ever done with regards to ergonomics. It works wonders in all softwares, not only vim. It's much more convenient to press with the thumb than CapsLock is with the pinkie.


Die hard vimeleon here.

IMHO chording the 'j' and 'k' keys simultaneously [1] is a severely underutilized solution for escape.

Try it. You'll love it.

If you're going to rebind capslock to something — and this is particularly true if you're on macOS — rebind it to backspace. Capslock escape isn't useful outside of Vim. Backspace is useful everywhere, including inside Vim.

[1] https://github.com/kana/vim-arpeggio


> If you're going to rebind capslock to something — and this is particularly true if you're on macOS — rebind it to backspace.

No, rebind it to Compose. Makes life a lot easier.

https://en.wikipedia.org/wiki/Compose_key


That's interesting. I'm a bit spoiled by primarily using Vim to write code and prosé in American English. Vim's digraph feature (Ctrl-K by default) has handled unicode char input nicely enough for me, but I wonder if the compose key could be of use when writing text in Japanese for example.


I actually meant to do it systemwide, for when you're writing or googling things not in English, or when you want to write a fancy ⅝. The day I have to start putting diacritics into computer code is the day I quit programming:)

I think it's no good for Japanese, but I know very little about Japanese input. Romanji is still Japanese, right?


Now that's an idea. Haskellers routinely use x' as a variable name, but ẋ and x̃ are also valid ones!


I use option-e e to insert é, option-n n to insert ñ, etc. I noticed this while pressing option in the Keyboard Viewer.


The problem with your jk solution is that it doesn’t work in other Vi-like interfaces such as those provided by readline or shells.

Also ctrl-h is backspace so mapping caps to ctrl gives you a convenient escape and backspace shortcut.

(It also gives you a heap more terminal shortcuts but that’s another story).


I sort of got obsessed with the aforementioned ADM-3A keyboard layout, so I got myself a keyboard with unofficial QMK[1] support, and with that I remapped my keys as follows:

- Tab functions as Escape, Caps Lock as Control. That makes both keys well in reach of my pinky, and I can still use ^I for Tab.

- I remapped symbols according to an illustration[2] of the ADM-3A layout on Wikimedia (with some small adjustments). Aside from not having to press shift to enter command-mode, this also has the advantage of being more similar to the German layout, which I often have to use.

- And finally I changed ^H and ^I to work outside of terminal emulators (i.e. they send keycodes for Backspace and Tab, respectively).

While this layout is somewhat inconvenient for navigating CUA-derived UIs, I've found it great for use with vi clones and other TUIs.

[1] https://qmk.fm/

[2] https://upload.wikimedia.org/wikipedia/commons/a/a0/KB_Termi...


I also remap shift-tab to tab in Vim, and then somehow manage to live without being able to actually shift-tab in Vim. I should probably think of some solution for that at some point...


I'm personally a fan of remapping jk or jj to esc, there barely any instances in the english language where you would use those two letters together, and it means you can leave insert mode whilst barely moving your hands :D


My issue with this is that it causes a delay with every single j that is entered. Only a visual delay that freezes the cursor and then lets it jump by two characters, but irritating for me regardless.

Otherwise it's very practical though.


I thought I was the only one. That visual delay made me nuts.


I don’t use it either but I think you can change the delay. Check out :h 'ttimeout' and :h 'ttimeoutlen'

Haven’t touched that part of my vimrc in years


Changing the delay will not completely get rid of this phenomenon but will definitely make a ton of my other shortcuts harder to use. That visual delay makes a lot of sense, it's just not a feature that was intended with this specific use in mind and so it seems to behave strange for jj/jk/etc shortcuts.


I tried mapping both jk and kj to Esc for a while (so I could just mash them in any order), but the slight delay it added to the letters always threw me off my loop.


You can reduce the delay by setting ttimeoutlen, the time in milliseconds between an escape key being pressed (or jk etc. that are mapped to Esc) and exiting Insert mode. I have it set to 100.


The first thing I put in my .vimrc on any system:

  inoremap jk <ESC>
I learned it through Spacemacs and it's one of the things that really made modal editing work for me, so I was thrilled to discover that Vim itself also supports it. (I'd tried to learn Vim before, but always having to jump over to the Escape key was a huge downer for me, and coming from Emacs I'd already mapped my CapsLock to Ctrl--though the idea of having it be Esc if pressed by itself is intriguing and I need to look into it more!)


I use jk too. Happy with it. My .vimrc has this: set <esc>=jk I wonder what the difference is.


I use zz, it's similarly rare and compliments ZZ (save and quit) well.


But how are you gonna solve fizzbuzz?


I like kk.


On remapping caps:

ctrl-[ is escape in terminals by default.

It’s often easier to map caps to ctrl than escape when pressed and ctrl when held. Most OSs support that without extra software.

Even in Vim it’s still very useful to have a convenient ctrl key. A lot of useful features make use of Ctrl in Vim.

On remapping leader:

Remapping to spacebar means your thumbs are dedicated to that operation. That’s more balanced left-right for touch typing.

Also you get to keep the default behaviour.


> Remap your "capslock" key to "escape."

I hear this recommendation a lot. You can do that, but much better is to get a keyboard with a proper thumb cluster like a kinesis[1], maltron[2], dactyl[3], ...

Much better to put such a common key on the thumb than stress out a pinky. I have a kinesis, and have esc mapped to the 'end' key there; similar positioning is possible on other keyboards. The keyboards I linked are also much more ergonomic than most flat keyboards—important, if you rely on your hands and wrists for your livelihood. Bit expensive, but well worth it.

1. https://kinesis-ergo.com/shop/advantage2/

2. https://www.maltron.com/

3. https://github.com/adereth/dactyl-keyboard


Several years ago I finally developed RSI. It took nearly a year of different setups and exercises to figure out what would work. The cause of RSI for me was a well known ergo keyboard. I had been using it for nearly a year before the pain/numbness started in my hands. I went back to standard slab keyboards, and every time I use a ergo keyboard the issues flare up again.

So, while I like the style of those keyboards, I can't justify spending that much if I am likely to develop RSI again.

---

I'm one of those weirdo's that has remapped caps to Lctrl/esc, tab to hyper/tab, \| to alt/\|, return to Rctl/enter. It's comfortable. (Ralt is now Compose/Dead Greek and Rctrl is Caps Lock)

I would love more buttons to the left of the keyboard. I currently use a 10-keyless but would love a cluster of 10-15 keys to the left of my left hand. and possibly 6 keys under the thumb area. And a real dedicated hyper key. Maybe another row of F-Keys too...


For me it was enough to just remap my right Alt to Ctrl. No need for expensive hardware which I can't bring with me everywhere. The ThinkPad keyboard is good enough.


Regarding 2, I think using 'space' as leader will be the most easy one to get into. You don't lose any meaningful functionality and space is (ideally) operated with your thumb, which means you can bind any key combination without awkward hand movements.


I just use ctrl-c instead of esc. Infinitely more accessible than esc or even ctrl bracket - it mystifies me why it’s not more commonly known. Only problem is that it quits you out of macros, so you need to use esc then, but that’s easy to remember and I use ctrl-c probably 4 orders of magnitude more than I use macros. (In fact, multi cursor mode in vscode vim obsoletes them for me entirely!)


It’s not that ctrl-c isn’t widely known it’s that Escape and ctrl-c are not equivalent in Vim.

Ctrl-c breaks all kinds of things including repeats, so ctrl-[ is usually a better choice.


my leader character is space, makes things super easy


Make your leader key something easy like the comma character ","

I would do this but I use the comma and semicolon keys all the time. I find them so useful. Gosh vim is weird. Everyone uses it differently!


I guess you mean you use them to insert ,s and ;s. But the leader key would not be for insert mode, so you can choose anything convenient.


No, I use them with the f and F keys. They repeat the previous character search in forward and backward directions.


Oh, I see. Sorry for assuming. I use the ; for that often, but didn't even know about , for going backwards. (Now I'm thinking that my bunch of maps using , were not such a good idea.)


I find rhysd/clever-f [1] to be more DWIM than Vim's default f/F.

    " 0: F is backward search, and repeating f after F searches in the same direction
    " 1: F is backward search, and repeating F after F searches in the same direction
    let g:clever_f_fix_key_direction = 1
[1] https://github.com/rhysd/clever-f.vim


I try not to use vim plug-ins where built in functionality will suffice. I’ve trained vim’s default behaviour into my muscle memory so I’m fine with it. In fact, I used plain old vi (technically Keith Bostic’s nvi [1]) for years and sometimes I find myself preferring it.

I think a lot of people who use vim end up with a ton of unnecessary plugins and they aren’t even aware of half the functionality of plain vi. I might just be a weird minimalist though.

[1] https://sites.google.com/a/bostic.com/keithbostic/vi/


About 1., you can simply use ctrl-] as an alternative Escape command.


Remap esc to ‘kj‘ instead. It’s faster to type than ‘jj’ it’s on the home row and doesn’t require a custom binding. The sequence kj is rarely used in English or coding.


What a hackjob that is.


> Remap your "capslock" key to "escape."

Isn't it possible to configure vim to just use the actual CapsLock status for the mode switch?


I see the value of remaping the esc key to cpaslock, but my hands are quite big and I can reach esc on most keyboards quite effortlessly.


I think this is a bad idea because remapping keys has significant consequences with compatibility as you develop across more platforms. A good vi user is trying to build universal muscle memory, and making personal exceptions kinda ruins the efficacy of the editor.

For example: I switch between dozens of computers, some are transient VMs or cloud instances, and I cannot afford the time (or simply cannot alter the system) to set each one up to my personal VI specs.

(Ironically, I'm a mac fan, but this is my biggest gripe going between every OS and Apple: the command key is absurd; I tried to remap to make everything work like Ctrl but that hoses the entire system and screws up VNC/RemoteDesktop...)


I haven't done this completely (I use the jk remap hack in preference to escape) but I agree with this in general.

Emacs is an operating system, and vi is a language, which is widely "spoken". But if you invent your own dialect, you have an MxN problem, of getting M changes to register across the N programs which will listen to you when you speak to them in vi.

And I simply must nibble the bait in your last line: As a Mac native user, the command key, and consistency in commands across every native application, is one of the great features. It means, among other things, that Ctrl-whatever won't be intercepted when I send it to a program that uses it, or alternately, that it won't shadow the OS level affordance.

Back when I was spending five days a week inside a Linux VM, the context switch between Cmd-X and Ctrl-X for cut was pretty rapid and painless. Sure, I'd get the occasional cache miss, but that's harmless.


You should absolutely personalize tools you use extensively. Vim if your a writer or programmer.

It’s very little to cp .vimrc. I do a lot more, have dotfiles git repo scripted to self install.

But yes transient vms are problem. But I’m willing to suffer a little on them to have 20x more enjoyable and productive were I do 90% of my writing.


The first thing I do on a new machine is clone my dotfiles from Github. It's fast enough for an action that increases my productivity exponentially and I'll end up saving back that time it took to clone very quickly. I don't switch machines that often anyway.


I wholeheartedly agree with this sentiment. I have a lot of keybindings but I always make sure I can survive without them, such as by dropping into vanilla vim to once in a while to do work and ensuring I'm not completely lost. A user in the vim subreddit refers to this as 'sharpening the saw'.




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

Search: