http://qs1969.pair.com?node_id=1160757

Sorry for slightly misusing this section as this is not something deep - just a little productivity hack...

As a vim-user for many years I would edit my script in the one true editor and then run it (again and again for development) either in another terminal altogether or would background vim via Ctrl-Z.

But now I have found something more convenient.

If you run vim inside tmux and install the vimux-plugin you can send tmux-commands from within vim.

Now add this to your .vimrc:

let mapleader=" " map <Leader><space> :VimuxRunCommand("perl " . bufname('%'))
If you now open your perl-script in vim within a tmux-session and hit <space> twice (tweak the key-binding to your liking), a new tmux-pane opens and runs your script - without loosing focus in vim - so much nicer...

Replies are listed 'Best First'.
Re: developing in vim and tmux
by morgon (Priest) on Apr 21, 2016 at 02:48 UTC
    New feature.

    Running perl-scripts is nice and dandy, but sometimes these scripts needs arguments...

    So here is how to add arguments to your perl-script:

    Add this to your .vimrc:

    function! PerlArgs() let @p = getline(".")[1:] endfunction let mapleader=" " map <Leader><space> :VimuxRunCommand("perl " . bufname('%') . " " . @p +)<CR> map <Leader>a :call PerlArgs()<CR>
    The idea is to let the vim-register p hold the arguments you want to supply to your script.

    You have to set them only once and run the script with these args as many times as you want. Only when you want different arguments you need to set them again.

    Assume this script:

    #hubba bubba print join "\n", @ARGV;
    To run this script without arguments you simply hit <space> twice.

    To supply the arguments "hubba bubba", you place your cursor on the first line and press <space>a.

    This puts the content of this line (excluding the first character '#') into register p, which will be used when you call the script with <space><space>.

    I hope I don't misuse this section, my idea is to improve productivity with trivial code that is understandable, as opposed to using plugins or tools that no-one understands...

Re: developing in vim and tmux
by nysus (Parson) on Apr 20, 2016 at 17:18 UTC

    Cool tip. But I can't get it to work with a double space. Only if I hold the space key down and get it to repeat, then the VimxRunCommand shows at the bottom.

    Update: It actually took a triple space to get working.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Re: developing in vim and tmux
by karlgoethebier (Abbot) on Apr 22, 2016 at 09:21 UTC
    "...the one true editor..."

    The one true editor is emacs ;-)

    Regards, Karl

    M-x shell-mode. One must be the asshole

    «The Crux of the Biscuit is the Apostrophe»

      Actually I deliberately put that in to provoke some reaction from people that have yet to see the light :-)
        VIM - the one true editor (and only editor!)

        Truth is that most VIM "cool new" feature threads here deal about things, which are already bundled with emacs for far more than a decade now.

        And the complexity to activate them for VIM is not smaller than configuring ("the one true") IDE-Construction-Set that emacs is.

        In the end most users of all these tools end up with their own highly personalized development environment which is mostly unusable for others. Most monks here are aware of this and don't care about such pseudo flames.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re: developing in vim and tmux
by nysus (Parson) on Apr 21, 2016 at 01:22 UTC

    So I've been using this. One problem I noticed is if I have 2 panes split side by side sitting on top of the pane created by vimux and run the perl code, the output does not get sent to the vimux pane but to the other pane. Do you know how to force the output to the pane generated by vimux?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      Sorry, but the truth is I am myself just learning tmux.

      I believe you can name tmux panes and probably there is a way to send commands to specific panes, so probably the way to do it would be to create a named pane and then send the command to this pane, but I have to investigate...