Comment #2 on issue 202 by [email protected]: Dot operator doesn't work
with user-defined insert functions
http://code.google.com/p/vim/issues/detail?id=202
Sure, sorry. I actually tried using vim-operator-user (as well as
github.com/neitanod/vim-sade), but it breaks for this particular use-case.
I actually had a discussion about this with the creator of vim-sade here:
https://github.com/neitanod/vim-sade/issues/3#issuecomment-36698860
The code is in that post, but I'll post it here too. Basically, I want to
call an operator that takes a motion and then moves to a specified side of
that motion (e.g. for `ip` it would either go before the paragraph or after
the paragraph depending on the operator used). It then starts insert mode
at that location. The idea being you could use the dot operator to apply
the entered text to one side of the text object you're using. Even better
would be to be able to do `{the operator}+.` to apply the text to the side
you want, without having to retype the text. But that's a stretch goal
right now.
This is what I wanted to write (I posted in the linked issue a failed
attempt at a workaround; this is what I wanted to do)
```Vim
function! SadeAppend()
exe "normal! \<esc>`>"
call feedkeys('a', 'n')
endfunction
function! SadeInsert()
exe "normal! \<esc>`<"
call feedkeys('i', 'n')
endfunction
call sade#Func('(', 'SadeInsert')
call sade#Func(')', 'SadeAppend')
```
Unfortunately I don't really know the internals of sade very well so I
can't tell you exactly how this looks when you expand the sade#Funcs, but
according to the developer it won't work anyway because
feedkeys/startinsert overwrites the repeat record. A similar issue occurred
when I tried implementing this operation with kana/vim-operator-user. The
syntax is almost identical anyway (replace sade#func with
operator#user#define and change the arguments). I also tried using Tim
Pope's repeat.vim, but it still came up against the same issue.
The operator works perfectly if the text to be added is hard-coded. The
issue arises only when text is entered interactively at the time of the
operator call. Like I said before, it's because feedkeys (or startinsert)
is seen as a distinct "action" to Vim. Feedkeys (and startinsert) is by
design called after the function ends, so this behavior makes sense.
However, it's not what I want. And there is no version of feedkeys that
works from within the function
I tried another workaround where I used a one-time autocommand to call
a "postamble" function on InsertLeave. Combining that with repeat.vim, I
managed to repeat the original function call instead of the text insertion.
So it would perform the motion and then leave the cursor in insert mode.
However, the cursor location was fixed to wherever the original call went,
meaning pressing `.` on a different paragraph would put you at the
corresponding location in the _original_ paragraph. In addition,
InsertLeave is not triggered if the user types <C-c> to escape, so there's
no guarantee the postamble will even be called.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.