Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:03:06+00:00 2026-06-12T08:03:06+00:00

I am trying to use an external command to handle some formatting over a

  • 0

I am trying to use an external command to handle some formatting over a range of lines in Vim but can’t seem to find a way to deal with errors from the external command.

These errors are usually when the shell returns something other than 0 and it prompts Vim to display something along the lines of:

shell returned 1

Besides doing that, it replaces the lines I wanted to format with the actual message of the error. This happens as well if I do:

:set equalprg=myformatter\ --format-flag\

How can I safely catch an error for an external command and display whatever the error message is?

Note: this is not a question on how to use an external command to format some text in Vim, but rather, how to catch an error and display the message back.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:03:07+00:00Added an answer on June 12, 2026 at 8:03 am

    There may be a better way to do this, but I got this rough draft working (see further below for equalprg). It basically remaps gq, overwriting it to print the error and then undo it.

    set formatprg=~/test.sh
    
    nnoremap gq :setl opfunc=FormatPrg<cr>g@
    fun! FormatPrg(...)
       silent exe "'[,']!".&formatprg
       if v:shell_error == 1
          let format_error = join(getline(line("'["), line("']")), "\n")
          undo
          echo format_error
       end
    endfun
    

    This is what’s in ~/test.sh:

    echo "error!!
    alskdjf alskdf
    alskdj flaskdjf" 1>&2
    exit 1
    

    Edit:

    I just realized that I didn’t answer your question at all haha. My solution for equalprg is even less elegant, but it may suit your needs. To use this you must set equalprg. Either comment out the nnoremap line or set indentexpr=EqualPrg() if you want to switch back and forth between an external tool and the internal indentation formatter.

    set equalprg=~/test.sh    
    
    nnoremap = :setl opfunc=EqualPrg<cr>g@
    fun! EqualPrg(...)
       if &equalprg != ""
          silent exe "'[,']!".&equalprg
       else
          set indentexpr=
          exe "norm! `[=`]"
          set indentexpr=EqualPrg()
       endif
       if v:shell_error == 1
          let format_error = join(getline(line("'["), line("']")), "\n")
          undo
          echo format_error
       endif
    endfun
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use some external Framework in my iPhone app. I did
I'm trying to use javac with the windows command prompt, but it's not working.
I am trying to use a python script to call an external command a
I'm trying to use an external REST Library for my application, and I'm hoping
The question says it all, I am trying to use an external library in
I am trying to use external font in PDF document. I have no problem
I'm trying to access my .android debug.keystore so I can use it for facebook.
I'm trying to run some external executable code from within Python and then make
I am trying to use an external program from within Scala that accepts its
i'm trying use facebook API to upload photo in my fan page. I downloaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.