PhpStorm zsh terminal CTRL+(leftArrowKey or rightArrowKey) not working - terminal

On phpstorm terminal window (with zsh shell) when I do a CTRL+(leftArrowKey or rightArrowKey) what is happening is this:
Navigation behavior error
Searched the problem in other terminal emulators and found this solution:
Searched solution -> Looking for ALT+LeftArrowKey solution in zsh
So I've done what user lolesque said to do:
Tried lolesque solution
and added to my ~/.zshrc file these lines:
bindkey -e
bindkey "^[[5C" forward-word
bindkey "^[[5D" backward-word
The problem is that the solution found does not work :|.
Any help will be appreciated.

It's a bug, currently these bindings are only supported for Bash.
Please vote here: https://youtrack.jetbrains.com/issue/IDEA-180154

Add this to ~/.zshrc:
bindkey "\e\eOD" backward-word
bindkey "\e\eOC" forward-word
Don't forget to restart the terminal or to
source ~/.zshrc
for applying the changes.
Source: https://gist.github.com/ecksite/e341835ef266e67b63a2620aee692fdd

Related

Why goland's terminal is not using configuration in .zshrc

I'm using goland's terminal to run commands. I noticed that it doesn't apply my configuration in ~/.zshrc. For example, I have couple lines to configure shortcuts in my ~/.zshrc
bindkey "^[backward-word" backward-word
bindkey "^[forward-word" forward-word
bindkey "^[line-begin" beginning-of-line
bindkey "^[line-end" end-of-line
bindkey "^[undo" undo
bindkey "^[del-prev-word" backward-delete-word
bindkey "^[u" backward-kill-line
And when I open iterm, this configs are applied. But when I'm using the terminal in goland, it doesn't follow these rules. I'm wondering how can I config the shortcuts in goland's terminal too.

Command-arrow for back and forward one word in PhpStorm terminal

I'm on OSX, and for some reason, when I do command - ← (back arrow) in the PhpStorm terminal I get a [D, while command - → (forward arrow) outputs a [C. What I want to do is jump forward and back one word.
In my OSX terminal these keypresses work as expected, and I can't find anywhere where they are set to output those characters. Does anyone have the answer to this conundrum?
Turns out that an answer for the same problem on iTerm also works for PhpStorm! The fix involves creating a new file named ~/.inputrc and then put the following code in it:
"\e\e[D": backward-word
"\e\e[C": forward-word
Here is the original link
If you are using zsh, add this to ~/.zshrc:
bindkey "\e\eOD" backward-word
bindkey "\e\eOC" forward-word

zsh shortcut 'ctrl + A' not working

I recently switch from bash to zsh shell. To be more precise, the oh-my-zsh
Very nice, but the shortcut I most often use; jumping to the beginning/end of the line doesn't work anymore. From the docs it should be
ctrl + A --> beginning
ctrl + E --> end
However, when I do that I get the following
$~> my-command
$~> my-command^A # did a ctrl + A here
Although I see this working by everybody else, on my system something seems to be different. Any suggestions what that might be ?
If you're wondering why this happened: You likely have $EDITOR or $VISUAL set to vi/vim which made zsh default to the vi keymap which doesn't use ctrl+a for moving the caret.
Adding bindkey -e to ~/.zshrc will restore the old behavior (emacs keymap).
you don't have to config the Ctrl+A behavior if you use default keymap (emacs keymap). It does what you are expecting.
However if you set your zle to use vi keymap, you have to define the keybind for vi-beginning-of-line. same for Ctrl+E.
So check which keymap did you set in config. If it was vi, try pressing ESC then ^ and $ should do what you want.
zsh .zshrc
bindkey "^A" vi-beginning-of-line

How to make byobu forward-word and backward-word with CTRL+arrow?

When used in uxterm zsh is jumping words when I press ctrl+left and ctrl+right.
When used in plain unconfigured byobu (tmux backend) it is not. The cursor sits there doing nothing.
I can however achieve that by using alt+b and alt+f, but I'd really like to use ctrl+arrow in keeping with general system-wide ergonomics.
Create ~/.byobu/.tmux.conf with this value:
set-window-option -g xterm-keys on
Then add the following to ~/.byobu/keybindings.tmux
unbind-key -n C-Left
unbind-key -n C-Right
OK, I found a workaround :
bindkey '^[[1;5D' backward-word
bindkey '^[[1;5C' forward-word
in ~/.zshrc
To find out the arcane key code I had to cat -v and enter them. Gosh my productivity went up 15%.
The patch here correct the problem for me on Ubuntu 12.04
https://code.launchpad.net/~jake-biesinger/byobu/byobu/+merge/126830

Looking for ALT+LeftArrowKey solution in zsh

