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.
I never noticed C-u was from cursor. I tend to use it mostly from the end of the line.
I guess lots of people leave C-a as the default escape key for screen.
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.
$ stat /tmp/foobar
File: `/tmp/foobar'
Size: 0 Blocks: 0 IO Block: 4096
...
$ rm -v $_
removed `/tmp/foobar'With a numeric prefix argument N, it grabs the Nth-from-the-end argument of the previous command, so M-3 M-. grabs the 3rd-from-last argument from the previous command.
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.)
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 "\C-l": clear-screenThanks. 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?
works well with "\t": menu-complete
But I had to delete this entry. I need the case to differentiate between which path I really wanted :(
bindkey -M viins 'jj' vi-cmd-mode [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 ""
explorer "C:\Documents and Settings"
does what you'd expect. $ echo "alias o='xdg-open'" >> ~/.bashrc $ qlmanage -p <file> $ qlmanage -p <file> &>/dev/nullC-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)
In OSX, last time I looked (maybe a version or two ago), there was really no builtin way to achieve the same thing. Command+Space then typing what I want to open is pretty close, but way more keystrokes, and not as powerful.
It's not quite as straightforward, but you can define custom services using Automator, and subsequently bind them to any key combo using System Preferences.
Since Automator workflows can do pretty much anything (like running AppleScripts, shell scripts, manipulating other apps etc...) you're pretty much free to do what you want.
http://www.macosxautomation.com/services/learn/tut01/index.h...
The use of the Command key and a bunch of standard shortcuts using it are particularly notable.
#notsoobjective
If naught else, I will say that:
- The use of Cmd so widely and consistently makes it easy to bind one's own shortcuts to Ctrl/Shift/Alt/... (every menu in almost every application I use contains only Cmd shortcuts).
- The ability to remap shortcuts to anything in a menu being built into the system for all apps systemwide (System Preferences -> Keyboard) is amazing and underappreciated, methinks.
- The almost completely consistent use of a single windowing toolkit (Cocoa) everywhere makes a whole bunch of controls incredibly consistent in feel, which includes all textboxes supporting OS X and Emacs cursor movement keys, irrespective of the application - the mind boggles. o_O
- Similarly, the systemwide use of Cocoa means that the endless tools that allow for keyboard rebinding and window movement that we see (Slate, BetterTouchTool, ...) not only can exist but work very reliably and with few corner cases with most-every application on the system, oftentimes through the Assisted Access APIs (another thing Apple do well on all their platforms, I'm quite reliably informed).
OTOH, on Linux I use Xmonad as my DE and I will admit to missing the amazing keyboard-based window control I get with the tiling window manager (I use Slate on OS X for a poor facsimile to the same effect).
Well, I didn't know this was possible... and I have used Macs for a few years!
I 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.
The blame lies with "desktop environments", not X.
X has plenty of its own problems without getting Gnome's problems heaped on top.
Edit:
> It's only the this-is-finally-the-year-of-Linux-on-the-desktop crowd slavishly imitating Microsoft's mistakes that screwed it up.
Most of the recent garbage they've cargo-culted from Apple (and common software for OS X), not Microsoft. Witness the really shitty reimplementation of Growl, the really shitty (and shamefully unmandated) window menu bar -> system menu bar consolidation.
And hey, as far as ‘really shitty reimplementations of Growl’ go, even Apple has one now.
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.
I really find that hard to see as anything but the IDE's fault, probably due to cross platform shortcuts not rethought for OS X - but even then, something like 40 base non-function keys times at least four combinations of modifiers, and something as important as running the program gets relegated to alt-shift-F10?
That's fine, but the IDE is an application running on the OS X platform. OS X has these problems just as much as any platform, but the situation is made worse by their use of the function keys and by poor choices for other shortcuts.
Now you could point out Pages has the same shortcut and same stupid behavior. I agree, but that's what happens when there's a clear market leader.
(Oddly enough, I've been implementing a web-based word processor, and we make paste-and-match (paragraph) style while retaining (character) styles the default. You can't actually do this in Word or Pages — default or not — despite the fact it's what users want 99% of the time. So if I paste some text with an italicized passage, the font changes to match the ambient styling, but the italics remain. When we implemented it, the UX people were flabbergasted -- they assumed it must be impossible because no word-processor does it.)
If I copy and paste from a web browser, sometimes I want the formatting and sometimes I don't. It's not an usual case. Places where I use this shortcut include Word, Evernote and Mail. It's just not a sensible key combination.
The default SHOULD be to lose the formatting of the original and to use the font/style that is in Word. I would think that 99% of time anyone is copying and pasting into Word this is their intended result.
I agree with the other post, it is incredibly stupid to have it keep formatting from the original by default.
Yes, it is. https://developer.apple.com/library/mac/documentation/UserEx... says "Table A-2 lists the system-reserved and commonly used keyboard shortcuts mentioned in the rest of this document."
Table A-2: contains ../art/ks_option_2x.png ../art/ks_shift_2x.png ../art/ks_command_2x.png V Apply the style of the surrounding text to the inserted object (equivalent to the Paste and Match Style command). See “The Edit Menu.” That links to https://developer.apple.com/library/mac/documentation/UserEx..., which describes the command, too.
I disagree with the claim that this is a bad choice, though. It may not be optimal if starting from a tabula rasa, but Apple did not do that when it introduced the combination, five years ago or so, in my memory. By that time Command-V has done styled paste for about 25 years, making it difficult to dethrone.
We must be glad that we have a standard for this, not angry that it may be a bit complex to type.
I'm suggesting the standard paste should behave as expected, not adhere to some literal definition the user doesn't care about. If I copy a passage of text from one document and paste it into another, I generally want it to look like it belongs in the destination document but I don't want to lose obvious intentional styling such as italicization.
The common case should be the easy case. Instead we have the common case and the four-fingered shortcut both doing the wrong thing. Awesome.
Maybe, the logic in a word processor should be to keep character styling, but not paragraph styling, but I think there will be many edge cases (for example, the user might be using the word processor as a document layout package)
I doubt those edge cases can be programmed away; user intervention is required. Microsoft solves that after the paste. That may be the better solution.
> Paste and match style (incredibly useful) is "alt-shift-
> command-v" i.e. four keys . . . Four is too many. Three
> is too many for such an important function.
I've literally never heard of this functionality before, in any application, on any platform. tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
tell application process "System Preferences"
click checkbox 1 of tab group 1 of window "Keyboard"
end tell
tell application "System Preferences" to quit
end tell
Then, put the following line into your .bash_profile. alias f12="osascript .f12Keys"
Now whenever you need to switch the default behavior of function keys, simply open a new terminal window and type "f12". It takes my computer about half a second to execute. That's kind of the brilliance of Apple products and Cocoa. If there's something you do frequently, if it's in a GUI or otherwise, so long as it's written in Cocoa you can automate it. Yeah, most Apple users have never heard of AppleScript, but for those who use it for the little things every day, it's quite helpful.I could never remember the various screen shot shortcuts, so for me it's command-escape for the clipboard and option-escape for straight to a file.
It took me less than a minute to change Pages so command-v pastes matching style, and command-option-v pastes with the original style. Even better, Pages's menus display the new shortcuts.
The latest Pages doesn't really seem to have paragraph styles vs. character styles, so it might be more difficult to pull that off, but Automator is very clever, and AppleScript moreso, so I'm betting it's possible.
The WindowsKey is often overlooked, for example, there are great key combinations for manipulating application windows. WindowsKey+Arrow moves the current window around in a logical way (up maximizes, left docks to left edge of screen, etc), WindowsKey+Shift+Arrow moves the current window to another monitor in a sensible fashion. Out of the box OS X doesn't seem to have equivalents.
On OSX, you can install something like ShiftIt, but if ANYONE discovers such a utility for Linux that is DE agnostic, I would cry with joy because I am using tile -m at the moment...
why? command-Tab (switch between and show running apps) and command-Q (force quit)
also you can use command w to close a window if really really want to go that route
Edit: Thanks arrrrg, just noticed your solution - alt command esc to reactivate the Force Quit window, then command W.
What’s not as obvious is how to close this window without the mouse when you have switched to some application and Force Quit is no longer the active window. Command-Tab won’t allow you to switch to the Force Quit window since it’s not treated as an app by OS X. However, you can switch to the window by simply using the command for Force Quit again, i.e. pressing Command-Option-Esc, then closing the now active force quit menu with Command-W.
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 :-)
There's just no reason for Windows to be that bad.
I second the "everything is about five syllables" and sure, you can set up aliases, but I went through that hell on VAX/VMS and don't want to go back.
Plus why are all the built-in commands like 20 characters long and camel cased?
Anyway, if you have to suffer PowerShell at least do it in the ISE.
Depending on where the control is on your keyboard (Windows vendors keep swapping FN and CTRL unfortunately, and rebinding might not be easy), I think the position of the hand is more natural - on the other hand, you might strain your pinky when pressing CTRL (or SHIFT) for long time and I haven't noticed that with using my thumb yet (and I doubt it will happen, given it is a much stronger finger).
$ 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.
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:
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!
python -m SimpleHTTPServer
I'd recommend an alias like "serve". It basically puts the current directory online (binds to 0.0.0.0:8000).OS X comes with apache preinstalled though
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
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.
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.
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
so Ctrl-A Ctrl-K will clear a given field
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.
For the most in depth info on the Cocoa Text System: http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html
* ⌘ + ` (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)
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.)
Yes, other systems have other key bindings, but why do common things like jumping to the begin/end of a line need a key combination? And why aren't the characters written onto the keys? Every time I have to type some code on a Mac I have to press all the keys in order to find { } [ ] etc. At leas I learned not to quit the terminal when I want to enter a @ by now. Whose brilliant idea was that?
In contrast a German PC keyboard: http://www.buypcsupplies.com/images/cat/38568_xlargenss_ndo4...
However, I prefer a Microsoft Comfort Curve keyboard, but I can't find an image of the German version right now.
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!
Also, iTerm is a great Terminal replacement, if you haven't tried it.
iTerm 2.0 Build 1.0.0.20140112 (latest version)
(when (eq system-type 'darwin) (setq locate-command "mdfind"))
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
http://www.bashguru.com/2010/04/how-to-handle-cursor-movemen...
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.