When I do :update, I'd like to print a message if the buffer was not written (because it wasn't changed).

I get a message upon save, but would like a message if save didn't occur, also.

  • 1
    You cannot replace a builtin command. What you can do is to write another one which will print a message if buffer is not modified. I believe, that's pretty easy to do. Did you make a try at least?
    – Matt
    Commented Sep 12, 2020 at 7:51

2 Answers 2


Here is an improved version to support as many of write/update features as possible. Even if it'd be of a lesser use for this case, it's a good habit to be more precise while creating new commands.

Also try never define a mapping as a prefix of another one (<leader>w vs. <leader>wq), as this may lead to surprising delays.

command! -bar -bang -range=% -nargs=* -complete=file Update
    \   if &modified
    \ |     execute printf('%s %d,%dwrite%s %s', <q-mods>, <line1>, <line2>,
    \           <q-bang>, <q-args>)
    \ | else
    \ |     echo 'Buffer is not modified'
    \ | endif

nnoremap <leader>w :Update<CR>
nnoremap <leader>q :Update<Bar>quit<CR>

With help from this answer, I came up with:

function! s:UpdateVerbose()
    if ! getbufinfo(bufnr())[0].changed
        echomsg "Save unnecessary: buffer is unchanged"
com! UpdateVerbose call s:UpdateVerbose()

" <leader>w to update file (only if it has changed) - a lot faster than :w<Enter>:
nnoremap <Leader>w  :UpdateVerbose<CR>
nnoremap <Leader>wq :UpdateVerbose<CR>:q<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.