I am a regex supernoob (just reading my first articles about them), and at the same time working towards stronger use of vim. I would like to use a regex to search for all inst
you probably want to use :[^ ]
to mach everything except spaces. As mentioned by Matt this will cause your replace to replace the extra character.
There are several ways to avoid this, here are 2 that I find useful.
1) Surround the last part of the search term with parenthesis \(\)
, this allows you to reference that part of the search in your replace term with a /1
.
Your final replace string should look like this:
%s/:\([^ ]\)/: \1/g
2) end the search term early with \ze
This will means that the entire search term must be met for a match, but only the part before \ze
will be higlighted / or replaced
Your final replace string should look like this:
%s/:\ze[^ ]/: /g