I am reading the book "learning vi editor"(linda lamb & arnold robbins 6th edition). Page 115, the book has a command like this:

:map ^J xyz

The xyz part itself doesn't matter here, my problem is to make the ^J part.

I have tried ctrl+V ctrl+j (ctrl+v can be used to escape Enter for example) and ctrl+j directly

In both cases it doesn't work.

I am using vi editor inside FreeBSD 11.0, it isn't the vim (vi improved) .

----- Edit -----



00:05 - map ctrl+K to do dd (delete entire line)

00:19 - try to do the same thing with ctrl+J, but it doesn't work because ctrl+J trigger a table.

00:25 - try again with ctrl+V ctrl+J. Also it doesn't work, triggering a table.

00:33 - try map exactly "^J"

00:44 - try with ctrl+J and it doesn't work as expected. It works typing the sequence "^J".

  • 1
    Hm. I would expect it to be ctrl+v ctrl+j. Have you tried caret j exactly how it looks? – zondo Apr 8 '17 at 15:01
  • Hi, zondo. I have edited the post inserting a video which include your suggestion. – user2865249 Apr 8 '17 at 18:48

That actually appears to be an error in the book. The example is followed by this comment:

In the previous example, even though ^J is a vi command (it moves the cursor down a line), this key is safe to map because it's really the same as the j command. There are many keys that either perform the same tsks as other keys or that are rarely used. However, you should be familiar with the vi commands before you boldly disable their normal use by using them in map definitions.

The usual inference for ^J is controlJ. But none of the vi's mentioned in the 6th Edition allowed one to insert a literal control/J in the text because that is the line-ending for Unix-like systems (vim will give you a ^@ null character when attempting to escape control/J, the other editors ignore that). A literal "^J" does not work with the comment, because those characters are not a vi command.

You can make the literal "^J" work, of course. But that was not the point of the example. Likely the author intended some other interesting character and changed it for whatever reason.

| improve this answer | |

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.