Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

developing in vim and tmux

by morgon (Curate)
on Apr 17, 2016 at 23:09 UTC ( #1160757=perlmeditation: print w/replies, xml ) Need Help??

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 (Curate) 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 (Priest) 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 (Prior) 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 (Priest) 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...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1160757]
Approved by atcroft
Front-paged by Arunbear
help
Chatterbox?
and God said, "Let Newton be!"...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-12-17 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (464 votes). Check out past polls.

    Notices?