← Back to context

Comment by ahmedfromtunis

13 hours ago

Using the terminal becomes much more cozy and comfortable after I activate vim-mode.

A mistake 3 words earlier? No problem: <esc>3bcw and I'm good to go.

Want to delete the whole thing? Even easier: <esc>cc

I can even use <esc>v to open the command inside a fully-fledged (neo)vim instance for more complex rework.

If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.

This reminds me of an excerpt from an old Emacs manual:

    . . . if you forget which commands deal with windows, just type @b[ESC-?]@t[window]@b[ESC].

This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world.

I think the better advice for command-line editing would be to set up the mouse.

  • For a bit about the language, read `3bcw` as move `b`ackward by `3` words and `c`hange the `w`ord under the cursor.

    The general form of `b` is `[count]b` where

        [count] An optional number that may precede the command to multiply
                or iterate the command.  If no number is given, a count of one    
                is used, unless otherwise noted.  Note that in this manual the
                [count] is not mentioned in the description of the command,
                but only in the explanation.  This was done to make the
                commands easier to look up.  If the 'showcmd' option is on,
                the (partially) entered count is shown at the bottom of the
                window.  You can use <Del> to erase the last digit (|N<Del>|).
    
        b       [count] words backward.  |exclusive| motion.
    

    https://vimdoc.sourceforge.net/htmldoc/intro.html#[count]

    https://vimdoc.sourceforge.net/htmldoc/motion.html#b

    For `c` it’s

        ["x]c{motion} Delete {motion} text [into register x] and start
                      insert.  When  'cpoptions' includes the 'E' flag and
                      there is no text to delete (e.g., with "cTx" when the
                      cursor is just after an 'x'), an error occurs and
                      insert mode does not start (this is Vi compatible).
                      When  'cpoptions' does not include the 'E' flag, the
                      "c" command always starts insert mode, even if there
                      is no text to delete.
    
        {motion} A command that moves the cursor.  These are explained in
                 |motion.txt|.  Examples:
                     w           to start of next word
                     b           to begin of current word
                     4j          four lines down
                     /The<CR>    to next occurrence of "The"
    

    https://vimdoc.sourceforge.net/htmldoc/change.html#c

    https://vimdoc.sourceforge.net/htmldoc/intro.html#{motion}

  • I have yet to see a shell that has mouse enabled line editing support. It should certainly be possible though.

    I do prefer vi bindings at the same time though. Vi bindings and mouse support complement each other well, you don't have to choose one or the other, just use whichever feels most natural and convenient in that exact moment.

  • > This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world.

    I think it's a question of context and familiarity. To a vim user, like me and, I assume, ahmedfromtunis, their examples do indeed seem simple and natural. Presumably, to an emacs user, the example you quote (if it's quoted literally—I don't use emacs and can't even tell) is just as natural, and assuming some comfort with emacs is presumably OK in a manual for the software!

    • > assuming some comfort with emacs is presumably OK in a manual for the software!

      How do you get familiar with the software, if the manual expects you to be an expert in it already?

      5 replies →

    • The example confusingly includes some weird markup. It's just saying press `ESC-?` then type "window" to search for window commands. These isn't even valid in modern Emacs. The equivalent is `C-h` followed by `a` then type "window".

