Selecting text in terminal without using the mouse - linux

If I'm working in a terminal window in Linux, is there a keyboard shortcut I can use to select output displayed on previous lines? If I select something with the mouse I can copy using Ctrl + Shift + C, but is there a way to select without using the mouse at all. I'm using either Gnome terminal or KDE konsole in Ubuntu desktop.
For example I often need to copy results from a mysql query and then google them.

You can use the screen application and enter copy mode with Ctrl+a, Esc. Start selecting text with Space and end selecting text with Space. Insert text with Ctrl+a, ]

Daniel Micay's Termite sports a "selection mode". Pressing Ctrl+Shift+Space will activate it. It's got vim-like key bindings. v or V will select à la vim's visual mode, y will yank, Esc will exit selection mode.

Screen and Emacs M-x shell, for example, allow for keyboard access to the scrollback buffer. This was also one of the features of Plan 9 (but I guess it was mouse-oriented, at least primarily); you might want to take a look at 9term and/or Sam, the Plan 9 editor.

You can to it at terminal:
1 - Move the cursor to the beginning of line using ctrl + a
$ touch test.txt
2 - Copy the line to the paste area ctrl + k
3 - Finally, you can past it ctrl + y
$ touch test.txt
4- You can do it in a single word or more just using crtl + ← or crtl + → and use crtl + k at word's beginning.

$ emacs -g '80x24' --eval '(term "/bin/bash")'
C-c C-k char mode
C-c C-j line mode
C-space Selecting text in terminal without using the mouse
M-w copy to X11 clipboard
C - Ctrl
M - Alt

Related

How to copy and paste in Vim's terminal mode?

I often want to copy text from a :terminal window to a normal text buffer. At the moment I exit the shell session and copy from the history.
There must be a better way to this.
Copy
To copy from a terminal window press CTRL-W N (This is a capital N)1 or CTRL-\ CTRL-N (this is not a capital N) to get into normal mode. From there you can use all usual vim commands to copy and paste stuff.
Entering insert mode will drop you back to your shell.
Paste
To paste from a register into the terminal window you have to be in Terminal-Job ("insert") mode.
Press CTRL-W " followed by the register.
:help Terminal-mode tells us:
When the job is running the contents of the terminal is under control of the
job. That includes the cursor position. Typed keys are sent to the job.
The terminal contents can change at any time. This is called Terminal-Job
mode.
Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the
contents of the terminal window is under control of Vim, the job output is
suspended. CTRL-\ CTRL-N does the same.
[...]
In Terminal-Normal mode you can move the cursor around with the usual Vim
commands, Visually mark text, yank text, etc. But you cannot change the
contents of the buffer. The commands that would start insert mode, such as
'i' and 'a', return to Terminal-Job mode.
See :h terminal-typing for more useful commands in terminal windows.
1Unfortunately the vim help doesn't tell you that it is a capital N, I kept the original notation
Can use Shift+Insert as a shortcut to paste from the clipboard into a running terminal session. Setup the mapping like
:tmap <S-Insert> <C-W>"+
The will result in pasting from the + register. Alternatively use the * register which sometimes works better in MS Windows.
Set the clipboard setting in your .vimrc to using system clipboard as the Vim's clipboard. Depends on your OS it may differ, assume you are using Mac OS: set clipboard=unnamedplus
Then you can use y command to copy then paste on another app just by Cmd + V, remember to exit the insert mode of the terminal by clicking any where or press Ctrl+\ Ctrl+n

IntelliJ Column Selection using Cursor Keys

Is it possible to some how setup IntelliJ IDEA so that I can column select with the cursor keys similarly to how I might in Notepad++, Visual Studio, or FlashDevelop.
For instance when I'm typing code I almost always do my navigation solely through use of the keyboard. In the IDEs mentioned previously I can quickly select blocks of code by holding Shift + Alt then tapping ↑ to extend my cursor across the lines above. I can then hold Shift + Alt + Ctrl and tap ← or → to quickly jump across words and select the chunk of text I want.
In IntelliJ IDEA I have to constantly enable and disable Column Selection Mode using the Shift + Alt + Insert and even then it doesn't quite function as it does in the other IDEs or Text Editors.
Any ideas?
You can do column editing using the Edit | Column Selection Mode.
The shortcut to turn it on/off is Alt+Shift+Insert. You navigate with arrow keys to select blocks of text.
Multiline Caret (without mouse)
Windows/Linux: CTRL + CTRL(Hold) + ↑ / ↓
Mac: ⌘ + ⌘(Hold) + ↑ / ↓
ESC will end multiline mode.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
It is also possible to select holding middle mouse key.
Go to the Settings | Keymap and set a shortcut for Clone Caret Above and for Clone Caret Below
Most convenient way is to:
MAC: Hold Option+Shift and click with mouse.
Windows: Hold Alt and click with mouse.
On a mac, to toggle block select on/off:
shift command 8
⇧⌘8
For me on Mac:
Press once 'option' key, release it, and press and hold it again.
Now navigate with cursor to select desired code.
Press 'Esc' to exit column mode! :)
I think #Meo's answer is the most correct, but if your hand happens to be on the mouse, you can also accomplish this with Ctrl+Alt+Shift+Left Mouse Button Click. Or look for the Add Rectangular Selection on Mouse Drag in the keymap settings.
In Windows or Linux I press two times Ctrl
For Mac cmd+shift+* didn't work for me. I changed the keymap to something else and now it works seamlessly.

how to paste to vim when using putty

