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.
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-backwardThanks. Keeping track of whether certain directories were capitalized or not has been unnecessarily occupying my mental bandwidth for years.
set editing-mode vi
... in one's inputrc and... set -o vi
... in one's .bashrc?I realize that .inputrc is the config file for Readline, and .bashrc is essentially a start-up file for Bash. But is it ever necessary to use both snippets?
"\C-l": clear-screen bindkey -M viins 'jj' vi-cmd-modeworks well with "\t": menu-complete
But I had to delete this entry. I need the case to differentiate between which path I really wanted :(
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.
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.)
These work in most GUI inputs as well.
[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
}Don't forget Ctrl-[ instead of Esc. I find that more quick, especially with Ctrl in place of CapsLk. :)
$ 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.
On Windows the equivalent is start (e.g. start C:\ )
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".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 ""
$ echo "alias o='xdg-open'" >> ~/.bashrc $ qlmanage -p <file> $ qlmanage -p <file> &>/dev/nullI guess I can sum this up by saying OS X has an additional modifier key than Windows, so you basically have 33% more power right out of the gate. The "Windows Key" is nearly useless.
X Window software used to get this right, too; Unix workstations generally had another modifier (e.g. Meta, diamond on Suns) since they knew better than to hijack keys people would type in a terminal. It's only the this-is-finally-the-year-of-Linux-on-the-desktop crowd slavishly imitating Microsoft's mistakes that screwed it up.
I don't agree with this at all.
I find it baffling that a company of great designers made such bad decisions about keyboard shortcuts.
Perhaps they are consistent, but they are consistently bad.
Paste and match style (incredibly useful) is "alt-shift-command-v" i.e. four keys. There are plenty of other shortcuts that also require four keys. Four is too many. Three is too many for such an important function. This is absurd.
Using shortcuts in IDEs is a nightmare on most apple keyboard. e.g. Intellij, to run your program: alt-shift-f10. This is daft in itself, but it actually translates to function-alt-shift-f10 on many keyboards. Yes, you can change your settings, but then you could remap all your keys in any O/S. Miss the function key and you've just muted your volume.
I have no interest in slagging Apple off; I use their products almost exclusively, but this is obviously an area where they messed up. I'd love to see this fixed, although I understand why they probably won't.
And such dumb commands within the menus! eg. Xcode show debug area: cmd-shift-y, continue: ctrl-cmd-y; these seem stupid to me, but probably because they have repurposed the Fn keys (F1-F19) to show expose etc. instead of having real function key behaviour, and probably because some function keys are missing from the tiny wireless keyboards...
To be fair, I am perfectly used to both of them but moving from OS to OS was a horrible learning curve to begin with!
I would say that keyboard shortcuts are consistently bad across OSX but I am perfectly used to them :-)
The use of the Command key and a bunch of standard shortcuts using it are particularly notable.
#notsoobjective
There's just no reason for Windows to be that bad.
C-a is always "beginning of line" and Command-C is always Copy.
and never the twain shall meet.
(I've had issues in linux going from terminal to windows, in fact very recently I kept ^W'ing while in GUI mode)
$ 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.
Just make a new shortcut under the All Applications group named exactly the same as the one you want to replace. http://i.imgur.com/JqBncTy.png
I've also had to add an entry for "Paste as Quotation" because that's Mail's default use of Command-V.
I've used the same trick on occasion when copying text from web pages into Gmail. When you paste such text into a Gmail draft, Gmail tries to duplicate the format of the original, which is often not what you want. pbpaste | pbcopy solves the problem nicely.
Edit: But Shift-Option-Cmd-V is easier. Thanks, Janteh!
Then you need to add the following to .tmux.conf
set-option -g default-command "reattach-to-user-namespace -l zsh"
There's a good writeup on what and why here, https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/blob/...pbpaste |sed 's/FIND/REPLACE/g' | pbcopy
Maybe make this into a script you can run from alfred. ;)
Also if you want to have access to pbcopy remotely, try this:
python -m SimpleHTTPServer
I'd recommend an alias like "serve". It basically puts the current directory online (binds to 0.0.0.0:8000). python -m smtpd -n -c DebuggingServer localhost:25
A makeshift SMTP server that logs all messages to the console. curl -s http://some/json/url | python -m json.toolFor pretty-printing without modification,
cat myjson | jq '.'Or Ruby: ruby -run -e httpd .
If you use Spotlight to find something and then want to see the file in Finder, Cmd+click the item in the Spotlight dropdown.
Edited from Cmd+shift+click due to note in child comment :-)
alias imgsz='sips -g pixelWidth -g pixelHeight'
sips stands for "scriptable image processing system"[1], and provides terminal users with a toolset for inspecting and manipulating images. The alias above is really useful for web developers who need a quick look at how big a given image is:
$ imgsz logo.png
/path/to/logo.png
pixelWidth: 500
pixelHeight: 120
[1] https://developer.apple.com/library/mac/documentation/Darwin...System Preferences > Keyboard > Modifier Keys
Saves lots of awkward pinky-bending.
I noticed this coming from Windows and Linux on other keyboards where tapping Caps Lock works but on Mac OSX with an Apple keyboard or on a Macbook you have to make a real deliberate effort to keep the key down longer than a nanosecond for it to register.
Is it just me who has noticed this?
Once I started with iTerm and built a config/flow around it, I can't go back.
Thanks for the tip though! I didn't realize this worked in Terminal too. I'll keep it in mind the next time I'm forced to use it.
I used to be a die-hard Terminal.app user but with Mavericks it felt incredibly sluggish doing everything from opening to listing files to editing things and this is another reason I moved to iTerm.
Be warned, though, that if you're using Vim with Solarized you and you're trapped in low color mode you want to be sure you're declared as a 256 color term and update your `vimrc` to remove the following for the colorscheme to work properly:
Remove:
* let g:solarized_termcolors = 256
* let g:solarized_termtrans = 1
* let g:solarized_contrast = "normal"
* let g:solarized_visibility = "normal"
Option-click is the shortcut to tell the terminal to forward the click to the application running in the terminal. That's usually your shell or some editor.
I seem to faintly remember that at some point this was actually configurable and you could configure the terminal to forward non-option-clicks and only enable selection mode on option clicks. I didn't find this option in current iTerm or Terminal.app versions though - I might just be imagining this.
Meta-f jump forward a word
Meta-b jump backwards a word
The shortcuts also work in every text field in the OS.
Terminal.app passes the key sequences to the application running inside of the terminal. The default shell (bash) uses GNU readline, which has an emacs-mode and a vi-mode (emacs is the default).
Terminal.app does not use any Cocoa text fields, so has nothing to do with the Emacs keybindings inherited from NeXTSTEP.
It's up to the process running in Terminal.app to support the key sequences sent to it. I doubt that M-f would work if your shell (bash, zsh, etc) were in Vi-mode rather than the default of Emacs-mode.
Ctrl-x, Ctrl-e will pop open your EDITOR so you can edit the command. Saving and closing the editor brings the command back in your terminal and automatically executes it.
fc will bring up your EDITOR with the last typed command. (You can use fc -l to see a list of commands)
* Ctrl-a to go to beginning of line
* Ctrl-e to go to end of line
I miss this feature a lot when I switch back to windows. I find myself pressing ctrl-n in my browser's address bar, expecting to view my URL history, and instead I get a new windows.
If anyone knows of a way to get similar functionality in windows, I would love to hear about it!
* ⌘ + ` (tilde key) to switch between different windows of your current application
* ⌘ + l (lowercase L) in most web browsers to highlight the address bar
Woohoo, love me some Linux, let choice reign ;-)
⌘ + ` to switch between different windows of current application
⌘ + SHIFT + ` to switch between different windows of current application (reverse order)
same for the general application switcher:
⌘ + TAB to switch between different windows of current application
⌘ + SHIFT + TAB to switch between different windows of current application (reverse order)
So, in practical terms, this means you have 1 + n clipboards[1]. The main global GUI clipboard (using the command key), and then an app-specific clipboard (using the control key with Emacs bindings). As a developer, it is extremely helpful to have two clipboards in TextMate, for instance.
[1] Technically, the clipboard in OS X maintains a history (not sure what the limit is), but the OS X GUI only exposes the last cut/copied item.
It's not that Macs are crappy, they just have different key bindings. I regularly work with Macs, Windows, and Linux for development and I've just learned to use the different key mappings.
I don't think I'm quite as proficient in any one system because of that, though. For example, I have avoided learning the Emacs key bindings for use in Mac/Terminal. (I don't want to try to remember TWO bindings for Mac, plus I learned vim first so usually avoid Emacs.)
Also, iTerm is a great Terminal replacement, if you haven't tried it.
(when (eq system-type 'darwin) (setq locate-command "mdfind"))
iTerm 2.0 Build 1.0.0.20140112 (latest version)
Two fingers: up/down: scroll up/down, left/right: forward/back in some browsers (such as Chrome)
Three fingers: up/down: show/hide a list of applications/desktops; left/right: switch desktops one at a time.
Five fingers together/apart: show/hide desktop
Before I discovered these, I was confused why I would occasionally see the forward/back arrow in the browser for a short period of time, not realizing that it showed because I happened to use a couple of fingers to move the mouse cursor.
you can add tons of additional trackpad shortcuts too, as well as keyboard shortcuts.
Another fave of mine: Ctrl-w for deleting whole "words" at a time. Better than holding that delete key down.
The default shell for OS X appears to be bash (my favorite shell as a Linux user as well).
Just google for Bash shortcuts. Here's a place to start: http://teohm.github.io/blog/2012/01/04/shortcuts-to-move-fas...
Also, Option+click and drag gives you column selection mode.
More tips linked in above tweet: https://apple.stackexchange.com/questions/5435/got-any-tips-...
However this is an issue which I dont know is a bug or something (I'm on Ubuntu 12.04) - if you open "System Settings" in Ubuntu and copy text from there, I'm not able to paste it on the browser, but am able to paste it everywhere else using the command sequence described above.
There's a system wide setting to make the cursor huge, but I don't want a huge cursor everywhere. And there's a terminal preference to make the insertion cursor different, but that's a different cursor, not the mouse cursor.
When do I want to see the mouse cursor? It's useful for things like highlighting a git hash or a few lines of text for copy/paste.
I often do "cd " + dragon drop folder to get to that folder in terminal
This includes dragging a folder's proxy icon to the terminal app to open the current Finder window in a new terminal.
The proxy icon is the little icon in the top middle of the window, to the left of the name.
Command-Tab is fine and dandy, but I want more stability in my application switching. And if it doesn't exist, I may have to dust off XCode like I've been threatening to do for a while now.
These two commands replace 'cd' and work with a directory stack of different paths.
$ pushd tmp # cd to tmp and remember current path /
/tmp /
$ pwd
/tmp
$ cd /usr # normal cd to wherever you want...
$ pwd
/usr
$ popd # pop the stck and get back to the previous path
/
$ pwd
/
Subsequent pushd will stack multiple paths.It's a built-in of bash and other shells. It works even with Windows' cmd.exe
$ cd /
$ pwd
/
$ cd /tmp
$ pwd
/tmp
$ cd -
$ pwd
/
Not the same, of course, but still useful, I think.Regarding OSX Terminal, I'm an heavy user since Leopard but it's a shame that after upgrading to Mountain Lion (an now Mavericks) I discovered that they broke VIM vertical selection since control-shift does not generate a keycode anymore [1].
Anyone with the same problem? I tried iTerm recently and I don't like it! :-(
[1] https://discussions.apple.com/thread/4694342?start=0&tstart=...
Ctrl-e: go to the end of the line Ctrl-r: search backwards (input the text)
and you go to the point where the search begins.
Another useful fyi that I haven't seen anybody else mention is the Bash framework bash-it [https://github.com/revans/bash-it/]. It has tons of fantastic plugins, aliases and themes out of the box.
I've only tried it on iTerm2, but as it only replaces your .bash_profile file it should work fine on Terminal.
bindkey -v
Now be happy, hit <ESC> and, use ^ and $ but also f<letter> t<letter> and also ,;.
You can copy/paste with dd, Y, etc...
(Note: I wrote MacTerm.)
set -o vi
this makes most vim motions available at the command line after hitting "esc"
/s
/s
What's more interesting is the possibility of using the new shell integration features (https://code.google.com/p/iterm2/wiki/ShellIntegration) to turn off this feature just at the shell prompt. I'll open a feature request for that :)
Thanks for sharing!
No.