Live data from Hacker News

Bash One-Liners Explained, Part V: Navigating around

catonmat.net

11–20 of 35 posts

Re: Bash One-Liners Explained, Part V: Navigating around

#11
post #7
post #5

This is a great guide. Especially awesome for me was: 26. Change input mode to vi $ set -o vi This command changes the key bindings to vi's. If vi's your favorite editor, you'll love this. I'll cover the vi mode in more details in the next part of the article. I'd love to find a cheat sheet for vi bash usage (and also an indicator for which editing mode I'm in).

I'm a huge vi(m) fan, but still use Emacs-style readline. When editing code in vim, I tend to make several edits each time I'm in edit mode. When at the terminal, all I'll need is "go to front" or "search backwards". And which is easier: Esc+Shift-6+i or C-a? Esc+Shift-/ or C-r? I'm in no way an Emacs ninja, but it's not too hard to memorize the ten or so most common commands. Added bonus: they work in OS X and Qt te…

I like vi-mode in my shell primarily for j/k to navigate through history (arrow keys just always suck imho, and C-r to search backwards in history is just overkill most of the time) and 'c[motion]', which is what I almost exclusively find myself using to correct things I messed up ('d[motion]' pops up less frequently). 99% of the time those are 99% of the things I use; for that set of features I think the vi sequences are definitely have the advantage.

Re: Bash One-Liners Explained, Part V: Navigating around

#13
post #2

If you find yourself using these keyboard shortcuts frequently, you can save yourself some pinky fatigue by remapping caps lock to ctrl.

Doing this was a big part in saving my left hand from RSI. I can't emphasize enough how awesome it is to have ctrl bound to caps lock.

Re: Bash One-Liners Explained, Part V: Navigating around

#14
post #9

My biggest complaint is that the semantics of CTRL-w and ALT-b are different. CTRL-w goes to the last space, and ALT-b goes to the nearest non-letter. Why did they define word in two different ways for the two different commands? I would kill for a non-deleting version of CTRL-w; if I have a long path in a command-line I want to be able to move to the previous parameter, not just the previous path element.

Alt+Backspace deletes to the last non-letter.

To go to the previous space, Ctrl+R SPACE works for me.

Re: Bash One-Liners Explained, Part V: Navigating around

#15
The author notes that there is no meta key anymore [1], however you can often setup your terminal emulator to use another key as the meta key.

In iTerm [2] I have the left alt/option key setup as meta, so things like meta-b are much easier to type then Esc-b.

[1] "You'll often see Meta+b but there is no such key on the keyboards anymore." [2] Profiles -> Keys "Left option acts as meta"

Re: Bash One-Liners Explained, Part V: Navigating around

#16
post #11
post #7

Earlier quoted context omitted.

I'm a huge vi(m) fan, but still use Emacs-style readline. When editing code in vim, I tend to make several edits each time I'm in edit mode. When at the terminal, all I'll need is "go to front" or "search backwards". And which is easier: Esc+Shift-6+i or C-a? Esc+Shift-/ or C-r? I'm in no way an Emacs ninja, but it's not too hard to memorize the ten or so most common commands. Added bonus: they work in OS X and Qt te…

I like vi-mode in my shell primarily for j/k to navigate through history (arrow keys just always suck imho, and C-r to search backwards in history is just overkill most of the time) and 'c[motion]', which is what I almost exclusively find myself using to correct things I messed up ('d[motion]' pops up less frequently). 99% of the time those are 99% of the things I use; for that set of features I think the vi sequence…

The Emacs next-line and previous-line bindings C-n and C-p also work well for history navigation.

Re: Bash One-Liners Explained, Part V: Navigating around

#17

"Bash uses the readline library for input editing. The readline library supports emacs style key bindings[...]" Been using Emacs for a year and I didn't know this. O_o

Are you using a Mac? Because if you are, those Emacs motion key bindings work in almost all text input fields in all apps.

Re: Bash One-Liners Explained, Part V: Navigating around

#18
post #7
post #5

This is a great guide. Especially awesome for me was: 26. Change input mode to vi $ set -o vi This command changes the key bindings to vi's. If vi's your favorite editor, you'll love this. I'll cover the vi mode in more details in the next part of the article. I'd love to find a cheat sheet for vi bash usage (and also an indicator for which editing mode I'm in).

I'm a huge vi(m) fan, but still use Emacs-style readline. When editing code in vim, I tend to make several edits each time I'm in edit mode. When at the terminal, all I'll need is "go to front" or "search backwards". And which is easier: Esc+Shift-6+i or C-a? Esc+Shift-/ or C-r? I'm in no way an Emacs ninja, but it's not too hard to memorize the ten or so most common commands. Added bonus: they work in OS X and Qt te…

uhh... try Esc-I and Esc-A. And Ctrl-R still works in vi mode.

Re: Bash One-Liners Explained, Part V: Navigating around

#19

"Bash uses the readline library for input editing. The readline library supports emacs style key bindings[...]" Been using Emacs for a year and I didn't know this. O_o

Are you using a Mac? Because if you are, those Emacs motion key bindings work in almost all text input fields in all apps.

I'm on a Mac about once or twice a week at work. Thanks for the heads-up!

Re: Bash One-Liners Explained, Part V: Navigating around

#20
post #13
post #2

If you find yourself using these keyboard shortcuts frequently, you can save yourself some pinky fatigue by remapping caps lock to ctrl.

Doing this was a big part in saving my left hand from RSI. I can't emphasize enough how awesome it is to have ctrl bound to caps lock.

Yes! It's the first thing I do when I get a new system these days.

In OSX you can set it up in keyboard preferences and in Windows I use Autohotkey.

Working on a keyboard with a regular Caps Lock key feels very strange after all this time.

Post reply on HN