1

I am setting makeprg to perl % to run my Perl script (if there's a better way, I'm up for that, too), and it works just fine, except that it reproduces the first line of output prefixed with the text "(1 of n)", where n seems to be the total output line count.

I'd like to suppress that, leaving me with just what my Perl script produces. Can I suppress that report line from :make? The .vimrc line that sets up makeprg is:

autocmd FileType perl   :set makeprg=perl\ %
4
  • you probably want to not use :make but instead map K key to :!perl % (or even :%w!perl)
    – Naumann
    Commented Dec 8, 2017 at 14:13
  • 1
    @Naumann K is usually used for documentation, make for running or compiling programs. I think this is the appropriate way to go.
    – D. Ben Knoble
    Commented Dec 8, 2017 at 15:54
  • RadlyEel, have you tried using the :compiler command to set the makeprg? Im sure perl has some native support in Vim... do you have filetype plugins enabled?
    – D. Ben Knoble
    Commented Dec 8, 2017 at 15:55
  • 1
    Thanks to both. I didn't like K, but F5 is a commonly used "Run" command in other IDEs, so I used it and that worked perfectly. Using the :compiler command only gives me syntax checking. And there's no user input in this approach, so for interactive scripts I have to use the two-terminal approach. There is a Perl mode in Vim, but I couldn't find what I was looking for. Thanks again.
    – RadlyEel
    Commented Dec 9, 2017 at 15:15

2 Answers 2

1

Plugin vim-dispatch by Tim Pope

This plugin provides as one of its main features running makeprg non-blocking either in the foreground or the background. Quote from :h dispatch:

Leverage the power of Vim's compiler system without being constrained by synchronicity.

The first command by vim-dispatch is :Make (note the capital M):

:Make [arguments]       Using the current |:compiler| settings, dispatch a
                        build in the foreground.  Adapter strategies vary, but
                        the goal is visibility without stealing focus.  When
                        the build is complete, load the results into the
                        |quickfix| list and call |:cwindow|.  This command is
                        preferred for shorter tasks like "build this file."

Let us consider this hello world perl file without errors which has as output two lines

#!/usr/bin/env perl
use strict;
use warnings;

print "Hello world\n";
print 42, "\n";

Set makeprg as the OP suggested or manually with

:se mp=perl\ % (abbreviated form of makeprg is mp)

Now press either m<CR> or type :Make<CR> from vim-dispatch. Perl will be executed and the output will be available in the quickfix window without any additional lines:

enter image description here

The OP might be interested in having the quickfix window automatically be opened or keeping it open during scripting & running. Unfortunately, I could not figure this out. But someone has already filed this as a feature request on github.

Other plugins provide this but are heavier plugins such as:

vim-dispatch as of 2019

  • supports vim8/neovim jobs (no tmux/screen/iterm needed anymore)
  • nice (IMHO) default mappings
    • m<cr> for :Make
    • m<Space> for :Make<space> (e.g. allows the user to run make debug)
    • and more (see :h dispatch-maps)
  • Pending PR #250 and active branch to use vim8/neovim terminal for :Start to spawn interactive processes.
0

autocmd BufRead *.pl map <F5> :exe ':silent !perl %'<CR>:redr!<CR>

This defines an autocmd for perl files. If F5 is pressed, the current file will be sent to the perl interpreter, afterwards the buffer is redrawn, so you will not see any output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.