0

In my current flow, I find that moving words is made slower by having to insert a whitespace, so I was wondering if there is a more efficient way

Here are two use cases:

  1. how do I efficiently move a word at the end of a sentence, eg transform from the first line below to the second line , assuming, say, that the cursor is on 'A':

    function Arg3 arg1 arg2

    function arg1 arg2 Arg3

Currently I delete the word dw, move to the end with A, insert a space then do <C-o>p, and press backspace to delete the unwanted additional space, and then finally <ESC>

  1. how do I efficiently swap 2 words at in a sentence, eg transform from the first line below to the second line , assuming, say, that the cursor is on 'A':

    function Arg2 arg1 arg3

    function arg1 Arg2 arg3

Currently I delete the word dw, move to the end with e, do a<C-o>p then <ESC>

I was wondering if there is a more efficient way of (1) moving a word at the end of a sentence and (2) swapping 2 words in a sentence, as what I do now seems a bit messy for vim

2
3

Generally speaking, if no efficient native solution is available that's when mappings ride in to save the day.

But you may like the efficiency of this for word swap: df<space>wP. I know that rolls off my fingers quite easily. (dawwP also works but the first four characters are all typed with the left hand which is not ideal. hdeep has three consecutive left handed keys but is okay. It has no capital letters and is easy to remember. I'd put it between the other two choices here.)

As for moving a word to the end of the line/sentence, if you back up one character you could do de$p (IOW hde$p).

1

For swapping I tend to use vim-swap plugin and/or vim-exchange plugin.

Both are really good, vim-swap shines if you want to reorder function parameters, words in a sentence, markdown columns (with additional setup) etc. Plugin vim-exchange is for exchanging parts of the text (selection with a word, or another selection etc)

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.