Skip to content

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

Closed

Description

@chdorner

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?

Activity

  1. ridiculousfish commented on Apr 15, 2013

    @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.

  2. padde commented on Sep 20, 2013

    @padde

    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
    
  3. jimtla commented on May 29, 2014

    @jimtla

    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.

  4. beloglazov commented on Jun 5, 2014

    @beloglazov

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

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

  5. michaeljones commented on Nov 29, 2015

    @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.

  6. krader1961 commented on Nov 29, 2015

    @krader1961
    Contributor

    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.

  7. krader1961 commented on Nov 30, 2015

    @krader1961
    Contributor

    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.

  8. michaeljones commented on Nov 30, 2015

    @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!

  9. faho commented on Nov 30, 2015

    @faho
    Member

    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.

  10. modified the milestones: , fish-future on Dec 15, 2015
  11. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions