3

I am a VIM user learning Emacs commands for use in Bash. I know that on my systems I can use Vim-keybindings in Bash but I'd like to learn how to use it effectively in its default configuration.

Consider the following command which uploads a file to a web service:

$ time curl -F "status_file=@under1meg.txt" -F "baz=777&bin=123&alice=bob" http://somesite.com/internal/project/status/foo/add_status.php

I have a bunch of files to upload with different parameters. Here are some questions:

  1. How might I easily go back from the end of the line to before the http part? The combination AltB only goes back per [a-z] block, so I must to this for each directory in the URL. Is CtrlRSpace the preferred way to go back? Notice that CtrlW does delete back to the previous whitespace, so the idea of <something> until whitespace seems to exist.

  2. How might I delete back to the @ character from the current cursor position? Pressing CtrlW deletes until whitespace, so that won't help as the @ character is buried in non-whitespace. I could CtrlR@ and then AltD to delete words until I get to where I need to be, but this is rather obtuse. Is there not a delete until previous <something> command?

Note that I am interested in learning how to use the default Bash configuration as I am more often than not SSHed into some webserver. I don't want to configure Zsh, Vim keybindings, or .bash_profile.

5
  1. "M-C-]" character-search-backward so M-C-] SPC in this case will go before http

  2. M-C-] @ and then C-k to delete from point to the end of the line (although it seems that you only want to delete to where you were before. I don't know any better option than M-d for that). To my knowledge there is no delete until previous <something> defined by default

What I find very useful is C-y which "yanks" (pastes) the contents of the "kill ring". So when you do C-u (delete from point to the beginning of line) you can paste this back with C-y and pressing M-y after C-y will cycle through the other "kills" made before (C-w, C-k etc.)

Also good to know is C-/ which is undo

If you want to know more, checkout man readline (readline is used by Bash) which has a neat section DEFAULT KEY BINDINGS:

       Emacs Standard bindings

       "C-@"  set-mark
       "C-A"  beginning-of-line
       "C-B"  backward-char
       "C-D"  delete-char
       "C-E"  end-of-line
       "C-F"  forward-char
       "C-G"  abort
       "C-H"  backward-delete-char
       "C-I"  complete
       "C-J"  accept-line
       "C-K"  kill-line
       "C-L"  clear-screen
       "C-M"  accept-line
       "C-N"  next-history
       "C-P"  previous-history
       "C-Q"  quoted-insert
       "C-R"  reverse-search-history
       "C-S"  forward-search-history
       "C-T"  transpose-chars
       "C-U"  unix-line-discard
       "C-V"  quoted-insert
       "C-W"  unix-word-rubout
       "C-Y"  yank
       "C-]"  character-search
       "C-_"  undo
       " " to "/"  self-insert
       "0"  to "9"  self-insert
       ":"  to "~"  self-insert
       "C-?"  backward-delete-char

       Emacs Meta bindings

       "M-C-G"  abort
       "M-C-H"  backward-kill-word
       "M-C-I"  tab-insert
       "M-C-J"  vi-editing-mode
       "M-C-M"  vi-editing-mode
       "M-C-R"  revert-line
       "M-C-Y"  yank-nth-arg
       "M-C-["  complete
       "M-C-]"  character-search-backward
       "M-space"  set-mark
       "M-#"  insert-comment
       "M-&"  tilde-expand
       "M-*"  insert-completions
       "M--"  digit-argument
       "M-."  yank-last-arg
       "M-0"  digit-argument
       "M-1"  digit-argument
       "M-2"  digit-argument
       "M-3"  digit-argument
       "M-4"  digit-argument
       "M-5"  digit-argument
       "M-6"  digit-argument
       "M-7"  digit-argument
       "M-8"  digit-argument
       "M-9"  digit-argument
       "M-<"  beginning-of-history
       "M-="  possible-completions
       "M->"  end-of-history
       "M-?"  possible-completions
       "M-B"  backward-word
       "M-C"  capitalize-word
       "M-D"  kill-word
       "M-F"  forward-word
       "M-L"  downcase-word
       "M-N"  non-incremental-forward-search-history
       "M-P"  non-incremental-reverse-search-history
       "M-R"  revert-line
       "M-T"  transpose-words
       "M-U"  upcase-word
       "M-Y"  yank-pop
       "M-\"  delete-horizontal-space
       "M-~"  tilde-expand
       "M-C-?"  backward-kill-word
       "M-_"  yank-last-arg

       Emacs Control-X bindings

       "C-XC-G"  abort
       "C-XC-R"  re-read-init-file
       "C-XC-U"  undo
       "C-XC-X"  exchange-point-and-mark
       "C-X("  start-kbd-macro
       "C-X)"  end-kbd-macro
       "C-XE"  call-last-kbd-macro
       "C-XC-?"  backward-kill-line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.