vimtagsvscodevimsurround

How do i use vim surround from the middle of a word to the end of a line?


printemployee.fullname(emp_1)

I want to use vs code vim-surround to give me this result:

print(emloyee.fullname(emp_1)

I've tried yss from the cursor on e but that wraps the whole line.

I've tried ysw from the cursor on e but that only wraps ( employee ).

I've tried ysiw from the cursor on e but that wraps ( printemployee ).


Solution

  • If you only want to insert a ( before the cursor, as per your example, then Surround is useless.

    If the missing ) is a typo (which is likely given the missing p in employee) and you actually want:

    print(employee.fullname(emp_1))
    

    then you should do:

    ys$)
    

    which literally reads as "surround the text from here to the end of the line with parentheses".

    Note that this is not specific to Surround. ys is an operator provided by Surround that operates on the text covered by the motion you give it, like the native y or d.

    The motion you want is right there in the title of your question: "to the end of the line", so there is no point using random motions with vastly different semantics. Neither of the following motion could be expected to fit the bill:

    so using them is pointless.

    And yss rather explicitly covers the entire line, which makes it useless.

    The right motion, here, is $, for "to the end of the line".