Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vs-code: unable to reverse search on built-in terminal

When I do ^R on the terminal to reverse search, I get the following:

(^R) was pressed. Waiting for second key of chord...

How do I fix this? I'm on OS X.

like image 449
nz_21 Avatar asked Dec 11 '22 00:12

nz_21


2 Answers

Also see Run recent command as a replacement for reverse search from the v1.70 Release Notes:

When shell integration is enabled, we're aiming run recent command to be a cross-shell drop in replacement for the shell's reverse search (kbstyle(Ctrl+R)). There is a new contiguous search mode that is the default when triggering the command. This behaves like kbstyle(Ctrl+R) in most shells, with the option of switching back to fuzzy search:

terminal run recent search

The new inTerminalRunCommandPicker context key is available that allows setting up a keybinding like kbStyle(Ctrl+R) to go to the next match. For example, the following keybindings are now a fairly complete replacement for your shell's reverse search, with kbstyle(Ctrl+Alt+R) as a fallback to the old behavior:

{ "key": "ctrl+r",     "command": "workbench.action.terminal.runRecentCommand", "when": "terminalFocus" },
{ "key": "ctrl+alt+r", "command": "workbench.action.terminal.sendSequence", "args": { "text": "\u0012"/*^R*/ }, "when": "terminalFocus" },
{ "key": "ctrl+r",     "command": "workbench.action.quickOpenNavigateNextInViewPicker", "when": "inQuickOpen && inTerminalRunCommandPicker" },
{ "key": "ctrl+c",     "command": "workbench.action.closeQuickOpen", "when": "inQuickOpen && inTerminalRunCommandPicker" },

Perhaps you actually want both! Terminal keybindings that are of the form

Ctrl+R Ctrl+something else

that is, keybindings that are chords AND still use

Ctrl+R (a non-chord keybinding) to trigger a reverse search in the terminal.

You can have both - add this keybinding to your keybindings.json:

  {
    "key": "ctrl+r",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u0012" },
    "when": "terminalFocus"
  },

That sends a "Ctrl+R" to the terminal and thus starts a reverse search. Even if you have other terminal keychords that starts with Ctrl+R, the terminal will not wait for the second part of a keybinding.

Note if you have a frequently used search you can add text to the command like:

    "args": { "text": "\u0012node" },

where it will already have started the search for commands with node in them.

like image 129
Mark Avatar answered Dec 22 '22 01:12

Mark


I realized that this started happening with me after I installed "Visual Studio Keymap" extension.

That is how I solved:

Ctrl + Shift + P for the command. There write: "Settings JSON" and select the option that says "Preferences: Open Settings (JSON)"

There, write the following setting:

"terminal.integrated.allowChords": false

Save and be happy

like image 30
Francisco Cardoso Avatar answered Dec 22 '22 01:12

Francisco Cardoso