I have the following vim auto command:
autocmd BufWritePost *.go :cex system('revive '..expand('%:p')) | copen
It executes a binary called revive, passing it the current file path, and then opens up the quickfix window with the results from the revive binary.
But if the revive binary returns empty I'd prefer not to have the quickfix window opened.
Wondering if there's a better way to handle this? Is there a way to check for an error status or checking the length of the quickfix results before opening?
Thanks!
#romainl solved this for me by commenting about :cwindow.
The use of :cwindow prevents the quickfix window opening unless there are error items in the list.
Thanks Romainl
Related
I would like to always open a vertical split with Explore whenever I open a file in vim. So I added the following list to my init.vim
topleft vsplit | :vertical resize 30 | :Ex
however I get the following error message.
Not an editor command: :Ex
however I get the following error message.
So the command is invalid. :Ex is provided by a plugin (usually netrw). The message means that netrw is not loaded (yet).
I added the following list to my init.vim
Please, take your time reading :h startup. To put it short, vimrc (or init.vim) is processed long before any plugin is loaded. You really should delay your command until VimEnter event. Kind of
if v:vim_did_enter
DoSomethingIfSourcedManually
else
autocmd VimEnter * ++once ++nested DoSomethingOnStartup
endif
I've been trying to experiment with using :make recently but I don't like that vim has to switch to showing the shell output first and require one enter keypress, then it shows me what I think is a list of the collected errors based on 'errorformat' which I also need to confirm by pressing enter. I would prefer to just have a short "OK" message that does not require confirmation by a keypress, or that vim would open the :cwindow if there were any errors.
I'm using next line just for exact purpose you wrote:
nnoremap <leader>m :silent make\|redraw!\|cc<CR>
cc in the end shows first error or No errors message if this is the case.
You can map for example F9 to use gcc for small C snippets that don't require libraries, linking, etc:
map <F9> :!gcc -o %< % <enter><CR><C-w>
This will produce for the file foo.c the binary foo. I know that's not exactly what you want, but this doesn't show any shell and is useful for small c snippet.
Try:
:silent make
To automatically open the quickfix window after you run make, you can put this into your .vimrc:
autocmd QuickFixCmdPost * :copen
I want to run make | tee errors.err and then have :copen use errors.err to open the quickfix list and jump to any compilation errors.
You're looking for :cfile [errorfile] instead of :copen.
Read the error file and jump to the first error.
According to the answer of this question, the :bd command should not quit Vim (gVim) when it is the last buffer remaining. Unfortunately, it does close gVim in my case. Did I understand something wrong about :bd?
I am also using a preconfigured vimrc file. Maybe a setting in there has that side affect, but I couldn’t find it.
Try doing the following:
:set eventignore=all | bd | set eventignore=
If this won't quit vim then you have some plugin that defines an autocommand that quits vim when no more buffers are present in the list, so after that try doing
verbose autocmd BufWinLeave,BufLeave,BufDelete,BufUnload,BufWipeout
This will show you all autocommands attached to given events (these are events that are executed when buffer is deleted) and where they were defined. Note that I do not have any autocommands attached to these events that are defined by plugins in standart vim distribution.
Update: I do not see anything bad in your output. You may also try
verbose autocmd BufNew,BufAdd,BufCreate,BufEnter,BufWinEnter
(because when you leave last buffer new empty one is created). If this does not show anything suspicious, start ignoring event types: if you are on linux try the following script:
for event in BufWinLeave BufLeave BufDelete BufUnload BufWipeout BufNew BufAdd BufCreate BufEnter BufWinEnter
do
event=$event vim file -c "set eventignore=$event | bd"
done
This script should iterate until you find event name that causes trouble. After this you can use execute "verbose autocmd" $event in vim to narrow number of plugins that should be checked. After you got list of autocmd groups (augroup names are shown just before event name in your output: railsPluginDetect is one of such groups), delete events in them (augroup {GroupName} | execute 'autocmd!' | augroup END) and find out which plugin to claim.
Alternatively, you can use debugger:
debug bd
, then s<CR>n<CR><CR><CR>... until vim quits; don't forget to remember what vim have shown above > prompt before quiting.
When I use vi to open a file *.c, I would like the cursor to move to the string "main" automatically. If there is no "main", I want the cursor to go to "void" without an error prompt.
In my .vimrc I have set
:autocmd BufRead *.c 1;/main
but this cannot implement all my requirements. Specifically, if there exists no "main" in some opened C source file, vi prompts "Error, cannot find main ...." which is the behaviour I want to remove.
I have also tried adding <silent> or :silent to that autocmd line, but it doesn't do what I want. Can anyone help me? Thanks.
Just use :silent!; it runs a given command blocking not only the
normal messages but also the errors.
I would recommend to use the BufReadPost event instead of BufRead
to run your command after the buffer is loaded, and change the
search pattern to look for main as a separate word:
:autocmd BufReadPost *.c :silent! 1;/\<main\>
Try /main\|^, but if cursor in file not on first line - it's not that you want.