How to put two words in the same line?

Asked

Viewed 34 times

0

Good morning, community!

I’m studying what I came for. I would like to put two words (right to left and left to right) on the same line on vim. For example:

def br(esq, dir):

would like to put with a key to

def br(dir, esq):

To put from right to left did

nnoremap <C-Left> B"zdwBh"zpi<Esc>w

But this doesn’t work well with commas.

1 answer

1

There are several ways to do this. Most will depend on specifics of your text, such as where the cursor is, or whether there are only two parameters always, etc.

I leave here a relatively simple way of understanding that you do what you want:

Given the specified text, and cursor position:

def br(esq,| dir):
            \_ Cursor esteja aqui

Press:

  • dt) that will delete all content up to the character )
  • T( which will move the cursor to the character (
  • vt,p which will enter visual mode, select up to the character ,, and paste the previously deleted content
  • t)p which will move the cursor to the character ) and paste what was removed in the previous command.

With this sequence of commands you can re-map and put in your file . vimrc or write to a macro, for example.

Again, there are other paths you can follow that might suit your everyday life better. If you think better, you can look for plugins that do the specified as well. They will probably do better and more generally than the example I gave.

For more generic response options, and some plugin suggestions, see this answer (in English).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.