I have this column in a file I’m editing in VIM:
16128
16132
16136
16140
# etc...
And I want to convert it to this column:
0x3f00
0x3f04
0x3f08
0x3f0c
# etc...
How can I do this in VIM?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
printf(analogous to C’ssprintf) with the\=command to handle the replacement:Details:
:%s/\d\+/: Match one or more digits (\d\+) on any line (:%) and substitute (s).\=: for each match, replace with the result of the following expression:printf("0x%04x",: produce a string using the format"0x%04x", which corresponds to a literal0xfollowed by a four digit (or more) hex number, padded with zeros.submatch(0): The result of the complete match (i.e. the number).For more information, see: