Today I Learned

hashrocket A Hashrocket project

End of Line Substitutions in Vim

Today I learned a couple of nice regexes for substitutions in (n)vim.

Say you have a list, and you want to replace the character at the end of each line with something else:

123@
456@
789!

To replace the @s and ! with commas (,), you can use this substitute command :%s/.$/,/

123,
456,
789,

The regex .$ matches the character (.) that's at the end of the line ($)

Additionally, if you want to add something to the end of each line (but not replace), you can use the substitution :%s/$/,/ to transform

123
456
789

into

123,
456,
789,
See More #vim TILs
Every developer at Hashrocket is a Vim expert. Check out our development environment, Dotmatrix, and if you are in Chicago, come to the Vim Chicago Meetup hosted at our Chicago office.