0

I'm just learning how to use the vi editor, and was trying to make use of the following map command in my .exrc file:

map K 0I^I^[j0O^I^[j0

That is what appeared when I created the map in ex mode and typing it in manually gave me those escape codes. I wanted to:

  • go to the start of the line
  • Insert-mode
  • press Tab (^I)
  • Esc
  • go down one line
  • go to the start of the line (unnecessary I guess)
  • open a new line below
  • Tab again
  • Esc
  • go down one line and
  • go to the start of that line

But it doesn't work! It does the 0 and the I, but then inserts the remaining map keys as if in insert mode ^I^[j0O^I^[j0. Please tell me, someone, why it doesn't work? What am I doing wrong?

Follow-up: I double-checked what I did. If I type in the keystrokes in a :map command while in ex, whether I escape the Tab with Ctrl-v or not, it prints just a plain, single "^I" for each Tab. So when I keyed in the same thing WHILE EDITING MY .exrc FILE, when I make sure I type Ctrl-v Tab, IN THERE, it displays a bunch of whitespace for each Tab, untranslated into an escape code! And when I go back to vi and try it out, NOW it works. Perhaps it's because "in vi", where I was really using ex (since I was typing in ":map"), I was really IN EX, but since the map commands in the .exrc file don't need the initial colon before "map", I was starting the entry without a colon, and I was really using vi, not ex! Maybe that was what caused the disparity?

2

1 Answer 1

0

I suspect you don't enter the escape code correctly.

To enter the escape code ^[ I propose you to type: Ctrlv Esc.

The same for inserting the escape code ^I for Tab by typing: Ctrlv Tab.

5
  • Actually I DID use Ctrl-v Esc....for both Escapes. And both Tabs. But I noticed that even if I pressed just Tab, it would show up in purple as ^I in ex..... Jul 15, 2022 at 20:29
  • Do you have the odd insertions for both tab and esc or only for tab? Jul 15, 2022 at 20:59
  • Well, thank you, Vivian, I double-checked what I did. If I type in the keystrokes in a :map command WHILE IN VI, whether I escape the Tab with Ctrl-v or not, it prints just a plain, single "^I" for each Tab. So when I keyed in the same thing WHILE EDITING MY .exrc FILE, when I make sure I type Ctrl-v Tab, IN THERE, it displays a bunch of whitespace which is clearly the Tab, untranslated into an escape code! And when I go back to vi and try it out, NOW it works. This seems like very odd behavior. Recording the keys behaves differently based on where I key it in!! Jul 15, 2022 at 21:16
  • Perhaps it's because "in vi", where I was really using ex (since I was typing in ":map"), I was really IN EX, but since the map commands in the .exrc file don't need the initial colon before "map", I was starting the entry without a colon, and I was really using vi, not ex! Maybe? Jul 15, 2022 at 21:24
  • 1
    @user1013210 Please incorporate your findings from the comments into the question itself. You can edit your question to add those details. It’s easier for someone trying to address your issue if they can find the whole context in a single place. Thanks!
    – filbranden
    Jul 16, 2022 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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