The reason that this isn't working for you is that forward slash /
(ASCII 47), isn't included in your 'iskeyword'
setting, which in Vim defaults to @,48-57,_,192-255
.1
You could fix it by adding the forward slash to your 'iskeyword'
setting but I wouldn't recommend doing this:
:setlocal iskeyword+=/
The 'iskeyword'
setting is used in many places in Vim, and there's a fairly decent chance that by adding forward slash to it you will break things. e.g. Do you like being able to step through the components of a path with the w
motion?
Slightly quicker than setting the search register with a :let
command is just searching:
/\/\/
If you find the construction of regular expressions to be slow, you could also take advantage of the method the *
uses for selecting what to search for:
- the keyword under the cursor |'iskeyword'|
- the first keyword after the cursor, in the current line
- the non-blank word under the cursor
- [...]
In order that steps 1 & 2 don't find anything, construct a line which contains no keywords, search for it, and then remove it again, by typing:
o//<Esc>*u
You can then carry on with your cgn
replacements.
For more details on the 'iskeyword'
setting, see :help 'iskeyword'
and :help 'isfname'
(the latter just for the description of the format of the former), and for more details of how *
works see :help *
.
1: Except on Windows, where it's slightly different: @,48-57,_,128-167,224-235