I have a screen session where in i have created 10 sessions .
I use the below key combination to toggle to the active screen session attached.
ctrl + a + number 0 to 9
Ctrl-a 0-9 Go to a window numbered 0-9
i have created a 10th session now
ctrl-a 10 will end up to the screen session 1.
how to toggle to the 10th session ??
work around for the same is , go to the 9th session
Ctrl-a 9
and then ctrl-n will lead me to the 10th session.
Link i referred to learn screen in linux
http://www.kb.indiana.edu/data/acuy.html
Pressing Ctrl+A then ' (apostrophe) will display a prompt and let you enter the number or name of a window to switch to.
To rename a window, use Ctrl+AShift+A. (Ctrl+U to remove the old name before typing a new one.)
Other ways to switch windows include:
Ctrl+ACtrl+A to return to the window you were looking at before
Ctrl+An or Ctrl+ASpace to go to the next in sequence
Ctrl+Ap to go to the previous in sequence
Ctrl+A" to select from a list (thanks stan and dogbane!)
I think some of these can open a windows list:
ctrl+a " #window list
ctrl+a w #window list
You can use C-a " which will show you a list of all windows and you can then select the 10th one
Alternatively, go to the 9th window and then use C-a n to go to the 10th.
According to screen's manual page, you can add the following lines to your ~/.screenrc file:
bind -c demo1 0 select 10
bind -c demo1 1 select 11
bind -c demo1 2 select 12
bindkey "^B" command -c demo1
makes C-b 0 select window 10, C-b 1 window 11, etc. Alternatively, you can use:
bind -c demo2 0 select 10
bind -c demo2 1 select 11
bind -c demo2 2 select 12
bind - command -c demo2
makes "C-a - 0" select window 10, "C-a - 1" window 11, etc.
Related
i have wired situation when i try to go to the end of the word using vim
enter code hereVIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 24 2019 23:56:49)
for example when i press shift e or $ it goes to 1 char before the end of the word
for example :
Your cursor is going to the last character of the word, which is the intended behavior of $ and E.
If you want to be able to place your cursor after the last character on a non-existent end-of-line character, enable that behavior with
set virtualedit=onemore
You could also define a custom mapping or overwrite a default one to move the cursor one more forward with l as part of the motion, for example
nnoremap E El
To enter insert mode at the end of a line use A. You can also press $ and then a to enter insert mode after the next character.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
Is it possible to copy text from a file, opened with nano, to the shell?
I have a text file, and I want to copy several lines to the console, but I cannot find a keyboard shortcut to copy the text.
Nano to Shell:
1. Using mouse to mark the text.
2. Right-Click the mouse in the Shell.
Within Nano:
1. CTRL+6 (or CTRL+Shift+6 or hold Shift and move cursor) for Mark Set and mark what you want (the end could do some extra help).
2. ALT+6 for copying the marked text.
3. CTRL+u at the place you want to paste.
or
1. CTRL+6 (or CTRL+Shift+6 or hold Shift and move cursor) for Mark Set and mark what you want (the end could do some extra help).
2. CTRL+k for cutting what you want to copy
3. CTRL+u for pasting what you have just cut because you just want to copy.
4. CTRL+u at the place you want to paste.
Much easier method (for short pieces of text):
$ cat my_file
Ctrl+Shift+c to copy the required output from the terminal
Ctrl+Shift+v to paste it wherever you like
For whoever still looking for a copy + paste solution in nano editor
To select text
ctrl+6
Use arrow to move the cursor to where you want the mark to end
Note: If you want to copy the whole line, no need to mark just move the cursor to the line
To copy:
Press alt + 6
To paste:
Press ctrl + U
Reference
nano does not seem to have the ability to copy/paste from the global/system clipboard or shell.
However, you can copy text from one file to another using nano's file buffers. When you open another file buffer with ^R (Ctrl + r), you can use nanos built-in copy/paste functionality (outlined below) to copy between files:
M-6 (Meta + 6) to copy lines to nano's clipboard.
^K (Ctrl + k) to cut the current line and store it in nano's clipboard.
^^ (Ctrl + Shift + 6) to select text. Once you have selected the text, you can use the above commands to copy it or cut it.
^U (Ctrl + u) to paste the text from nano's clipboard.
Finally, if the above solution will not work for you and you are using a terminal emulator, you may be able to copy/paste from the global clipboard with Ctrl + Shift + c and Ctrl + Shift + v (Cmd + c and Cmd + v on OSX) respectively. screen also provides an external copy/paste that should work in nano. Finally if all you need to do is capture certain lines or text from a file, consider using grep to find the lines and xclip or xsel (or pbcopy/pbpaste on OSX) to copy them to the global clipboard (and/or paste from the clipboard) instead of nano.
The thread is quite old, but today I humbled around with the same question and all the mentioned solutions above did not help. As I wished to copy long lines my solution is - acording to what #themisterunknown wrote above - outside nano. I used awk!
awk '{ if (NR==87) print $0 }' filename
where NR==[line number] and $0 is complete line.
I don't know any way to do this directly in nano. However you can use "cat" or "grep" to display lines of your file in the console.
If you use a terminal multiplexer like "screen" you can copy and paste strings like this.
Simply use Ctrl+Shift+6 to copy current line or you can set mark using Ctrl+6 and copy multiple lines using above command as well.
Relatively straightforward solution:
From the first character you want to copy, hold Shift down and go all the way to the end.
Press Ctrl+K, which cuts the text from the file.
Press Ctrl+X, and then N to not save any changes.
Paste the cut text anywhere you want.
Alternatively, if your text fits into the screen, you can simply use mouse to select and it automatically copies it to clipboard.
The following works in Nano but also anywhere in a terminal:
Copy text from a terminal, after selecting with your mouse: Ctrl + shift + C.
And to past text in to a terminal: Ctrl + shift + V.
The copy buffer can't be accessed outside of nano, and nowhere I found any buffer file to read.
Here is a dirty alternative when in full NOX: Printing a given file line in the bash history.
So the given line is available as a command with the UP key.
sed "LINEq;d" FILENAME >> ~/.bash_history
Example:
sed "342q;d" doc.txt >> ~/.bash_history
Then to reload the history into the current session:
history -n
Or to make history reloading automatic at new prompts, paste this in .bash_profile:
PROMPT_COMMAND='history -n ; $PROMPT_COMMAND'
Note for AZERTY keyboards and very probably others layouts that require SHIFT for printing numbers from the top keys.
To toggle nano text selection (Mark Set/Unset) the shortcut is:
CTRL + SHIFT + 2
Or
ALT + a
You can then select the text with the arrows keys.
All of the others shortcuts works fine as the documentation:
CTRL + k or F9 to cut.
CTRL + u or F10 to paste.
Select the text in nano with the mouse and then right click on the mouse.
Text is now copied to your clipboard.
If it does not work try to start nano with the mouse option on :
nano -m filename
First method
This method seems to work when the content doesn't include ●.
Install xsel or similar and assign a global shortcut key for this command in your WM or DE:
xsel -o | sed -r 's/^ ?[[:digit:]]+($| +)//g' | perl -pe 's/\n/●/g' | sed -r 's/●●/\n\n/g; s/ ?● {1,}/ /g; s/●/\n/g' | xsel -b
Put this in your ~/.Xresources:
*selectToClipboard: false
Issue this in your xterm once to activate the above option:
xrdb -load ~/.Xresources
Now select the line(s) including the line numbers by pressing Shift while dragging the mouse. After the selection click your key combo; the line(s) are coppied and ready to be pasted anywhere you like.
Second method
Doesn't have the shortcoming of the first method.
Install xdotool and xsel or similar.
Put these two lines
Ctrl <Btn3Down>: select-start(PRIMARY, CLIPBOARD)
Ctrl <Btn3Up>: select-end(CLIPBOARD, PRIMARY)
in your ~/.Xresources like so:
*VT100*translations: #override \n\
Alt <Key> 0xf6: exec-formatted("xdg-open '%t'", PRIMARY, CUT_BUFFER0) \n\
Ctrl <Key>0x2bb: copy-selection(CLIPBOARD) \n\
Alt <Key>0x2bb: insert-selection(CLIPBOARD) \n\
Ctrl <Key> +: larger-vt-font() \n\
Ctrl <Key> -: smaller-vt-font() \n\
Ctrl <Btn3Down>: select-start(PRIMARY, CLIPBOARD) \n\
Ctrl <Btn3Up>: select-end(CLIPBOARD, PRIMARY)
Issue this in your xterm once to activate the above option:
xrdb -load ~/.Xresources
Create this scrip in your path:
#!/bin/bash
filepid=$(xdotool getwindowpid $(xdotool getactivewindow))
file=$(ps -p "$filepid" o cmd | grep -o --color=never "/.*")
firstline=$(xsel -b)
lastline=$(xsel)
sed -n ""$firstline","$lastline"p" "$file" | xsel -b
Assign a global shortcut key to call this script in your WM or DE.
Now when you want to copy a line (paragraph), select only the line number of that line (paragraph) by right mouse button while pressing Shift+Ctrl. After the selection click your custom global key combo you've created before. The line (paragraph) is coppied and ready to be pasted anywhere you like.
If you want to copy multiple lines, do the above for the first line and then for the last line of the range, instead of Shift+Ctrl+Btn3 (right mouse button), just select the number by left mouse button while pressing only Shift. After this, again call the script by your custom global shortcut. The range of lines are coppied and ready to pasted anywhere you like.
M-^ is copy Text. "M" in my environment is "Esc" key ! not "Ctrl";
so I use Esc + 6 to copy that.
[nano help] Escape-key
sequences are notated with the Meta (M-) symbol and can be entered using
either the Esc, Alt, or Meta key depending on your keyboard setup.
1) Ctrl + 6 to mark the text that you want to copy
2) Ctrl + k to cut the text and Ctrl + u to paste back to the original place
3) Go to the desired line where you want to paste the code marked in step (2). Ctrl + u to paste it.
Hope it helps.
First off, I'm using Opensuse 13.2 64-bit and also Arch_Linux 64-bit
Can't get the bind to work for either of them (well, the binds that I want), but I'm mostly focused on the Arch_Linux. Also, using openbox wm, xfce4-terminal. ( in opensuse using konsole and gnome 3) and my $TERM is set to xterm-256color in my ~/.bashrc and is switched to screen-256color when using screen in opensuse, but strangely is not changed in Arch.
I want to bind C-a down: to focus down, C-a up: to focus up, C-a left: to focus left etc.. Lets just focus on focus down for the moment.
I've tried everything in my ~/.screenrc file
bind "\E[B" focus down
bind "\EOB" focus down
bind "^[[B" focus down
bind "^[OB" focus down
bind "\033[B" focus down
bind "\033OB" focus down
bind "\033\133\102" focus down
bind j focus down # works fine
Nothing catches the down arrow key. I CAN use the following
bind -k kd focus down
however, I also want to bind multiple keys using the arrows and AFAIK the -k option only allows binding 1 key (or shift + left/right) . Actually I'm lucky I can even use the -k option since it is not documented.
Now I've checked my kd (termcap) and kcud1 (terminfo) using infocmp
infocmp -1 | grep kcud1
kcud1=\EOB,
infocmp -1C | grep kd
:kd=\EOB:\
and BTW these symbols can be looked up here for termcap and here for terminfo and its termcap equivelancies (actually I guess you can just use: man terminfo)
when I use Ctrl-v and press down arrow I get
^[[B
showkey -a
^[[B 27 0033 0x1b
91 0133 0x5b
66 0102 0x42
Anyone know how to go about this. I want to know why I can't use bind without the -k termcap_name and/or how to use combo of keys(such as ctrl/alt) and termcap names. Thanks for all and any info.
I've tried setting termcapinfo also with no luck. don't think I'm using it right.
termcapinfo * kd=\EOB
bind "\EOB" focus down
termcapinfo * kd=\E[B
bind "\E[B" focus down
etc...
It appears that GNU screen doesn't permit binding sequences of multiple keys.
Quoting the man page:
bind [-c class] key [command [args]]
Bind a command to a key.
...
The key argument is either a single
character, a two-character sequence of the form "^x" (meaning
"C-x"), a backslash followed by an octal number (specifying
the ASCII code of the character), or a backslash followed by a
second character, such as "\^" or "\". The argument can also
be quoted, if you like.
...
As said in this answer, try:
bindkey "^A^[OB" focus down
The vim trick is really helpful to get the code for the combinations you want (for example, if you wanted the combo Ctrla Ctrldown instead of Ctrla down, this would be ^[[1;5B instead of ^[OB).
Credit should go to koyae for the original answer.
How to copy a specific line from less ? Lets say I am opening a man ( which is by default opened by less ) and want to select and copy it to clipboard and after that lets say paste it to file opened in vim ? I don't want to use the mouse wheel to paste. I am looking for a simple Ctrl-c , Ctrl-v method as in windows.
When opening a man page I can't switch to my default editor (which is vim ) with 'v' key because less shouts with "Cannot edit standard input" error.
Thanks a lot and sorry if this question is silly.
tl;dr, use m and |.
Example:
Within the man page of less, by running man less:
7g
mx
6g
|x
xclip (Linux) or pbcopy (macOS), to copy to clipboard.
cat > file, to save to file, or cat >> file for append mode.
We would get:
less - opposite of more
The key things to learn are just two less commands: m (mark), and | (pipe).
Command m (mark)
Followed by any lowercase letter, marks the current position with that letter.
The marker we used above is x, as in step 2, it marked line 7 with x.
Command | (pipe)
| <m> shell-command
<m> represents any mark letter. Pipes a section of the input file to the given shell command.
The section of the file to be piped is between the first line on the current screen and the position marked by the letter.
<m> may also be ^ or $ to indicate beginning or end of file respectively. If <m> is . or <newline>, the current screen is piped.
Using |xpbcopy, we pipe the line-range [7, 6] into pbcopy, as line 6 is currently the first line on the screen, and line 7 is the one we marked as x, and pbcopy is the command to put text into the macOS clipboard.
Alternatively, use xclip on Linux, or even dd of=/path/to/file to save as a file.
Note
The text range is boundary inclusive, so both the beginning and the ending lines of the range, or at least 2 lines are copied.
We marked the range in the backward way, namely from bottom to top, otherwise, less might behave awkwardly, and throw the whole screen through the pipe.
I think I found the solution: it is using tmux. Tmux provides it's own clipboard ( correct me if I am wrong ). From tmux I can enter the copy-mode wherever I am ( in MAN pages, less, console output ) and let me to copy the content.
The current accepted answer is based on setting a mark, navigating one line up, piping the current screen up to that mark into the clipboard.
Copy 1 line into clipboard
Navigate to the line (using 1g to go the first line)
|
Press RETURN
head -1 | clip (or xclip et. al)
head -1 | tr '\n' '\' | clip
Explanation
| pipes the whole screen into the command, so navigate to where we want that to start.
2-3. | <m> shell-command if <m> is . or newline, the current screen is piped.
head -1 just the first line
| tr '\n' '\' replace the the carriage return with \ (for pasting to shell)
| clip pipe to clipboard (or /dev/clipboard, xclip et. al)
Short answer: Ctrl+C and Ctrl+V are associated with other actions. For instance Ctrl+C sends an interrupt signal to the foreground process. Usually you need to use Ctrl+Shift+C and Ctrl+Shift+V in order to copy and paste from a terminal.
Long answer: This very good thread from superuser.
I want to initiate those commands automatically when attaching a screen:
Ctrl+a |
Then
Ctrl+a TAB
Then
Ctrl+a :resize 15
Anyway to do this in one command line?
You can put respective commands at the end of your ~/.screenrc file and they'll get executed every time you start screen. In case you'd like this happen only occasionally, you could create a special screenrc-file, e.g. ~/.screenrc.special and then run screen with screen -c ~/.screenrc.special when you want these things to happen.
Your ~/.screenrc in this case should have as last three lines this:
split
focus
resize 15
Split now supports the -v option
split -v
focus
resize 15