The vim keyboard shortcuts thread



  • Continuing the discussion from Status: How can our eyes be real if they exist in the complex plane?:

    @ben_lubar said:

    Status: I should really learn more commands for vim than just a, A, i, I, R, Esc, :w, :q, :wq, v, V, Ctrl+v, d, y, p, gu, gU, and Ctrl+xCtrl+o.

    gd
    ,gd
    ,i


  • :wq!
    
    apt-get install nano
    


  • I'm fond of the t and f movements. Both take a character argument; t moves to just before the nth occurrence of the character, f moves onto it.

    Also, C-x C-] for autocompletion based on the tags file.


  • Winner of the 2016 Presidential Election

    I'd agree with you if nano's copingcopying wasn't so damned awkward!

    Seriously, probably the two biggest reasons I use vim instead of nano are visual block selection and y-related shortcuts.



  • ^C^C^C

    ­




  • gd

    Ctrl+o



  • I've ended up using w/e for movement a lot. Also c for changing stuff (didn't see that in the original post). I use :s fairly extensively, although somebody pointed out that for a lot of the stuff I do with :s, recording a few actions with q would be much easier. Trying to use that every now and then.

    In insert mode, there's also C-x C-f for autocompleting a file name, which is handy at times.

    Edit: what's up with the random spaces being eaten by discourse?



  • And don't forget the mighty . to repeat the last action.

    /oldname<enter>
    cwnewname<esc>
    n.n.n.n.n.
    


  • You need one of these;



  • I defined space as the leader, and leader + j and k to be 10 j and k, respectively. Don't know how people handle moving up and down in Vim without something like that. { and } just don't quite cut it, IMHO. Also jk for escape in insert mode, because who wants to reach for escape or one of the control equivalents all the time?








  • @ufmace said:

    because who wants to reach for escape

    I remapped caps-lock to escape. Who needs caps-lock anyway? (Besides, for really long sections of UPPERCASE, there's v+U).



  • @cvi said:

    Who needs caps-lock anyway?

    There was a book somewhere that proved the shift key is adequate for typing several hundred pages of all caps.



  • Not bad, but my finger are already over j and k. This also causes me to occasionally type random jks into inferior text editors.

    Also, WOAH DISCOURSE SUPPORTS SOME VIM BINDINGS! as I randomly hit j and k and notice that it seems to move me up and down. Maybe Discourse isn't all bad? Eh, who am I kidding here?



  • @ufmace said:

    This also causes me to occasionally type random jks into inferior text editors.

    Inferior text editors where it's possible to type the string "jk" without pushing extra keys in the middle?



  • @ufmace said:

    Maybe Discourse isn't all bad?

    YMBNH­



  • Besides, the finger gymnastics for holding down shift don't bother me; I prefer a Swedish keyboard+layout even for programming. AltGr finger-gymnastics FTW!

    (Yes, in this particular instance, I'm possibly TR :wtf:)



  • Which will surely work fine if I'm actually renaming a function. That's not the common case.



  • PageUpPageDown work. If I'm editing code I'm usually using search.



  • What is a common case for renaming something, then? Local variables?



  • @ufmace said:

    Not bad, but my finger are already over j and k. This also causes me to occasionally type random jks into inferior text editors.

    I like the idea, but that would take me a lot of retraining to start using properly. (For some sequences, I still occasionally reach for the "normal" escape key afterwards, despite having had the caps-lock remap for years.)



  • Never needed to do that, except when telling people about it. But if you do, you just have to wait a second before hitting the k.



  • Local variables. Struct members. Prefixes of same. Not always the same action with all occurrences - if all I wanted to do was rename things I wouldn't be spending time refactoring.



  • Normally I use Ctrl+U and Ctrl+D for moving up and down. They move half a page at a time. You can also use Ctrl+B and Ctrl+F (back, forward full page) but that's too much movement at once for me.



  • Yeah, I know them. I just wanted something that moves up and down less and without moving the screen view. I probably use zz, z-enter, and z-minus for moving the view more often, though.



  • I just use the arrow keys. Even vi on our old version of Solaris supports that.



  • Oh yeah? OH YEAH?! Sometimes I use the freaking mouse wheel to scroll. How do you like that?





  • @cvi said:

    @ufmace said:
    because who wants to reach for escape

    I remapped caps-lock to escape. Who needs caps-lock anyway? (Besides, for really long sections of UPPERCASE, there's v+U).

    After I had to use Windows at work I started using ^C to get to command mode. It works on most vi clones and emulations and I don't need to remap caps lock. It's also not that far from the home row.

    % is also handy to go from starting curly bracket to ending curly bracket. Too bad if you're using python.



  • No mention of / and ? for searching (along with // and ?? to repeat the last search)?


  • :belt_onion:

    @PleegWat said:

    I'm fond of the t and f movements. Both take a character argument; t moves to just before the nth occurrence of the character, f moves onto it.

    I'm starting to like the vim-sneak plugin for its extensions to this model, sadly it's not available in most Vim emulators for IDEs.



  • IIRC, remapping caps lock to escape is fairly simple under windows. (It's possible to do without third-part tools even, just with regedit.) MacOS on the other hand... It's doable with ukulele (which I typically want anyway, to get a sane keyboard layout), but I don't think there's an easy/quick way.



  • @Scarlet_Manuka said:

    (along with // and ?? to repeat the last search)

    Or you could use n, which doesn't require hitting enter after it, and has a counterpart N for going in the opposite direction.



  • @ufmace said:

    Not bad, but my finger are already over j and k. This also causes me to occasionally type random jks into inferior text editors.
    Blijkbaar is dit onmogelijk when writing Dutch.



  • I suppose if you're writing dutch, or any other language where jk is actually used, you'd have to pick another pair of home-row keys to make a quick command-mode shortcut.



  • ... or you could map it to a key that doesn't appear in text, like caps lock or escape. When I'm typing, my hands don't stay in home row.





  • :'<'>s/[some horrendous regex]/\1: &\r/gc



  • Fuck you all, Discourse says this thread is "new".


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.