Lurker News
OSX Terminal: hold option and click a position in the current line to move your cursor to that position. #yearslost

Comments (395) 107 threads

Show all comments

Showing thread 1 of 107

juanre12 replies#
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.

adventureloop1 reply#
I started using vi mode recently. The only thing that I really miss are ci and di commands.
graywh#
ci and di aren't commands. c and d are operators and the i is part of the motion--specifically, text objects.
andrewtbham#
great tip. on my system i added it to .bash_profile.
SDGT3 replies#
C-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.

pavanky4 replies#
More:

- 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.

oinksoft2 replies#
Just 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.

pavanky1 reply#
Thanks! fixed.

I never noticed C-u was from cursor. I tend to use it mostly from the end of the line.

oinksoft3 replies#
And that's why C-e C-u is burned into my hands :^)

Continue this thread — 3 replies

teddyh#
Note: Ctrl-U and Ctrl-W are not from Emacs. They are instead from the same group as Ctrl-C for interrupt, Ctrl-D for End-of-File, etc; i.e. traditional Unix TTY driver keys. Run “stty -a” to see them all; the stty command can also be used to change them.
Syssiphus4 replies#
Pressing ESC and then _ will insert the last argument of the last line. Repeat to go up in the history.

If you go through the command history and press CTRL-o on a line it will be executed and the command on the commandline will be replaced by the next line in the history.

Continue this thread — 4 replies

ivanhoe#
also alt + backspace, works similar to ctrl + w, but word is defined as only alphanumerics. Very useful when deleting parts of the long file paths because it will stop on / character (unlike C-w that deletes the whole path)
RBerenguel4 replies#
Also, most emacs keybindings (C-u and C-w don't, but C-k, e, a and y do, at the very least) work in all Cocoa text fields. This (in general) means you have two copy buffers: the normal, system wide Cmd-C (or X), Cmd-V and the "Cocoa wide" C-k C-y buffer

Continue this thread — 4 replies

lazerwalker#
It's worth noting that that the C-w/C-k/C-y yank ring is a distinct buffer from the system Cmd+X/C/V pasteboard.

That way, you can have two different things on your clipboard without having to use a fancy clipboard manager. (Or, alternatively, you can be confused why the thing you're pasting isn't the thing you thought you copied last.)

jbeja1 reply#
I 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.
pyre1 reply#
Depends on how much of Vi/Vim you use. IIRC, Evil-mode doesn't implement everything.
jbeja#
Pretty much 90%, but that is enough at least for me.
eof1 reply#
you 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#
bash/emacs has C-x C-e to open up the command in a editor.
tjdetwiler#
zsh also has these modes.
bilalq6 replies#
I 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-ryan3 replies#
Thanks 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#
Oh 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_man1 reply#
Command-K also does the trick

Continue this thread — 1 reply

yawboakye#
Signs 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#
>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.

Continue this thread — 4 more replies

Continue this thread — 5 more replies