This might be a silly question, or someone may say it lacks research, but I really cannot understand what does the exclamation mark after silent
mean.
For example, in the following function that removes extra characters such as ^M
:
function! RemoveExtraCharacters()
let l:initialCol = getcurpos()[2]
let l:line = getline('.')[0:initialCol-1]
let l:numRemoved = len(l:line) - len(substitute(l:line, '[^[:print:]\t]', '', 'g'))
let l:save = winsaveview()
keeppatterns silent! %s/[^[:print:]\t]//g
call winrestview(l:save)
if l:numRemoved != 0
call cursor(line('.'), (l:initialCol-l:numRemoved))
endif
endfun
autocmd! BufWritePre * call RemoveExtraCharacters()
You can either use
:silent
or:silent!
as a prefix to any command or you can add thee
option to the substitute, which is often easier.:%s/x/y/ge :silent! %s/x/y/g :silent %s/x/y/g