Replace the string matching a specific regular expression with a length in Vim

In Vim, how to replace a string corresponding to a certain regular expression with its length, for example:

Regexp = "\ w *"

hello β†’ 5
"bye" β†’ "3"

Can this be done with: s or do I need to write some script?

Best wishes

+6
source share
1 answer

Replace 'hello' with a regex expression expression, and this should work in VIM:

:s/hello/\=strlen(submatch(0))/ 
+12
source

Source: https://habr.com/ru/post/885398/


All Articles