Let’s explore a typical use case: write the current buffer, start the build, check the errors.

Now, repeating the :w & :mak & :cw dance over and over doesn’t sound fun. Does it? Well, those commands can be chained with a |:


and recalled with <Up> so that’s not such a big deal but there is still room for improvement, here:

Let’s address the first issue by telling Vim to shut up with the :silent command (or :sil for short):

:w|sil mak|cw

A simple mapping would be a perfect alternative to all that typing. Let’s try with <F5>, a shortcut often used in IDEs to compile the project, both in insert mode and normal mode:

inoremap <F5> <Esc>:write|silent make|cwindow<CR>
nnoremap <F5> :write|silent make|cwindow<CR>

Hmm…​ It looks like Vim doesn’t like bars in mappings. That’s understandable, actually: bars are used to separate commands but inoremap <F5> <Esc>:write|silent make|cwindow<CR> is one command and the parts between bars don’t really make sense on their own. So what can we do? Escape those bars?

Well yes:

inoremap <F5> <Esc>:write\|silent make\|cwindow<CR>
nnoremap <F5> :write\|silent make\|cwindow<CR>

or we can use <Bar>:

inoremap <F5> <Esc>:write<Bar>silent make<Bar>cwindow<CR>
nnoremap <F5> :write<Bar>silent make<Bar>cwindow<CR>

Let’s see how it looks: