Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VIM to make acronyms?

Tags:

vim

I have a file with lot of full names like ....

Light Machine Gun
Statistical Analysis System
etc

I want to capture the first character of every word in a line and want to make an acronym. For example Light Machine Gun would be LMG etc. I want to do it in VI editor record it as a macro and run it over the entire file.If anyone can help me that would be great? Thanks in advance.

like image 921
PKumar Avatar asked Dec 03 '25 17:12

PKumar


1 Answers

Assuming one name per line and that the words are space separated, the following works:

%s/\(\w\)\w*\ */\1/g

If you also want to capitalize each letter, add an up-case flag (\u):

%s/\(\w\)\w* */\u\1/g

The "very magic" version (see :help /magic):

%s/\v(\w)\w*\s*/\u\1/g
like image 151
Thor Avatar answered Dec 06 '25 11:12

Thor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!