I've been a (n)vim user for 20+ years now, but I hate vi-mode in the shell. However if I feel that I need to do a complex command, I just do ctrl-x+e to open up in neovim (with EDITOR=nvim set). I find it a good middle ground.

  • It’s strange. I have heard this from lots of others too. I think I am an anomaly here. I can’t live without shell vi mode

    • it is an additional burden to switch to shell vi mode, it is not the standard. Maybe you can put it in all of yout bashrc files but you will probably hear some swearing from the people logging to your machines :).

    • You're not alone, I heavily rely on vi mode and often struggle if I'm on someone else's machine and can't use it. I always wonder how you're supposed to work without it but I never dare to ask

      1 reply →

  • I'm the same and in my opinion this is the best of both worlds. Taking the time to learn some of the regular (emacs-style) shortcuts is one of the best investments I've ever done. Even just CTRL+Y and the likes.

    edit: And of course, CTRL+R, the best time saver of all

  • Huh. I don’t use vi-mode for more than jumping to the beginning or end of a line, which I like a lot.

  • I used to hate it because I'd sometimes change modes without realizing it, but I began to appreciate it a lot more when I added a mode indicator -- a red 'N' on the rightmost side of the input line.

  • Agree.

    I WANT to love it - and if I was only ever working on one, or a small number of systems that I was the only one working on I’d probably do it. I’m ALL about customizing my environment.

    However ssh into various servers through the day (some of which are totally ephemeral), and having to code switch my brain back and forth between vim mode and emacs mode in the shell would just slow me down and be infuriating each time I connect to a new box.

I use vim a lot but not on the shell

A mistake 3 words earlier?

meta-bbbd (not as elegant, I admit)

delete the whole thing?

ctrl-ak (this is even quicker than vim, especially if capslock is mapped to ctrl)

the control-based emacs movements work system-wide on macos btw. I am using ctrl-p and ctrl-n to go up and down lines, ctrl-a and ctrl-e to go to beginning and end of lines while writing this comment in by browser (which has vimium extension)

Sometimes I wish vim just had full emacs bindings while in insert mode. But I don't like to mess with defaults too much.

I keep thinking I should give vim readline a try though, so maybe today. Thanks for the comment.

Oh wow I didn't know about this, thank you. The underlying feature is called "readline vi-mode" for folks who want to search more about it.

> <esc>cc

Doing control+o in insert mode temporarily places you into normal mode so that you can execute one normal-mode command, and then go back to insert mode again--no need to hit 'i' again.

So, instead of '<esc>cc', '<c-o>S'.

  • The vim version is much easier, if you ask me: 3 strokes, 2 keys and 0 combinations.

    The one you suggest however requires 4 strokes (ctrl then o then shift then s), 4 keys (ctrl, o, shift, s) and 2 combinations.

    The "cc" sequence deletes the line and switches automatically to insert mode. To forgo the switch, the sequence then becomes "dd".

    • Maybe I have my bash/readline vi mode configured specially to do this, but if I want to delete the entire line and type a new one (from anywhere in that line), I do something simpler than either of these alternatives:

      <esc>S

      Esc exits insert mode (of course) and capital S erases the line and puts you in insert mode at column 0 (just like in (n)vim, right?).

      Like I said, maybe I configured that? But 'S' is standard vim-stuff... (I'm not able to double check my config at the moment).

      [Edit: right after hitting submit I realized that my way is perhaps "arguably" simpler because I do have to hit shift to get capital S. So I'm also hitting three keys...]

    • <c-o>S is also a vim sequence. The equivalent readline/emacs is <c-e><c-u> or <c-a><c-k>, or just <c-u> or <c-k> if you're already at the end/start of the line.

I've been a vim/nvim casual user for the past year or two, and I still feel as if I'm slightly less proficient in it for the amount of time that I put into it.

I really need to get around to playing with it more. I just hope that especially now with genAI that it's not too late for learning it further.

   <esc>3bcw

What is your keyboard layout? This looks like a crime against humanity on a regular qwerty kb.

  • I use qwerty and azerty, and in both I never felt typing the sequence was any harder than typing any other regular word. Generally speaking, I prefer sequential "shortcuts" then multikey bindings.

  • Instead of esc, type ctrl [

    • Does it help a lot? You've still got a three to type which is a crime, plus some letters, only to move 3 words. My typing skills are not great, but that sounds like an awful lot of work(?)

      If I hit CTRL + ARROW_LEFT 3 times, I am done a lot faster I guess. But I am open to learn, do people really use that and achieve the goal significantly faster?

      4 replies →

The <esc>v has been such a lifesaver at times when having to execute/modify super complex commands!