Skip to main content
C-U #n -> C-#n : saves one keystroke
Source Link
YSC
  • 812
  • 5
  • 10

Emacs, 2626, 25-ish keystrokes

ARETBRETF3UPUPC-SPACEC-EM-WDOWNDOWNC-Y UPC-AC-SPACEC-EM-WDOWNC-EC-YRETF4C-U#(n-2)F4

command(s)               explanation                      buffer reads (| = cursor aka point)
-----------------------------------------------------------------------------------------------
A<RET> B<RET>            input starting points            "a\nb\n|"
<F3>                     start new macro                  "a\nb\n|"
<UP><UP>                 move point two lines up          "|a\nb\n"
C-<SPACE> C-E M-W        copy line at point               "a|\nb\n"
<DOWN><DOWN>             move point two lines down        "a\nb\n|"
C-Y                      yank (paste)                     "a\nb\na|"
<UP>                     move point one line up           "a\nb|\na"
C-A C-<SPACE> C-E M-W    copy line at point               "a\nb|\na"
<DOWN>                   move point one line down         "a\nb|\na|"
C-E C-Y <RET>            yank (paste) and add new line    "a\nb|\nab\n|"
<F4>                     stop macro recording             "a\nb|\nab\n|"
C-U #(n-3) <F4>            apply macro n-3 times            "a\nb|\nab\nbab\nabbab\n|"

Emacs, 26-ish keystrokes

ARETBRETF3UPUPC-SPACEC-EM-WDOWNDOWNC-Y UPC-AC-SPACEC-EM-WDOWNC-EC-YRETF4C-U#(n-2)F4

command(s)               explanation                      buffer reads (| = cursor aka point)
-----------------------------------------------------------------------------------------------
A<RET> B<RET>            input starting points            "a\nb\n|"
<F3>                     start new macro                  "a\nb\n|"
<UP><UP>                 move point two lines up          "|a\nb\n"
C-<SPACE> C-E M-W        copy line at point               "a|\nb\n"
<DOWN><DOWN>             move point two lines down        "a\nb\n|"
C-Y                      yank (paste)                     "a\nb\na|"
<UP>                     move point one line up           "a\nb|\na"
C-A C-<SPACE> C-E M-W    copy line at point               "a\nb|\na"
<DOWN>                   move point one line down         "a\nb|\na|"
C-E C-Y <RET>            yank (paste) and add new line    "a\nb|\nab\n|"
<F4>                     stop macro recording             "a\nb|\nab\n|"
C-U #(n-3) <F4>          apply macro n-3 times            "a\nb|\nab\nbab\nabbab\n|"

Emacs, 26, 25-ish keystrokes

ARETBRETF3UPUPC-SPACEC-EM-WDOWNDOWNC-Y UPC-AC-SPACEC-EM-WDOWNC-EC-YRETF4C-#(n-2)F4

command(s)               explanation                      buffer reads (| = cursor aka point)
-----------------------------------------------------------------------------------------------
A<RET> B<RET>            input starting points            "a\nb\n|"
<F3>                     start new macro                  "a\nb\n|"
<UP><UP>                 move point two lines up          "|a\nb\n"
C-<SPACE> C-E M-W        copy line at point               "a|\nb\n"
<DOWN><DOWN>             move point two lines down        "a\nb\n|"
C-Y                      yank (paste)                     "a\nb\na|"
<UP>                     move point one line up           "a\nb|\na"
C-A C-<SPACE> C-E M-W    copy line at point               "a\nb|\na"
<DOWN>                   move point one line down         "a\nb|\na|"
C-E C-Y <RET>            yank (paste) and add new line    "a\nb|\nab\n|"
<F4>                     stop macro recording             "a\nb|\nab\n|"
C-#(n-3) <F4>            apply macro n-3 times            "a\nb|\nab\nbab\nabbab\n|"
Source Link
YSC
  • 812
  • 5
  • 10

Emacs, 26-ish keystrokes

Program

#n to be read as key with digit(s) n:

ARETBRETF3UPUPC-SPACEC-EM-WDOWNDOWNC-Y UPC-AC-SPACEC-EM-WDOWNC-EC-YRETF4C-U#(n-2)F4

Explanation

command(s)               explanation                      buffer reads (| = cursor aka point)
-----------------------------------------------------------------------------------------------
A<RET> B<RET>            input starting points            "a\nb\n|"
<F3>                     start new macro                  "a\nb\n|"
<UP><UP>                 move point two lines up          "|a\nb\n"
C-<SPACE> C-E M-W        copy line at point               "a|\nb\n"
<DOWN><DOWN>             move point two lines down        "a\nb\n|"
C-Y                      yank (paste)                     "a\nb\na|"
<UP>                     move point one line up           "a\nb|\na"
C-A C-<SPACE> C-E M-W    copy line at point               "a\nb|\na"
<DOWN>                   move point one line down         "a\nb|\na|"
C-E C-Y <RET>            yank (paste) and add new line    "a\nb|\nab\n|"
<F4>                     stop macro recording             "a\nb|\nab\n|"
C-U #(n-3) <F4>          apply macro n-3 times            "a\nb|\nab\nbab\nabbab\n|"

With n=10

a
b
ab
bab
abbab
bababbab
abbabbababbab
bababbababbabbababbab
abbabbababbabbababbababbabbababbab
bababbababbabbababbababbabbababbabbababbababbabbababbab