How to copy a line of text in terminal using keyboard only? - visual-studio-code

I am coding in the terminal of VS Code. When I manage to make a line of code that I like, I would like to copy it and paste to the editor. How can I copy the current line from the terminal with keyboard only without using mouse?
Edit1: I am using windows

Press arrow up to get the line of code that you want. Then press CTRL+A to select it and CTRL+C to copy it into clipboard. Paste it with CTRL+V.

Allow users to do copy paste in the integrated terminal using ctrl+c, ctrl+v.
In addition to ctrl + shift + v you can use ctrl + shift + c to Merge-Copy. And ctrl + shift + x to Merge-Cut. Select clipboard to paste ( ctrl + alt + v ). Paste and cycle through clipboard items ( ctrl + shift + v ).

Related

How can i switch windows in vscode quickly

I just find it is very hard to switch windows.Is there any tool or key-Binding ?
I already find some material on vscode site.
Each window has his own shortcut key, you cant use to switch windows using only one key. You can use their predefined keys to switch between windows.
Probably the most common are:
switching to the sidebar Ctrl + b
Selecting files in sidebar Ctrl + Shift + e
switch to terminal Ctrl + `
Opening the folder Ctrl + K O
Switching to files Ctrl + 1 for first file Ctrl + 2 for second and so on
You can find this link here for complete keybinding for VS Code

Select all text between quotes in VS Code?

I had to reinstall VS Code recently, I rember using Ctrl+W to kind of smart select everything between quotes but now what that command does is move me to another file/tab instead? Is there a way to do this in VS Code, Ctrl+W was just so easy to me, really helped with deleting or copying strings of text.
As #Mark says in the comment, you can use the "Expand Selection" shortcut, this will first select everything between the quotes.
The shortcut on Windows by default:
Shift + Alt + →
And OS X:
Ctrl + Shift + ⌘ + →
Try using the Quick and Simple Text Selection extension.
On a Mac, the extension's default shortcut is ⌘ k, "
Press ⌘ and k
let go of of ⌘ and k
press "
This will select everything in double quotes.
If you want to select everything in single quotes use ⌘ k, "
It also works for brackets
⌘ k, [
⌘ k, {
⌘ k, (
On Windows, replace ⌘ with Ctrl
https://github.com/dbankier/vscode-quick-select
Shift + Alt + (Right Arrow) for the word next to cursor
Shift + Alt + (Right Arrow)x2 for entire sentence between quotes
After re-reading your question, I noticed that you want to press Ctrl + W to press multiple times to expand your selection
To see and set the shortcut, you can
Press Ctrl/Cmd + Shift + P
Go to Keyboard Shortcuts by typing Preferences: Open Keyboard Shortcuts
Search for the command: editor.action.smartSelect.expand
Double click the keybinding to set a new keybinding
Summary of answers
Most use cases: use #colinD's answer (Alt + Shift ← or →) which expands the selection word by word
Press Ctrl + Shift + → multiple times to expand the selection's scope
it might be different on Windows
If you want to select all of the text in quotes and there's a lot of spaces and your cursor is in the middle of the quotes
Use the Quick and Simple Text Selection extension
The best / simplest way to do it I've found on Mac is to click the text anywhere in the quote marks, then hold down Control + Shift and tap the right arrow twice.

Keyboard shortcuts for Copy/Paste disabled when using vim extension

I am using VisualStudioCode with the extension VsCodeVim Version 1.10.2.
Ctrl + v is mapped to select region and I don't know what Ctrl + c does. It does not change the copy buffer, because when I paste into another application, it pastes the ??previous?? clipboard contents.
I was able to copy/paste with the Edit-Menu and Right-Click menu. So my question is:
How can the keyboard shortcuts for copy/paste be accessed/enabled?
Adding the following lines to your settings.json disables the handling of Ctrl + C, Ctrl + V and Ctrl + X by VsCodeVim.
"vim.handleKeys": {
"<C-c>": false,
"<C-v>": false,
"<C-x>": false,
},
Without these lines Ctrl + C works for me when selecting words via 'VISUAL' mode. I can now use Ctrl + V to paste the clipboard into any other editor. Or I can use Ctrl + Shift + V to paste into VsCode Editor without entering 'INSERT' mode.
But when in 'INSERT' mode Ctrl + C will not work, since Ctrl + C will normally abort any commands. Ctrl + V on the other Hand works as usual.
Note: I tested this with Visual Studio Code Version 1.38.1 and VsCodeVim Version 1.10.2
You have to be in INSERT mode, for Ctrl-Shift-v to paste.
From normal mode, Ctrl-v enters block visual mode, if you want char or line visual mode you use v and Shift-v respectively... Then presumably copy and cut with Ctrl-Shift-(c/x) would work.
Alternatively you can try this suggestion.

How to comment multiple lines in Visual Studio Code?

I cannot find a way to comment and uncomment multiple lines of code in Visual Studio Code.
Is it possible to comment and uncomment multiple lines in Visual Studio Code using some shortcut? If yes, how to do it?
Windows: Shift+Alt+A
Linux: Shift+Ctrl+A
Here you can find all the keyboard shortcuts:
Windows VSCode Shortcuts
Linux VSCode Shortcuts
PS: I prefer Ctrl+Shift+/ for toggling block comments because Ctrl+/ is shortcut for toggling line comments so it's naturally easier to remember. To do so, just click on the settings icon in the bottom left of the screen and click 'Keyboard Shortcuts' and find "toggle block...". Then click and enter your desired combination.
First, select the lines you want to comment/uncomment (CTRL+L is convenient to select a few lines)
Then:
To toggle line comments, execute editor.action.commentLine (CTRL+/ on Windows)
or
To add line comments, execute editor.action.addCommentLine (CTRL+K CTRL+C)
To remove line comments, execute editor.action.removeCommentLine (CTRL+K CTRL+U)
or
To toggle a block comment, execute editor.action.blockComment (SHIFT-ALT-A)
See the official doc : Key Bindings for Visual Studio Code
How to comment out multiline / single line in VS Code:
MacOS:
Shift + Option + A:
/* multiline
comment */
CMD + /:
// single line comment
Windows:
Shift + Alt + A:
/* multiline
comment */
CTRL + /:
// single line comment
How to remap / change these shortcuts?
Windows: File > Preferences > Keyboard Shortcuts.
MacOS: Code > Preferences > Keyboard Shortcuts.
You can search through the list both by keybindings (key names) and command names.
Read: How to set shortcuts from another text editor (Sublime, Atom etc)?
Official docs: Key Bindings for Visual Studio Code
The keyboard shortcut to comment multiple in Windows is shift+alt+A.
In my case, Ubuntu, the shortcut is ctrl+shift+A.
You can see all available keybindings on the official documentation.
Here's the relevant bit for osx:
Key Command
⌘K ⌘C Add Line Comment
⌘K ⌘U Remove Line Comment
⌘/ Toggle Line Comment
⇧⌥A Toggle Block Comment
You will need to select the lines you want to comment first, then execute above shortcut, i.e. ⌘/ on osx Ctrl/ on Windows.
In MacOS comment out multi-lines in Visual Studio Code by keyboard shortcut:
Option + Shift + A
/*
...
...
*/
Or,
Select all lines and then press CTRL + /
Try option 1 first. If it doesn't work for you then try option 2 which is the actual shortcut for VS Code:
Option 1. Alt / Option + Shift + A
Option 2. While the text is selected hit Ctrl / Cmd+K and then Ctrl / Cmd+C.
As of now (version 1.16.3), you can check all available keyboard shortcuts by going into
File > Preferences > Keyboard shortcuts. Here you can search for shortcuts related to code comments.
For users who are coming from Sublime Text or likes to have Ctrl+Shift+/, you can make the change from the above mentioned settings panel or simply install the Sublime Text Keymap extension by Microsoft.
Update: As VS Code has become pretty much standard editor for almost everything these days, I would say picking option 1 is always helpful.
For my keyboard layout it's Ctrl + § for:
//
//
//
And Shift + Alt + A for:
/*
...
*/
For me to comment I use:
Ctrl + k, Ctrl + c
and to uncomment:
Ctrl + k, Ctrl + u
I am using ubuntu 18.0.4
To comment multiple line on visual code use
shift+alt+a
To comment single line use
ctrl + /
Select all line you want comments
CTRL + /
Win10 with French / English Keyboard CTRL + / , ctrl+k+u and ctrl+k+l don't work.
Here's how it works:
/* */ SHIFT + ALT + A
// CTRL + É
É key is next to right Shift.
All the key board shorcuts for VS code can be found in the link : Link
Add a Line comment Ctrl+K Ctrl+C
Remove a line comment Ctrl+K Ctrl+U
More shortcut Ctrl+/
On Windows 10 you can use CTRL + } to comment/uncomment on any line or block of code.
CTRL + SHIFT + A for CSS multiline
Ubuntu 16
VSCode Version 1.17.2
For multiline commenting in Python VSCode, all you have to do it just:
Ctrl + /
If you are using VSCode in a linux environment, then you can comment multiple lines by either:
Selecting a block of code => then, press Ctrl + Shift + A (Block commenting)
Or, selecting a block of code => then, press Ctrl + / (Single-line commenting applied to all selected lines)
Hope this helps.
In the new version of VSCODE ( version 1.26.1)
Go to File > preferences > Keyboard Shortcuts
Search for comment Double click the existing shortcut 'keybinding`
And press the new keyboard shortcut in my case ctrl + shfit + /
You can assign any shortcuts you want. Hope it helps.
You can find the shortcut in the Edit menu :
Edit > Toggle Block Comment => Shift-Alt-A
visual studio 2017 we do a: Comment Selection
Ctrl+K, Ctrl+C
press Ctrl+K to get shortcut. press Ctrl+C to confirm
http://visualstudioshortcuts.com/2017/
For doing on mac: CMD + Shift + 7
For me it was ctrl + ' (I am using a swedish layout for the keyboard). Hope that helps anyone.
Select lines which you want to Comment
Then press Ctrl + / to make selected lines comment
And to uncomment:
Select the commented lines you which want to uncomment
First press Ctrl + K then Ctrl + Uto make commented lines uncomment
In windows you need to press ctrl + / in mac you can do ⌘ + / to make multiple comment
// public function index()
// {
// $badgeIcon = BadgeIcon::all();
// return $this->showAll($badgeIcon);
// }
Then if you want to un-comment then select the lines again and then press ctrl + /(in windows) again ⌘ + /(in mac).
If your Ctrl+/ isn't working maybe you need to change it to Ctrl+NumPad_Divide.
1.Select the text, Press Cntl + K, C to comment (Ctr+E+C )
2.Move the cursor to the first line after the delimiter // and before the Code text.
3.Press Alt + Shift and use arrow keys to make selection. ...
4.Once the selection is done, press space bar to enter a single space.
Multi-Line Comment in VS Code
To comment the code select the lines and hit: Alt + Shift + A
To Uncomment select the commented code and hit: Alt + Shift + A
For windows, the default key for multi-line comment is Alt + Shift + A
For windows, the default key for single line comment is Ctrl + /
CTRL + SHIFT + A
For Red Hat,centos
Select item
then CTRL+SHIFT+A

Eclipse: how to switch between console window and editor?

I'm using Eclipse for Python and R development. How can I jump between editor tab and console window using a keyboard shortcut / hotkey?
Go view Console: Shift + Alt + Q + C
You can switch to Editor using Ctrl + F7.
Ctrl + Shift + L displays all the shortcuts in Eclipse.
I've found the following works:
Toggle between views: Ctrl + Shift + F7
Switch Editor: Ctrl + Shift + F6
Go to R Console (In StatET perspective): Ctrl + R, C
However, the first two are not a direct route back to the editor and require use of the arrow keys and Ctrl + 7 does not work for me. Any other ways to go directly back to the last editor used?
For RStudio:
Ctrl+1 : focus to source
Ctrl+2 : focus to console
More shortcuts are mentioned under the 'View' menu.