2

I want to remove the ending section of my output that typically follows the below pattern:

^[[2D[^[D but my regex will not allow me to select the ^[ parts of the word. Note on my Vim that part shows in a different color almost like it is a a digraph or special character.

Any thoughts on how I can create a mapping to remove this from my outputs?

Note when I copied the output to my clipboard and pasted into my browser it translated the ^[ to ``

I am writing to you today as an email full of typos. Ye^[[2D[^[K
Yes, you heard that right – I'm a bit of a typo-ridden mess. But don't worry, I've got fa^[[2D^[[K

2 Answers 2

8

The special character ^[ is actually Esc.

If you want to include it in a regex you can type it using the following key sequence:

Ctrl vEsc

In general in presence of a special character you can discover its code using the ga command. Move the cursor on the character and hit ga.

The output gives you:

  • The decimal code (27 in case of Esc)
  • The hexadecimal code (1b in case of Esc)
  • The digraph if any (EC in case of Esc)

You can use that information to reinsert the same character in insert mode:

  • Ctrl v027
  • Ctrl vx1b
  • Ctrl kEC
1
  • 5
    Teach 'em to fish: you might mention ga
    – D. Ben Knoble
    Oct 2 at 14:37
3

Alternatively, you can just copy the offending text (yank into a register) and paste it into your replacement expression without knowing (or caring) what the special characters are.

:%s/CTRL-R0//g

See :help c_CTRL-R for details.

Your Answer

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

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