Quite a common task to swap words on a single line might be really cumbersome.
Consider following text transormation:
def hello(world, is, on, fire) → def hello(is, world, on, fire)
This one is fairly simple:
-
put your cursor on
world
-
dWWP
— swap it withis
The next one would have more keypresses:
def hello(world, is, on, fire) → def hello(world, is, fire, on)
-
put your cursor on
on
-
dw
— delete it -
w
— go tofire
-
vep
— select and paste over it (yanking prev selected text) -
bbP
— back to whereon
was, pastefire
yanked previously
Or the next one:
def hello(world, is, on, fire) → def hello(fire, is, on, world)
-
put your cursor on
world
-
diw
— delete it -
/fi<CR>
— go tofire
-
vep
— select and paste over it (yanking prev selected text) -
``P
— back to whereworld
was, pastefire
yanked previously
There is a way to simplify it:
-
You can introduce your own mappings to some of usecases as described in https://vim.fandom.com/wiki/Swapping_characters,_words_and_lines
-
or use plugins like https://github.com/machakann/vim-swap or https://github.com/tommcdo/vim-exchange
With mentioned plugins it looks way more convenient:
There is customization in vim-swap you can use to swap markdown table cells:
vim-swap settings for the markdown cells swaps:
let g:swap_no_default_key_mappings = 1
nmap g< <Plug>(swap-prev)
nmap g> <Plug>(swap-next)
nmap g. <Plug>(swap-interactive)
let g:swap#rules = deepcopy(g:swap#default_rules)
let g:swap#rules += [
\ {
\ 'mode': 'n',
\ 'description': 'Reorder the | bar | delimited | things |.',
\ 'body': '|\%([^|]\+|\)\+',
\ 'delimiter': ['\s*|\s*'],
\ 'priority': -40
\ }
\ ]