I have found this great tip how to implement strikethrough for the unicode characters in gVim - http://vim.wikia.com/wiki/Create_underlines,_overlines,_and_strikethroughs_using_combining_characters
It is working great for me, but I am stuck in creating "reverse function" final result which I would like to achive would be in pressing e.g. t to striketrough characters and repeating this would remove the striketrough from the characters. I think I would be able to create such function but I am missing a core thing and that is how to remove the combine character. In mentioned article there is mentioned that you can
:set delcombine
which enables to you deleting by 'x' only the combine character. But that is not something I would like to do :)
So is anyone able to change the following script stated in that article to also add there fucntion to remove the strikethrough from selection?
" modify selected text using combining diacritics
command! -range -nargs=0 Overline call s:CombineSelection(<line1>, <line2>, '0305')
command! -range -nargs=0 Underline call s:CombineSelection(<line1>, <line2>, '0332')
command! -range -nargs=0 DoubleUnderline call s:CombineSelection(<line1>, <line2>, '0333')
command! -range -nargs=0 Strikethrough call s:CombineSelection(<line1>, <line2>, '0336')
function! s:CombineSelection(line1, line2, cp)
execute 'let char = "\u'.a:cp.'"'
execute a:line1.','.a:line2.'s/\%V[^[:cntrl:]]/&'.char.'/ge'
endfunction
I would really appreciate that :)
This function either removes the passed combining character, or adds it to the text.
function! ToggleCombining( character, text )
let l:cleanedText = ''
let l:idx = 0
while l:idx < len(a:text)
let l:codepoint = nr2char(char2nr(a:text[l:idx :]))
if l:codepoint !=# a:character
let l:cleanedText .= l:codepoint
endif
let l:idx += len(l:codepoint)
endwhile
if l:cleanedText !=# a:text
return l:cleanedText
else
return substitute(a:text, '[^[:cntrl:]]', '&' . a:character, 'g')
endif
endfunction
Invoke with
:call ToggleCombining("\u0332", "sample text")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With