There is a text file with bash commands.
Is there a way to copy a line from that file using vi and paste it to console? It may be nano as well.
It is console only server installation. No mouse to be clear.
24 Answers
GPM , "General Purpose Mouse" provides mouse functions in a console, most useful perhaps is cut and paste.
From the man page:
This package tries to be a useful mouse server for applications running on the Linux console. It is based on the "selection" package, and some of its code comes from selection itself. This package is intended as a replacement for "selection" as a cut-and-paste mechanism; it also provides additional facilities.
Additional features are outlined in the "Special commands" section
sudo apt-get install gpmGenerally it works out of the box, at least I have not had to manually configure it.
but a nice overview of how to configure it see
or the man page
4In bash, it is possible to edit the current command in an editor, by pressing CtrlxCtrle.
So:
- Start with a new prompt, press CtrlxCtrle. This will open up a new, blank, editor, preferably Vim (I believe the editor is decided by the
VISUALandEDITORvariables). - Open the file containing commands in a new tab or split.
- Copy the relevant commands over to the original buffer (probably named something like
bash-fc-xxxxxxxx). - Save and quit. Et Voila!
In vi there is a visual mode which allows you to visually select text. You can enter this mode by pressing v. Once you have entered this mode you can use the arrow keys to select the text you wish to copy and paste. Then use y to copy, p to paste (to your desired location), and finally you may use d to cut text (or delete it).
There is a special version of vim you can get which supports X and therefore allows access to the system clipboard. But as it is easiest not to have lots of them hanging around (as the default version does not have those extended capabilities), it is good to compile from source as this person suggested.
So to do this first make sure that you have mercurial installed, and if not then install it:
sudo apt-get install mercurialOnce you are sure that that is installed get the compile-dependencies of vim:
sudo apt-get build-dep vimThen get the source with:
hg clone vim_sourceFinally we need to compile it:
cd vim_source
./configure \ --enable-perlinterp=dynamic \ --enable-pythoninterp=dynamic \ --enable-rubyinterp=dynamic \ --enable-cscope \ --enable-gui=auto \ --enable-gtk2-check \ --enable-gnome-check \ --with-features=huge \ --with-x \ --with-compiledby="Your Name <>" \ --with-python-config-dir=/usr/lib/python2.7/config
make && sudo make installPLEASE NOTE: This will install it in /usr/local, so you need to be sure that it's in your PATH before /usr so that it's used instead of the default Ubuntu version.
Then you should be able to get this working with:
"+yTo copy to the system clipboard. And:
"+pTo paste from it.
9I do not know if there is a global buffer in linux console.
I found a workaround. It is possible to copy & paste within vi or nano.
If some command, part of a command an or amended comand should be executed, I would copy it to end of file, then close the editor and run
tail -1 file.txt | bashSome line of the file can be run by
sed -n <line_number> file.txt | bashor
grep <pattern> file.txt | bashBut that does not quite answer my question. It is a kind of workaround.