Q:

How to replace char in file with appropriate ascii code in vim

In a vim buffer if I have a list of characters say:
A
B
c
C
d
D
and for each one I want to replace it with its corresponding ascii code ( in decimal ).  Is there a way to do this without using an external tool through :r!some_tool
For instance, I know there is the :ascii and ga commands but they print the value to the screen but I can't find a way to get its output into the buffer.

A:

You can take advantage of the sub-replace-expression functionality along with char2nr() and submatch().  The following replaces any alphabetic character at the start of the line with its decimal equivalent.
%s/^\a/\=char2nr(submatch(0))/

If you want to do this for any character at the start of the line, simply replace the \a with ..

