Something like this will work
nnoremap ;; :s/\v(.)$/\=submatch(1)==';' ? '' : submatch(1).';'<CR>
In this case, the substitute command is used and it is checked whether the last character is a semicolon, and if it deletes it. If he does not attach it to the character that was matched. This uses \= in the replacement part to execute the vim expression.
If you don't match an arbitrary character, you can wrap it in a function and pass in the character you want to match.
function! ToggleEndChar(charToMatch) s/\v(.)$/\=submatch(1)==a:charToMatch ? '' : submatch(1).a:charToMatch endfunction
and then the display would have to switch the semicolon.
nnoremap ;; :call ToggleEndChar(';')<CR>
source share