It would be fine if after :make
command vim opened the new buffer with errors and put the cursor to it. Exactly like :make | copen
command. How to map sequence :make | copen
?
You could create an abbreviation in the command line mode by adding this to your vimrc:
cabbrev mc make<bar>copen
Now when you'll type mc
in the command line it will be replaced by make|copen
making it faster to type.
You could also create a mapping to invoke the commands you want:
nnoremap <key> :make<bar>copen<CR>
EDIT As @Sato Katsura pointed it out in the comment my first version of cabbrev
is not a good one: Indeed in the first version mc
will be replaced no matter where it is placed in the command line, so for example I you want to search in a buffer for the string mc
and you try to hit /mc
it will be replaced by /make|copen
.
To resolve that @Sato linked an interesting tip. With the following syntax mc
will be replaced only if it is the first thing typed in the command line:
cabbrev make <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'make<bar>copen' : 'make')<CR>
-
1Thank you! Both spells work well. I put
cabbrev make make<bar>copen
in .vimrc (I more used to type `make') it works. – Alexey Reshetnyak Aug 13 '16 at 19:31 -
3
The best solution is to not create a mapping at all.
Simply put the following snippet in your vimrc
:
augroup quickfix
autocmd!
" automatic location/quickfix window
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
augroup END
This will open the quickfix window automatically after :make
and other quickfix-related commands like :grep
, when there are valid errors (:cwindow
versus :copen
).
Same for location-related commands like :lvimgrep
.
--- EDIT ---
The general structure of an autocommand is:
autocmd [<group>] <EventName>[,<EventName>[,...]] <pattern> <command>
Here, <pattern>
is matched against Ex command names:
l*
matches all command names starting withl
(:lgrep
,:lmake
, etc.),[^l]*
matches all command names not starting withl
(:grep
,:make
, etc.).
Quickfix-related command names start with different letters while location-related command names all start with an l
so l
as first character is a convenient way to discriminate them.
-
This solution doesn't put cursor to the quickfix window, but
make | copen
does. – Alexey Reshetnyak Aug 13 '16 at 18:57 -
-
| wincmd p
spell doesn't works either. It puts cursor to the first error in the window with source code not to quickfix window. – Alexey Reshetnyak Aug 13 '16 at 19:20 -
could you explain, please, where do the patterns
[^l]*
andl*
come from? I mean, what are they for? Or they aren't patterns? – Dmitry Koroliov Jun 3 '17 at 2:16 -
1