0

Vim has a key binding to swap two words while keeping the cursor in the same place as detailed here

:nnoremap gw "_yiw:s/(\%#\w+)(\W+)(\w+)/\3\2\1/

Unfortunately this does not seem to work in VSVim with an error reporting that the pattern could not be found: (\%\w+)(\W+)(\w+). I note that the # is missing from the pattern reported by the error message. I wonder if anyone has an idea of what the problem maybe with regex element of the binding and indeed what role the # has?

Gravin
  • 1
  • 1

1 Answers1

0

\%# in vim's regex gives the cursor position (see http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\%#)

It doesn't seem to be working for me either, seems like a decent feature request, I added it here: https://github.com/jaredpar/VsVim/issues/1780

Edit: The developer responded that this feature is out of scope for VsVim:

Unfortunately this is a feature that I can't take at this time. My regex infrastructure is based on using .NET Regex under the hood. They have no notion of cursor position and there is no way for me to translate the cursor position into a regex element. Hence there is no way to do this without creating a full regex engine from scratch which is currently beyond the scope of this project.

Ian Hatch
  • 1,241
  • 2
  • 8
  • 4