8 ms·
Bash, running in your terminal, understands both the Emacs and the Vi commands. By default is Emacs, so you can C-a (control-a) for beginning of line, C-p to g
by juanre 13y ago
Bash, running in your terminal, understands both the Emacs and the Vi commands. By default is Emacs, so you can C-a (control-a) for beginning of line, C-p to go back in command line history, or C-r to search it.
I prefer the Vi mode, though. Add to your .bashrc
set -o vi
Then you can press escape to go from input mode to normal mode; there k will take you to the previous line in command line history, j to the next line, ^ and $ to the beginning and end of the line, /something will search something back.
Editing is really fast; move by words with w (forward) and b (backward), do cw to replace a word, r to replace a letter, i to go back to input. It will remember the last editing command, just as Vi, and repeat it when you press . in normal mode.
- adventureloop 13y agoI started using vi mode recently. The only thing that I really miss are ci and di commands.
- graywh 13y agoci and di aren't commands. c and d are operators and the i is part of the motion--specifically, text objects.
- andrewtbham 13y agogreat tip. on my system i added it to .bash_profile.
- SDGT 13y agoC-a : beginning line, C-e end line, alt+f forward word (unless system shortcut for file menu), alt+b back word, C-k kill line, C-b back char, C-f forward char. At least in my current setup, C-w yank and C-y paste works as well. Immensely helpful. Sometimes at+left/right does forward/ back word depending on the terminal emu. Note most of these keystrokes are valid in nano as well.
- pavanky 13y agoMore: - C-u to kill (cut) from current location to beginning of the line - C-k to kill (cut) from current location to end of line - C-w to kill (cut) from current location to beginning of word - C-y to paste (copied / cut) lines - C-l to clear screen (I use the shit out of this) - Ctrl + shift + '-' (holding ctrl, shift, minus at the same time), for undo. That is it. EDIT: Damn it, I didn't realize I was saying a bunch of the same things as you did. EDIT2 Thanks oinksoft for clearing up C-u and C-w.
- oinksoft 13y agoJust wanted to note: C-u kills from cursor to start of line. C-w kills from cursor to start of previous word. M-d is its friendly forward sibling.
- pavanky 13y agoThanks! fixed. I never noticed C-u was from cursor. I tend to use it mostly from the end of the line.
- oinksoft 13y agoAnd that's why C-e C-u is burned into my hands :^)
- philsnow 13y agoIs it any different from C-a C-k ? Both seem to stuff things into the kill ring (or whatever it's called in bash). I guess lots of people leave C-a as the default escape key for screen.
- oinksoft 13y agoYea, there's the GNU Screen mapping conflict, and also I rarely use C-k so it's not in my muscle memory.
- jbeja 13y agoI you tried Evil-mode, i actually using Emacs with this, now i got the power of emacs with the efficiency of Vi in one place.
- eof 13y agoyou can also go into visual mode (at least in vi mode).. pressing esc then v will launch your default editor with the current command in the buffer; saving an exiting runs the command; very useful for long commands and/or iterating
- jewi 13y agobash/emacs has C-x C-e to open up the command in a editor.
- tjdetwiler 13y agozsh also has these modes.
- bilalq 13y agoI use these settings in my .inputrc. The get me a few more commands and even the ability to escape using jj. set completion-ignore-case On set bell-style none set editing-mode vi $if mode=vi set keymap vi-command "gg": beginning-of-history "G": end-of-history set keymap vi-insert "jj": vi-movement-mode "\C-p": history-search-backward
- b-ryan 13y agoThanks for this. I switched my input mode to VI and was greatly missing using Ctrl-L to clear the screen when in input mode. I hadn't known about the inputrc before. Adding this line below your "\C-p" line fixed that for me: "\C-l": clear-screen
- bilalq 13y agoOh wow, I didn't even think about that. I've been making do with Cmd+K on OSX and aliasing c to clear to get around the problem.
- tambourine_man 13y agoCommand-K also does the trick
- bilalq 13y agoCommand-K won't play nicely with tmux panes though.
- yawboakye 13y agoSigns you have to revert to Emacs mode. Unless it's an assemblage, it's always a smell if you replace a unit of a body with that of a "competitor."
- awolf 13y ago>set completion-ignore-case On Thanks. Keeping track of whether certain directories were capitalized or not has been unnecessarily occupying my mental bandwidth for years.
- bgar 13y agoTo get [NORMAL] on the right side of the terminal like in Vim, I put this in my .zshrc file: function zle-line-init zle-keymap-select { VIM_PROMPT="%{$fg_bold[yellow]%} [% %{$reset_color%}NORMAL%{$fg_bold[yellow]%}]% %{$reset_color%}" RPS1="${${KEYMAP/vicmd/$VIM_PROMPT}/(main|viins)/} $EPS1" zle reset-prompt }
- Tyr42 13y agoIs there a bash version of that? I don't care about where it is too much.
- ansimionescu 13y agoAgreed, this was the reason for me to learn my first emacs shortcuts. Also, the option+click thing doesn't work in iTerm, so unfortunately it doesn't help me but -side note- it's amazing that after years of using OS X I can still discover small productivity features like this, and I think it stands for the thoughtfulness of the people behind it.
- aheu 13y agoyou sure? it works for me in iterm2
- JAFTEM 13y agoI just realized you can use some of these Emacs commands in the Chrome browser address bar (not sure about others).
- rhubarbquid 13y agoMost text inputs in Mac OS support at least C-a and C-e too.
- qoo 13y agoYes, Cocoa text fields by default supports EMACS keys such as C-a, C-e
- _cipher_ 13y ago> Then you can press escape [..] Don't forget Ctrl-[ instead of Esc. I find that more quick, especially with Ctrl in place of CapsLk. :)