i am searching for a substitution command in vim for removing every semicolon in a file, if it is the last character of the line.
i already found this command, which toggles a semicolon at the end of the line:
nnoremap ;; :s/\v(.)$/\=submatch(1)==';' ? '' : submatch(1).';'<CR>
Can someone help me out here?
SOLUTION
- the command i was searching for, was part of a little greater cleanup i want to do after saving a file. the complete solution looks like that
" greenkeeping files
" consecutive blank lines: https://unix.stackexchange.com/questions/12812/replacing-multiple-blank-lines-with-a-single-blank-line-in-vim-sed
" whitespaces: https://stackoverflow.com/questions/356126/how-can-you-automatically-remove-trailing-whitespace-in-vim
" last empty line: https://stackoverflow.com/questions/7495932/how-can-i-trim-blank-lines-at-the-end-of-file-in-vim
" last semicolon: https://unix.stackexchange.com/posts/462443
autocmd BufWritePre *.test silent! :%s/\s\+$//e | silent! :%s/\(\n\n\)\n\+/\1/ | silent! :%s#\($\n\s*\)\+\%$## | :%s/;$
:%s/;$/
, or is the keymapping in your example important for you?/
at the end?/
is redundant... as is the current actually.:%s/;$
works also.