nvim-treesitter-textobjects icon indicating copy to clipboard operation
nvim-treesitter-textobjects copied to clipboard

Allow to use "." for swapping

Open theHamsta opened this issue 3 years ago • 4 comments

Fix #35

theHamsta avatar Apr 14 '21 19:04 theHamsta

If possible I would recommend avoiding vim-repeat. Instead you can use vim's native g@ like in this example: https://gist.github.com/andymass/d465970cc178452eac006840e5e58b2b

Specifically, although g@ is usually used as the start of normal operators you can also use it for entire normal commands with the sequence g@l.

andymass avatar Apr 21 '21 01:04 andymass

@andymass can you create a PR for it? I can't think of a elegant way to implement this. As far as I understood, we must set operatorfunc. But we can't refer to our Lua functions with v:lua because we have a - in our folder name. Also we would have to create a outer function that sets the operatorfunc and an inner that does the actual action.

Can't you use the g@l hack already now in your config?

theHamsta avatar Apr 21 '21 08:04 theHamsta

Can't you use the g@l hack already now in your config?

Yes, it's possible via a wrapper function;

function! s:repeatable(cmd)
  function! s:inner(...) closure abort
    execute a:cmd
  endfunction
  let &opfunc=get(funcref('s:inner'), 'name')
  return 'g@l'
endfunction

nnoremap <silent><expr> <left>
      \ <sid>repeatable('TSTextobjectSwapPrevious @parameter.inner')
nnoremap <silent><expr> <right>
      \ <sid>repeatable('TSTextobjectSwapNext @parameter.inner')

But we can't refer to our Lua functions with v:lua because we have a - in our folder name.

I think that could be fixed fairly easily, but a problem remains that there would have to be some state held somewhere and I'm not sure how to refer to lua inner functions in operatorfunc.

can you create a PR for it?

Here is a first shot at it using the same technique as above: #55 . I'm not sure how to do it with pure lua.

andymass avatar Apr 23 '21 01:04 andymass

Ping

stellarhoof avatar Apr 01 '22 02:04 stellarhoof

Bump

kuator avatar Dec 22 '22 06:12 kuator

Superseded by #343 or #55

theHamsta avatar Dec 22 '22 14:12 theHamsta