(Re)-binding \cj breaks enter key #217

Closed
chdorner opened this Issue Jul 9, 2012 · 10 comments

Projects

None yet

10 participants

@chdorner
chdorner commented Jul 9, 2012

I wanted to have vim key mappings instead of the arrows with the following commands:

bind \ch 'backward-char'
bind \cl 'forward-char'
bind \ck 'up-or-search'
bind \cj 'down-or-search'

Which seems to work great, except that because of re-binding of the \cj key combination, the enter key stopped working.

Is that intended behavior or a bug?

@ridiculousfish
Member

ctrl+j is line feed, so it inserts the same thing as return. So when you bind to ctrl-j, you bind to return as well. This may be unfixable.

@padde
padde commented Sep 20, 2013

I stumbled upon this one too. As Vim user I hate to take the trip to the arrow keys ;-) I wonder how ZSH does it, because it works there. With the following mapping, ZSH somehow still manages to distinguish between ctrl+J and .

bindkey "^J" history-search-forward
@jimtla
jimtla commented May 29, 2014

As a workaround for this issue I used iterm2 to send the escape squence [18~ on \cj, and then added bind -k f7 down-or-search to my fish_user_keybindings. I'm sure you can do something similar in any other terminal emulator.

@beloglazov

@jimtla I couldn't make this work with urxvt.

Vim also manages to distiguish <C-j> and <CR>, so it should be possible.

@michaeljones

+1, I've experienced the same situation coming to fish with a history of vim. I like home row key bindings and it has been possible one way or another in zsh & tcsh. I can see there is a clear argument for them being indistinguishable but if it is possible in any standard way then it just makes things more flexible, I think.

@krader1961
Member

The reason \cJ seems to insert the same thing as [enter] is because the tty is in cooked mode with icrnl enabled -- that causes the tty driver to map carriage-return (aka \cM and [enter]) to newline (aka \cJ). See http://stackoverflow.com/questions/14615717/how-can-vim-tell-the-difference-between-ctrl-j-and-lf

I vote that fish disable icrnl mode so that \cJ can be rebound.

@krader1961
Member

P.S., I'm working on a change to implement this (i.e., separate \cJ from \cM) on UNIX. TBD is what, if anything, needs to change for MS Windows.

@michaeljones

Thanks for the update! You've helped me realise that that is what I'm seeing as well. I think it has been sufficient for me on other shells to distinguish between \cJ and \cM which means being able to distinguish between Enter and \cJ as well as they don't represent the same input.

I saw that stackoverflow question too but unfortunately I am not wise in the lingo of terminal programming. I would welcome any help on this and would be happy to try to test something if you have a fork I could look at. Thanks again!

@faho
Member
faho commented Nov 30, 2015

I vote that fish disable icrnl mode so that \cJ can be rebound.

@krader1961: Doesn't that just move the problem to \cm? At least that's how I understood the SO answer.

Of course \cj is probably slightly more usual, what with vi-bindings and all, but it's not a real solution.

@krader1961 krader1961 added a commit to krader1961/fish-shell that referenced this issue Nov 30, 2015
@krader1961 krader1961 allow \cJ (\n) to be bound separate from \cM (\r)
This makes it possible (on UNIX systems, don't know about MS Windows)
to bind \cJ (\n) independently of \cM (\r, aka [enter]).

Resolves #217
7ff8632
@ridiculousfish ridiculousfish added a commit that closed this issue Dec 9, 2015
@krader1961 @ridiculousfish krader1961 + ridiculousfish allow \cJ (\n) to be bound separate from \cM (\r)
This makes it possible (on UNIX systems, don't know about MS Windows)
to bind \cJ (\n) independently of \cM (\r, aka [enter]).

Resolves #217
d65c633
@zanchey zanchey modified the milestone: next-2.x, fish-future Dec 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment