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.
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.
- 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.
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.
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)
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
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.)
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
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
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:
$ open filename.png
$ open .
$ open -e filename.txt
$ open -a Pixen filename.png
The first command will open the file with the default application.
Open . will open the current directory in finder, which I find very helpful. The -e flag will open the file in textedit. The -a will open the file in the given application name.
I use start all the time, but also frequently curse at its stupid argument grammar and its interaction with auto-quoting on auto-completion. For example, type
start C:\Doc
Next, hit tab to get
start "C:\Documents and Settings"
Now, hit return, and watch a new command window open with title "C:\Documents and Settings".
I think xdg-open defers to gnome-open/kde-open/... depending on what DE is currently running. Not sure about that. Anyway, xdg-open should be installed anywhere where any kind of DE is installed.
This seems to run whatever code usually runs when you hit [space] on a filename in a Finder window. (Except that it outputs a bunch of debugging information.) Under what circumstances is that any better or more useful than "open"?
Correct (man 1 qlmanage). Depending on the type of file, it is usually faster to open quicklook than opening the file in its default application, especially if you just want to take a look and you don’t actually need to edit the file.
After making the switch to OS X in the last couple years after living in Linux and Windows before that, I think it's objective to say that keyboard shortcuts in OS X are much worse in both ease of use and consistency across applications.
Useful when copy/pasting things to share with other people in email and such:
$ pbpaste | pbcopy
takes the current contents of the copy/paste buffer and removes color/font/background color rich formatting and puts just plain text back into the paste buffer.
And of course pbcopy and pbpaste are also very useful on their own.
Comments (395) 107 threads
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.
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.
- 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.
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.
Continue this thread — 6 replies
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
Continue this thread — 4 replies
These work in most GUI inputs as well.
But yes, the keybindings work in Cocoa text controls, too, for example in TextEdit, in the Safari URL/search control, etc.
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.)
Continue this thread — 1 reply
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
Open . will open the current directory in finder, which I find very helpful.
The -e flag will open the file in textedit.
The -a will open the file in the given application name.
On Windows the equivalent is start (e.g. start C:\ )
Reason? If the first argument is a quoted string, it is used as the title of the window being opened (http://www.microsoft.com/resources/documentation/windows/xp/..., http://stackoverflow.com/questions/154075/using-the-dos-star...)
If you ever use start in batch scripts, pass a dummy first argument of ""
Continue this thread — 1 reply
Continue this thread — 1 more reply
Continue this thread — 77 replies
And of course pbcopy and pbpaste are also very useful on their own.
Continue this thread — 10 replies
All comments shown.
Couldn't load more comments. Check your connection and try again.