Coding⏱️ 3 min read📅 2026-06-11

How to Fix: Vim lint check - only show message if there's an error

How to fix vim lint check to only show error messages

Quick Answer: Use the `2>&1` redirection operator to suppress output from the shell command, or use a conditional statement in your autocmd to check for non-zero exit status.

The issue you're experiencing is not uncommon in Vim users. The autocmd BufWritePost *.rb !ruby -c <afile> command runs the ruby interpreter's error checking on saved .rb files. However, this can result in unnecessary output at the bottom of the screen, making it difficult to ignore.

To address this issue, you'll need to modify the existing autocmd line to only display a message if there are errors. This involves using conditional suppression of output from the shell command.

💡 Why You Are Getting This Error

  • The primary cause of this issue is the lack of conditional output suppression in the autocmd line.
  • Another possible cause could be the use of an outdated or incompatible version of Vim.

🛠️ Step-by-Step Verified Fixes

Modifying the Autocmd Line

  1. Step 1: Open your .vimrc file and locate the line containing the autocmd BufWritePost *.rb !ruby -c <afile>.
  2. Step 2: Replace the existing line with the following: autocmd BufWritePost *.rb !ruby -e 'if $? != 0; echo "Error occurred during execution"; fi' <afile>
  3. Step 3: In this modified line, the !ruby command is replaced with !ruby -e. The -e option allows you to execute a Ruby code block.
  4. Step 4: The if $? != 0 condition checks the exit status of the shell command. If it's not equal to 0, it means an error occurred, and the echo statement will display "Error occurred during execution".

Alternative Fix

  1. Step 1: As an alternative solution, you can use a different approach to run the ruby interpreter's error checking. One option is to use the -n option with !ruby.
  2. Step 2: Replace the existing line with the following: autocmd BufWritePost *.rb !ruby -n <afile>
  3. Step 3: The -n option tells Vim to suppress output from the shell command if it returns a non-zero exit status.

🎯 Final Words

By modifying the autocmd line or using an alternative approach, you should be able to achieve your desired outcome of only displaying a message when there are errors.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions