Category Archives: vim

vim tips

Vim get the current cursor char ascii code and replace it

In command mode press the keys ga (like get ascii) or :as / :ascii on the command line to find out the ascii code of the character where the cursor is. This displays the value of the current character in decimal, hex and octal. (Think “get ascii.”)

To do a search and replace with an hex code

:%s/\%x0d.*$//d

Being 0d the ascii character found with ga

Seeing ASCII/Unicode values in the status line

You can also add options to the statusline option to show the ASCII/Unicode value of the character under the cursor.

:set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P

It’s the %b\ 0x%B that does the trick. Note that you may need to :set laststatus=2 so that the status line is visible in with only one window showing.

See also at http://vim.wikia.com/