Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard shortcut to jump to previous command in iTerm2?

In Terminal, I can simply to cmd+up arrow. How can I do this in iTerm2? I've tried the cmd+shift+up arrow option, but it doesn't work reliably, especially when there is a currently running process.

like image 575
Logan Avatar asked Mar 07 '18 23:03

Logan


People also ask

What is the shortcut to go back to previous command?

To learn about the keyboard shortcuts in the new content editor, see Keyboard shortcut functions. To reverse your last action, press CTRL+Z. You can reverse more than one action. To reverse your last Undo, press CTRL+Y.

How do I switch between panes in iTerm2?

Split Panes iTerm2 allows you to divide a tab into many rectangular "panes", each of which is a different terminal session. The shortcuts cmd-d and cmd-shift-d divide an existing session vertically or horizontally, respectively. You can navigate among split panes with cmd-opt-arrow or cmd-[ and cmd-].

How do I skip to the beginning of a line in terminal?

CTRL-A / HOME : Move to the beginning of a line.

What does Ctrl w do in terminal?

Ctrl+W: Cut the word before the cursor, adding it to the clipboard. Ctrl+K: Cut the part of the line after the cursor, adding it to the clipboard. Ctrl+U: Cut the part of the line before the cursor, adding it to the clipboard. Ctrl+Y: Paste the last thing you cut from the clipboard.


1 Answers

You can do this with Shell Integration! By default, iTerm2 is not fully integrated with the shell (e.g. Bash) itself. It doesn't really know which lines are prompt and which are output, so it wouldn't know what line to jump you back to as the previous prompt. If you install shell integration, it'll automatically add a mark at each prompt line and you'll be able to cycle up and down with Command-Shift-Up Arrow and Command-Shift-Down Arrow respectively. On my machine this worked even while a process was running.

In Preferences > Keys you can change the default keybindings back to what you're used to. Double click on Command-Up Arrow, change the Action to Select Menu Item..., and set the menu item to Edit > Marks and Annotations > Previous Mark/Annotation. Repeat with Next Mark/Annotation for Command-Down Arrow.

EDITED 2020-03-30: It appears Mark and Annotation were separated into different menu items in a recent update. You should now use Next Mark instead.

like image 199
Jordan Ticktin Avatar answered Oct 25 '22 03:10

Jordan Ticktin