brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ga in Vim shows the code of the character under the cursor

Vim
~/tips/tip-vim-ga-char-code

ga

Identifies odd characters by their decimal, hex and octal code.

A character that looks like a space but isn’t one, or a quote that breaks a script: ga is how I’d find out exactly what it is.

ga

Put the cursor on the character and press ga. Vim shows its value at the bottom of the screen, for example:

<é> 233, Hex 00e9, Oct 351, Digr e'

That is the decimal value, the hex code point and octal. The Digr e' part says you can type it with the digraph Ctrl-k e ' in insert mode. A non breaking space shows up as 160, Hex 00a0, which explains a lot of mysterious errors in pasted config.

g8 shows the bytes instead, as they are stored in UTF-8:

c3 a9

That is useful when another program complains about a byte value rather than a character.

To find these characters in the first place, search for anything outside plain ASCII with /[^\x00-\x7F]. Then ga on each match tells you what it is, and r followed by a space replaces it.

The numbers depend on the file being read with the right encoding. If :set fileencoding? doesn’t match the file, Vim may show you two Latin-1 characters where there is one UTF-8 character.

Further reading: Vim help: ga, Vim help: g8

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Vim tips :%s/<Ctrl-r><Ctrl-w>/newname/g /oldname find . -name "*.conf" | vim – vim --clean file.txt :set textwidth=72 All Vim tips (45) All topics

Link