http://www.perlmonks.org?node_id=995450


in reply to How to write out a Perl script and run it in as few keystrokes as possible.

Unless you are running on a dumb terminal, why not have two windows open. Do your edits in one and just do :w to save the file without quitting the editor. Run the script in the other window. Repeat as required.

Cheers,

JohnGG

  • Comment on Re: How to write out a Perl script and run it in as few keystrokes as possible.
  • Download Code

Replies are listed 'Best First'.
Re^2: How to write out a Perl script and run it in as few keystrokes as possible.
by MrSnrub (Beadle) on Sep 24, 2012 at 23:20 UTC
    I would think that would actually increase the number of keystrokes needed by one:

    Original Process

    Start:
    (UP)vim filename.pl(ENTER) (2 keystrokes)
    (make changes) (0 keystrokes)
    :wq(ENTER) (4 keystrokes) *
    (UP)(UP)perl -Wall filename.pl(ENTER) (3 keystrokes)
    GOTO Start

    Total: 8 keystrokes

    Two-Window Process

    Start:
    (edit .pl file in vim, window1) (0 keystrokes)
    :w(ENTER) (3 keystrokes) *
    Alt-Tab to window2 (2 keystrokes)
    (UP)perl -Wall filename.pl(ENTER) (2 keystrokes)
    Alt-Tab back to window1 (2 keystrokes)
    GOTO Start

    Total: 9 keystrokes

    * : only counts as one keystroke because in my .vimrc I have ; mapped to : and vice-versa so I don't need to press the Shift key
      the first process can even be shortened by using ZZ instead of :wq and enter.
      but one advantage of the second is, you still have the vim history and can undo the recent changes easily. another is, you can still see the output of your script when continuing with editing.
      Enable sloppy focus/focus-follows-mouse and both alt-tab instances go away, reducing it to 5 keystrokes - just drift your mouse pointer over the other terminal window. (And, yes, I'm pretty sure both Windows and OSX have options/plugins/tweaks that let you use sloppy focus. It's not an X-only thing.)

      Even without that, you forgot to account for needing to go back twice in command history to return to editing the source after running it. Include that forgotten "(UP)", and it's a tie at 9 and 9.

      More importantly, as already mentioned, keeping your vi(m) session open lets you keep your undo history, which can be far more valuable than shaving off a keystroke here and there.

      Using multiple windows/tabs also generalizes nicely to working with multiple source files (you do organize your code into modules rather than making it all one huge file, don't you?), since you can view and switch between the different source files trivially rather than having to try to find the correct file in your command history.

      (Am I the only one who thinks this entire quest is a bit silly, though? I know that the primary bottleneck in my coding is not the number of keystrokes I spend in the shell... Not even close...)

      I think that your single window method is also going to be 9 keystrokes because you will need 2 up-arrows to get back to vim once you have run your script.

      When given the choice I prefer to use a GUI editor, nedit, and I have set up my window manager so that focus follows the mouse without the need to click in a window. I also use emacs-style command history navigation as I was an Emacs user on Pr1mos long before I ever saw vi so am more familiar with it. My process is as follows:-

      • Start:
      • Edit script with nedit - (0 keystrokes)
      • Ctrl-S to save (2 keystrokes)
      • Move mouse over xterm window (1 wrist twitch)
      • Ctrl-P then Enter to re-run script (3 keystrokes)
      • Move mouse back to nedit window (1 wrist twitch)
      • GOTO Start

      I make that 5 keystrokes and 2 wrist twitches.

      Cheers,

      JohnGG

        nedit used to be my text editor of choice. I now prefer SciTE; it has more reliable Perl syntax highlighting (I often found nedit couldn't find the end of a string or regexp) and an integrated panel for displaying shell output, so if I'm editing a Perl script, I just need to save it and hit F5 to show the output at the bottom of my editing screen.

        My only slight gripe is that the regular expression engine used by SciTE's search and replace is not quite as advanced as nedit's. But I can always copy and paste into a nedit window for advanced search and replace. (Or just run Perl or sed over the file.)

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'