I just recently switched from bash to zsh, however I miss my Alt+LeftArrowKey and Alt+RightArrowKey to go back and forth a word at a time.
Right now, if I press Alt+LeftArrowKey I go back a couple of letters and then I'm stuck. I won't go any further backwards and it won't back to the end of the line with Alt+RightArrowKey as I would expect. I can't even use the arrow keys to go to the end of the line, only to the second to last. Can't input new chars on the line either or indeed delete.
How do I get my beloved shortcut back?
I'm on Mac OS X using Terminal if that's important.
Run cat then press keys to see the codes your shortcut send.
(Press Ctrl+C to kill the cat when you're done.)
For me, (ubuntu, konsole, xterm) pressing Alt+← sends ^[[1;3D, so i would put in my .zshrc
bindkey "^[[1;3C" forward-word
bindkey "^[[1;3D" backward-word
(Actually I prefer to use Ctrl + arrow to move word by word, like in a normal textbox under windows or linux gui.)
Related question: Fix key settings (Home/End/Insert/Delete) in .zshrc when running Zsh in Terminator Terminal Emulator
For anyone using iTerm, regardless of shell
All of the solutions offered here take a backwards approach in my opinion. You're essentially telling your shell to listen for some esc sequence or other key binding you have set in your terminal, creating compatibility issues when you switch shells (If you SSH into some other shell, switch from BASH to ZSH, etc and you lose some if not all of your keybindings).
Most shells have a set of default sequences that come pre-bound. Furthermore, while they aren't 100% consistent, they're close enough. So the easiest way that I have found to create keybinding for a particular action in the shell is to tell your terminal application to bind to the default keybindings that are consistent across shells.
I wrote a compressive solution for getting your terminal to respond as close to native mac keybindings here
Open the iTerm preferences ⌘+, and navigate to the Profiles tab (the Keys tab can be used, but adding keybinding to your profile allows you to save your profile and sync it to multiple computers) and keys sub-tab and enter the following:
Move cursor one word left
⌥+← Send Hex Codes: 0x1b 0x62
Move cursor one word right
⌥+→ Send Hex Codes: 0x1b 0x66
And that should give you the desired behavior not just in ZSH, but also if you SSH into a server running BASH, irb/pry, node etc.
Adding the following to ~/.zshrc worked for me on OSX Mountain Lion.
bindkey -e
bindkey '[C' forward-word
bindkey '[D' backward-word
On MacOS High Siera 10.13.6 or Mojave 10.14.2 and using iTerm2 with ZSH
To move from words I have to put like this:
bindkey "\e\e[D" backward-word
bindkey "\e\e[C" forward-word
Another solutions doesn't work fo rme
For iTerm, go to where this screenshot shows and select "Natural Text Editing"
if you already had some key mappings it will ask below, select accordingly not to lose any special bindings you set before. however, if you don't remember adding any bindings or just started using iTerm (on this machine), you will be safe to choose "Remove"
Though not strictly answering your question, the default binding for forward-word and backward-word are alt-f resp. alt-b.
This works everywhere, does not require you to leave the home row, and has a nice mnemonic property (f=forward, b=back), while also being consistent with ctrl-f and ctrl-b being forward-character and backward-character.
Rip out your arrow keys!
To make it work for me I used this answer, however I had to swap the codes (left <-> right)
⌥+← Send Hex Codes: 0x1b 0x66
⌥+→ Send Hex Codes: 0x1b 0x62
and add the following to my ~/.zshrc
bindkey -e
bindkey "^[b" backward-word
bindkey '^[f' forward-word
On MacOS Monterey, use the following in ~/.zshrc to make SHIFT + Arrows jump words:
bindkey "^[[1;2C" forward-word
bindkey "^[[1;2D" backward-word
And this for Option + Arrows:
bindkey "^[^[[C" forward-word
bindkey "^[^[[D" backward-word
On Mavericks (10.9.4) the code is 1;5... so for binding alt with arrows I have my .zshrc using this:
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
You can use CTRL+V and then the command you want to use
in Yosemite use Rob's solution
In zsh, you can use the bindkey command to see keyboard shortcuts.
Use bindkey to explore options that are available without custom keybindings.
Namely ^[b to move backward a word and ^[f to move forward a word.
These keybindings work with Alacritty on Arch Linux, just add them to the ~/.zshrc file
bindkey -e
bindkey "^[[3~" delete-char # Key Del
bindkey "^[[5~" beginning-of-buffer-or-history # Key Page Up
bindkey "^[[6~" end-of-buffer-or-history # Key Page Down
bindkey "^[[H" beginning-of-line # Key Home
bindkey "^[[F" end-of-line # Key End
bindkey "^[[1;3C" forward-word # Key Alt + Right
bindkey "^[[1;3D" backward-word # Key Alt + Left
If you're using iTerm in CSI u mode, the bindings for your .zshrc end up being:
bindkey '^[[1;3D' backward-word
bindkey '^[[1;3C' forward-word
If you want iTerminal to respect Emacs style shortcuts like ^Mf and ^Mb for forward/back a word I found best way to use this tip:
Making iTerm to translate 'meta-key' in the same way as in other OSes

Resources