Search code examples
intellij-ideazshzsh-zle

How to have special/accented characters support in IntelliJ terminal


I use the IntelliJ IDEA's Embedded Local Terminal quite a lot, but there is one thing that is driving me nuts : special and accented characters do not work. This is what should but is not working :

  • HOME key to go to the beginning of the line : does nothing
  • END key to go to the end of the line : does nothing
  • [CTRL + left arrow] to go to previous word : prints D
  • [CTRL + right arrow] to go to next word : prints C
  • all accented characters : prints nothing at first, then ? when I hit another key

There are probably other combinations that should but do not work ... but these are the most annoying ones.

I'm using :

  • Ubuntu 16.04 virtual box guest running on a Windows 10 host
  • IntelliJ IDEA 2016.2.4
  • zsh
  • oh-my-zsh

Important notes :

  • in a GNU Terminal (outside of IntelliJ then) everything works perfectly, so I don't think that the "running inside a VM" thing is the source of the problem.
  • if I run bash instead of zsh the special characters are working (home, end, next work, etc...) but I still don't have propre support of accented characters (prints ), and I'd really prefer using zsh.
  • showkey --scancodes prints Couldn't get a file descriptor referring to the console
  • if I start od -c I get ^[[H for the HOME key and ^[[F for the END key
  • showkey --ascii works and prints ^[[H too for the HOME key

What I did already :

  • checked that the TERM variable is not overridden in .zshrc
  • add bindkey "${terminfo[khome]}" beginning-of-line and end of line equivalent in .zshrc
  • add lines (that seemd appropriate) in .inputrc for readline (OK I see now that this was useless as Zsh does not use readline)

edit : I could make the home/end keys work (see accepted answer below), but not the CTRL+LEFT and CTRL+RIGHT key (for forward-word and backward-word). After some more digging this seems to be an issue with IntelliJ not 100% properly emulating the terminal. 4

There is an issue here, with interesting input from an oh-my-zsh contributor : https://youtrack.jetbrains.com/issue/IDEA-118848#comment=27-1292473

They consider ditching smkx (which appears to be the root of the problem) from oh-my-zsh soon. I've checked out this PR and now my keys work fine (still need the bindings, but CTRL+LEFT and CTRL+RIGHT are ok now)


edit: accented/special characters are now properly supported in IntelliJ (yeehaa !), be sure to have at least the following version : IntelliJ IDEA 2016.3.1, Build #IC-163.9166.29, built on December 9, 2016


Solution

  • I can appreciate that zsh works fine outside IntelliJ.

    Step 1

    Find the correct key codes being used by the terminal inside Intellij. This will depend on the OS you are using. For OSX and Linux od -c followed by pressing the keys will result in the key code being emitted.

    Step 2

    Once you have the keycodes, modify your ~/.zshrc :

    bindkey "$HOME_KEY_CODE_FROM_STEP_1" beginning-of-line
    bindkey "$END_KEY_CODE_FROM_STEP_1" end-of-line
    

    for example (as was the case for the OP):

    bindkey "^[[H" beginning-of-line
    bindkey "^[[F" end-of-line
    

    and restart the terminal.