First I will describe what I am trying to achieve:
In general I use set iskeyword+=-
as I see this more usable (one should always put spaces around operators when needed). This is quite helpful, but has one significant disadvantage - it also causes i_^w
to behave not as expected. So I am trying to write function that would reset 'iskeyword'
to default value, modify it a little and then fire the same functionality as i_^w
, however I cannot find how to handle "deletion" part.
My attempt
func! smart#delete_word() abort
let l:iskeyword = &iskeyword
try
set iskeyword&vim
set iskeyword-=_
if col('.') == col('$') - 1
normal! dvb
else
normal! db
end
finally
let &iskeyword = l:iskeyword
endtry
endfunc
However db
/dvb
trick isn't always working as expected and sometimes there are some leftovers at the end of the line or some additional characters are deleted.
So question is, how to achieve the same behaviour as i_^w
in function (worth mentioning that i_^w
itself will be remapped to this function, so it wouldn't be a solution to just feedkeys("\<C-w>")
.
norm! i^w
where you insert^w
with<c-v><c-w>
exec "norm! a\<c-w>"
doesn’t work when started in the middle of the line.feedkeys("\<C-w>", 'n')
doesn't map (similar tonormal!
)feedkeys("\<C-w>", 'n')
didn't work as expected as it deleted single character at the time. However it can be bug in NeoVim.