2

I have VIM 8.2 with multi-byte support. I'm new to Vim and currently going through "Practical Vim" by Drew Neil. Tip 17 and Tip 18 talk about inserting special characters with character codes and by digraphs, so I decided to practice using this chart. However, I am having trouble having some of the characters to show up properly.

Here is a section of the chart that I decided to try.

^?  DT  0x7f    127 DELETE (DEL)
~@  PA  0x80    128 PADDING CHARACTER (PAD)
~A  HO  0x81    129 HIGH OCTET PRESET (HOP)
~B  BH  0x82    130 BREAK PERMITTED HERE (BPH)
~C  NH  0x83    131 NO BREAK HERE (NBH)
~D  IN  0x84    132 INDEX (IND)
~E  NL  0x85    133 NEXT LINE (NEL)
~F  SA  0x86    134 START OF SELECTED AREA (SSA)
~G  ES  0x87    135 END OF SELECTED AREA (ESA)
~H  HS  0x88    136 CHARACTER TABULATION SET (HTS)
~I  HJ  0x89    137 CHARACTER TABULATION WITH JUSTIFICATION (HTJ)
~J  VS  0x8a    138 LINE TABULATION SET (VTS)
~K  PD  0x8b    139 PARTIAL LINE FORWARD (PLD)
~L  PU  0x8c    140 PARTIAL LINE BACKWARD (PLU)
~M  RI  0x8d    141 REVERSE LINE FEED (RI)
~N  S2  0x8e    142 SINGLE-SHIFT TWO (SS2)
~O  S3  0x8f    143 SINGLE-SHIFT THREE (SS3)
~P  DC  0x90    144 DEVICE CONTROL STRING (DCS)
~Q  P1  0x91    145 PRIVATE USE ONE (PU1)
~R  P2  0x92    146 PRIVATE USE TWO (PU2)
~S  TS  0x93    147 SET TRANSMIT STATE (STS)
~T  CC  0x94    148 CANCEL CHARACTER (CCH)
~U  MW  0x95    149 MESSAGE WAITING (MW)
~V  SG  0x96    150 START OF GUARDED AREA (SPA)
~W  EG  0x97    151 END OF GUARDED AREA (EPA)
~X  SS  0x98    152 START OF STRING (SOS)
~Y  GC  0x99    153 SINGLE GRAPHIC CHARACTER INTRODUCER (SGCI)
~Z  SC  0x9a    154 SINGLE CHARACTER INTRODUCER (SCI)

If I press Ctrl-kDT, I get ^?, which is correct. The same thing happens if I press Ctrl-vx7f or Ctrl-v127.

However, if I go down the list, I run into problems. If I press Ctrl-kPA or Ctrl-vx80 or Ctrl-v128, I will get <80> instead of ~@

The same thing happens if I try to insert any of the other characters after ~@ such as ~A, ~B, etc.

Why can't I get these characters to show up properly with character codes or by digraphs?

Also, I have to use vanilla Vim with no .vimrc. When I load Vim with my custom .vimrc, the problem gets even worse, as either Ctrl-k or Ctrl-v appears to insert a Tab. When I type :map, none of the custom mappings appear to override these two key bindings. When I load vim with my .vimrc and type :verbose imap <C-k>, I get "No Mappings Found". Same thing with :verbose imap <C-v>.

Why does this happen if I use my own .vimrc?

EDIT

It turns out that I had previously had UltiSnips installed and had deleted the line installing it in my .vimrc, but I had forgotten to run :PlugClean to have vim-plug properly uninstall it. UltiSnips remaps Ctrl-k. When I uninstalled UltiSnips and sourced my .vimrc, the characters showed up properly with the character codes and with the digraphs.

Also, this chart is a much better representation of what gets printed out in vim although it still does not show that Ctrl-kPA will actually print out <80>

3
  • 1
    Random tip: don’t unconditionally set nocompatible. It’s usually already set when processing a vimrc. I didn’t see anything that would indicate a mapping on those keys, but you could try the tips in How to debug my vimrc. Lastly, I’m not super familiar with some of those keycodes, but they look like they do “strange things”—I’ve seen the <80> at various times, such as binary files not opened correctly, certain keystrokes in macros (eg the F-keys, other oddities).
    – D. Ben Knoble
    Sep 9 '20 at 13:34
  • 1
    Your link to the digraph chart has this at the end of section 2: "You may have problems using Vim with characters which have a value above 128."
    – DK Bose
    Sep 9 '20 at 14:04
  • 1
    You need to look up the keys in the :imap table though, since they're used in Insert mode. Try :verbose imap <C-v> and :verbose imap <C-k>
    – filbranden
    Sep 9 '20 at 14:38
2

This table does not reflect what vim intends to print. To see what actually will be displayed, use the command

:digraphs

You can see that some are of the form ^M and others are like <0d>. Additionally, you can toggle how vim displays control characters using

:set display+=uhex

for ^M type display, and

:set display-=uhex 

for <0d> type display. Even with uhex disabled, many control characters will still be displayed like <80>, among these are <c-k>PA.

2
  • 1
    In addition, I always use ga to check the actual value of the character under the cursor (which also includs combining characters) and is independent of the font used Sep 11 '20 at 6:17
  • This solved my problem, thank you. The only issue now is that when I type :digraphs, somehow the output will not show the characters that the digraphs correspond to. I can guess from the description what the character ought to be. And when I redirect the output to a file, the characters do show up properly. It must be something with my colorscheme or color settings.
    – rplee
    Sep 12 '20 at 19:44

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.