You could use the following solution:
First use v$ to select the text from the cursor to the end of the line. Then use the following command:
:s/\%V\ /_/g
The \%V
indicate to change the text in the previously visually selected area, see :h /\%V
.
If I take your example:
function my_function(argument, another argument, but there are spaces)
If my cursor is on the 40th column and I use the command I just wrote I get:
function my_function(argument, another argument,_but_there_are_spaces)
In answer to your comment you can also use
\%#
which matches from the cursor position
\%>23c
which matches after the 23rd column.
\%>'m
which matches after the position of a mark
See :h /\%#
, :h /\%>c
and :h /\%>'m
.
@User9433424 gave a way to use \%#
in his comment. For the pattern with the mark you can set it wit ma and then use:
:s/\%>'a /_/g
An explanation of the pattern given by @User9433424 is the following:
:s/\v(%#.*)@<= /_/
:s/ substitution command
\v Enable the very magic mode
%#.* Any characters from the cursor position
@<= Check for matches just before what follows
space Followed by a space
/_/ Substitute the matches by underscores
You'll want to see :h \v
and :h /\@<=
\%#
. So, you could use::s/\v(%#.*)@<= /_/g
. Which could be described as a space preceded by (@<=
) characters after the cursor position.\%#
trick, I'll accept his answer if you don't write one... But could either of you explain the regexp with a bit more explicitly ?