I am using putty to connect a remote host and editing via vim. I meet a trouble when I try to paste something to vim. That's, I copy something to clipboard in my local host and want to paste it to the vim in the remote host. How to do that?
ps: I am using putty! So, I open a vim window via putty. The very need is that I want to copy something in my local host and paste it to the vim editor opened by putty. That's all. Thanks!
Try with Ctrl + Shift + V or with middle click with a 3 button mouse
EDIT
What about? Shift + Ins
Source : https://superuser.com/questions/180043/paste-the-windows-clipboard-into-my-putty-session-using-only-the-keyboard
You can insert text from your host’s clipboard by pressing the right mouse button (default setting) or by pressing Shift + Ins. Note that this has the same effect as entering every character manually. So if you are using auto indentation in vim, this will very likely screw up your code.
To fix that, you can do the following:
Before pasting into vim, enable paste mode by entering :set paste.
Press i to enter insert mode. The status bar should say -- INSERT (paste) -- now.
Press the right mouse button to paste in your stuff. The auto indentation of vim should not happen.
If this puts you into the -- (insert) VISUAL -- mode, exit out of it using Esc (putting you into the paste insert mode again), and try pasting it again while holding Shift using your right mouse button.
Press Esc to leave insert mode, and disable paste mode using :set nopaste again.
You can change which mouse button is used to paste in PuTTY in the Window/Selection configuration page.
In Windows Subsystem for Linux it appears that you have to:
i = to enter -- INSERT -- mode
Shift-right-mouse-click = to paste
If you just right-mouse-click (i.e. without shift) then annoyingly all that happens is that the mode changes to -- (insert) VISUAL -- i.e. it doesn't paste anything.
To clarify the other answers, there are a couple ways to do this, depending on if Vim is running with mouse support. Lets assume its via some sort of terminal/Putty:
When not using mouse in remote Vim, right clicking will paste from local clipboard via Putty into remote Vim.
With mouse enabled in remote Vim, Shift + Ins will paste from local clipboard via putty into remote vim.
Ctrl + Shift + v will paste from local clipboard via native/*nixish/xterm into remote vim.
With mouse enabled in remote Vim, middle clicking will paste from remote clipboard into remote Vim.
Copy&Paste between Windows&PuTTY:
To copy from Windows and paste into PuTTY, highlight the text in Windows, press "Ctrl-C," select the PuTTY window, and press the right mouse button to paste. To copy from PuTTy and paste into Windows, highlight the information in PuTTY and press "Ctrl-V" in the Windows application to paste it.
Copy&Past between two vim in separate PuTTY:
highlight the information in the source PuTTY, and then press the right mouse button in the target PuTTY to paste.

IntelliJ IDEA - multiple carets?

Sometimes I have to write Java class where I need to define multiple fields of the same type. For example, I know that I will need to duplicate private final String on the next 4 lines.
Is it possible to spawn multiple carets in IntelliJ editor, so I can type on mutliple lines at the sime time?
IntelliJ IDEA 14.1 & 15
You can press Alt + Shift and using the mouse left click you can put many carets.
E.g.:
will become
typing "added" only once.
If you want to have a continuous vertical line, it's enough to press Alt + drag your mouse vertically. If there are lines with a length lower than the current position, the vertical line will be broken (carets will be placed at the end of every line) if "Allow placement of caret after end of line" is disabled (in File > Settings... > Editor > General > Virtual Space).
Another way to add a continuous vertical line is to hit Ctrl twice and then press up or down arrow key (supported in JetBrains 2016.X products, and possibly earlier).
If you cannot get the shortcuts working, check what they're currently assigned to under Settings > Keymap Add or Remove Caret, Clone Caret Above and Clone Caret Below. If they look right and you're on Linux, your window manager may be capturing the combination, e.g., for Alt + window drag operations.
See:
http://blog.jetbrains.com/idea/2015/02/multiple-selections-in-editor-using-mouse/
https://www.jetbrains.com/help/idea/2016.3/multicursor.html
I think "Column Selection Mode" could help you. You can enable it in the context menu in the editor. Then you can select multiple lines and type same text at once.
Column Select
For Windows, you can use CTRL+CTRL(Hold)+↑ / ↓. For Mac, replace the CTRL with ⌘.
Change Multi-caret Hotkey
To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.
I mapped mine to ALT+SHIFT+↑ / ↓.
Bonus
Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.
On Windows:
You can enable the Column Selection Mode (Alt + Shift + Insert)
And then Shift + ↑ / ↓ can select multiple columns
Hit Esc to go back to single cursor
Add/remove a caret: Alt + Shift + Mouse Click
Remove all carets: Esc
As for now(2018.9), you just:
Press middle mouse key to create a four-rows-high caret
Type what you want
Or,
Create the first line,
Press the "Duplicate entire line" key combination to create a new, identical line.
By the way, I think "multiple caret" should be like carets enabling me to edit different locations which are not necessarily vertically aligned. In Sublime Text you can press Ctrl and click. And in IntelliJ you can only "Clone caret up/down", that is to say, they are vertically aligned, which is not flexible.

How to paste into a terminal?

I have copied a URL, such as git://gitorious.org/openhatch/oh-mainline.git. I want to paste this in the terminal using a keyboard shortcut.
Please don't say "right click and paste."
Gnome terminal defaults to ControlShiftv
OSX terminal defaults to Commandv. You can also use CommandControlv to paste the text in escaped form.
Windows 7 terminal defaults to CtrlShiftInsert
Shift + Insert usually works throughout X11.
Mostly likely middle click your mouse.
Or try Shift + Insert.
It all depends on terminal used and X11-config for mouse.
same for Terminator
Ctrl + Shift + V
Look at your terminal key-bindings if any if that doesn't work
In Konsole (KDE terminal) is the same, Ctrl + Shift + V
On windows 7:
Ctrl + Shift + Ins
works for me!
Like this article How to copy paste text and commands in the Linux terminal mentioned.
You can use middle mouse button to implement the functionality of paste. I tested it on terminal successfully.

Resources