7

I want to press M-j and have readline place my cursor on the next line without entering a command. Thus I should be able to go back a character onto the prev. line. This answer states that it cannot be done. I think it's wrong.

You can kill the newline character, and yank it. This achieves what I want to do. However I just can't create the binding.

To test this out type: echo <<EOFRETURNENTERC-cC-pM-1C-dC-c

Now you should be on a newline, type C-y. It does what I want! But what character is this? What binding works in an inputrc file?

EDIT: It turns out the character is a line-feed. Still not sure how to bind it.

  • 1
    You can type a newline as C-v C-j, which is mostly useful for breaking lines up while line editing. The linked question is referring to up and down cursor motions in a multi-line line edit. I'm not sure that either of those are what you want to do. – rici Mar 30 '15 at 4:11
  • I added some to clarify, I want to be on the next line and able to go back. – cdosborn Mar 30 '15 at 4:21
  • 1
    On my system, @rici's shortcuts seem to achieve what you're asking for. What happens on yours? – Dennis Mar 30 '15 at 5:28
  • That is the correct behavior, The following binding works "\ej": "\C-v\C-j" based on how my terminal interprets meta. Please post an answer for me to accept @rici – cdosborn Mar 30 '15 at 6:24
11

You can type a newline character without having the line accepted by using readline's "quoted-insert", usually bound to C-v, followed by the newline character C-j.

"quoted-insert" is also useful for typing a tab character without invoking tab completion (C-vC-i).

  • Wow this is really useful, anyway to make this automatic when I use `\` to escape the newline when creating a multiline command? – CMCDragonkai Apr 6 '16 at 11:09
  • @cmcdragonkai: not that I know of but you could bind some key sequence to \\\C-j. – rici Apr 6 '16 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.