I want to select some characters on a line, then be able to move them by one character forward/backward (i.e to the right/left) as many times as desired whilst retaining the selection as it moves.

Kind of like this:

enter image description here

Is there way already to do this that's built in ? Else, How could one implement this ?


Plugin MvVis offers such feature.

It works on principle:

  • Let @ be the position of cursor:
func()int a
      ^^^^^ (@ is at the last ^)
  • If you now press d (or x) whole selection will be cut and cursor moved one place to left*:
  • Now you can paste it before cursor with P:
func(int a)
  • So the keys will be: dP

* If the selection was followed by something, then you need to press h to move to the left

func()int a foo
      ^^^^^ (@ is at the last ^)

func() foo

func() foo

In such case: dhP

  • @Akharrou There it is, MvVis should do the trick Nov 24 '20 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.