-
-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Hi Tim, here is my code of interest:
``
function! s:DeleteWhitespace() abort
let start_pos = getcurpos()[2]
let next_word_col = searchpos('\S', 'nW')[1] " get column without moving cursor
if next_word_col > start_pos
let delete_count = next_word_col - start_pos
execute 'normal! ' . delete_count . 'x'
echo 'vc=' virtcol('.') 'getcurpos=' start_pos 'wordpos=' next_word_col
silent! call repeat#set("<Plug>DeleteWhitespace", 1)
endif
endfunction
nnoremap DeleteWhitespace :call DeleteWhitespace()
nnoremap d DeleteWhitespace
``
It deletes the whitespace from the cursor position until the start of the next word. Works perfectly when called, but when repeated, col('.'), virtcol('.'), and getcurpos()[2] always return 1, instead of the actual column. I don't think this is a problem with your excellent plugin, but a bug in neovim. (Also searchpos() starts at the first column too, which leads me to believe the cursor position is not available to my function when it is running inside neovim's "repeat system")
I am posting this issue, because I am not a vim master and I cannot find a fix using google or chatGpt. If you can tell me how to get the current column when my function is called by vim's repeat system that would be great.