Skip to main content
2 of 3
added 6 characters in body
MiniMax
  • 4.2k
  • 1
  • 21
  • 36

Vim's variant. Vim should be the default editor.

  1. Pick a long command from the history, using up/down arrows. I have chosen this:echo "one two three" > new_file.txt
  2. Press Ctrl + x Ctrl + e combination. It will open our long command inside Vim. Press Ctrl + g, for showing the temporary file name in the bottom of the vim window. In my case it is /tmp/bash-fc.230BC2
  3. Go to another tty, type vim /tmp/bash-fc.230BC2 (using filename autocomplete, of course). It will tell you "Swap file already exist" - press O, for open read only.
  4. Then, inside vim, you are needed the next key sequence: yy : ! Ctrl+r " Enter
    Explanation:
  • yy - copy all line
  • : - go to the command-line mode
  • ! - execute command with shell
  • Ctrl+r " - paste the copied line to the command line.
  • Enter - execute command

I should mention, that all this key sequence can be mapped to one keystroke, by .vimrc file edit.

It is done - command was copied from one tty to another and executed.

MiniMax
  • 4.2k
  • 1
  • 21
  • 36