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.
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.
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 gpm
Generally 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 http://www.cyberciti.biz/tips/howto-linux-configure-the-mouse-at-a-text-based-terminal-for-copy-and-paste-operation.html
or the man page
sudo /etc/init.d/gpm start
.
In bash, it is possible to edit the current command in an editor, by pressing CtrlxCtrle.
So:
VISUAL
and EDITOR
variables).bash-fc-xxxxxxxx
).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 mercurial
Once you are sure that that is installed get the compile-dependencies of vim
:
sudo apt-get build-dep vim
Then get the source with:
hg clone https://vim.googlecode.com/hg/ vim_source
Finally 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 <[email protected]>" \
--with-python-config-dir=/usr/lib/python2.7/config
make && sudo make install
PLEASE 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:
"+y
To copy to the system clipboard. And:
"+p
To paste from it.
vi
and vim
better than me and would understand...
I 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 | bash
Some line of the file can be run by
sed -n <line_number> file.txt | bash
or
grep <pattern> file.txt | bash
But that does not quite answer my question. It is a kind of workaround.