Is there a keyboard shortcut or an extension that would allow me to select a block of code?
I'd like to select everything between curly braces, between HTML tags, etc.
Use Alt + Shift + → to expand the selection between braces or tags.
Use Alt + Shift + ← to shrink the selection between braces or tags.
Here is the Microsoft Visual C++ shortcuts cheatsheet that might help you.
Update 2019/3: this inner functionality of Visual Studio is not working very well after some updates. Alt + Shift + → now selects things including braces (which annoys me).
It is not like its behavior before. It selected things between curly braces, when I first posted this answer. I'm using Mark's answer now.
If anyone has a better solution (without an extension) now, please leave a comment.
On Mac Ctrl + Shift + → to expand the selection. Press multiple times to expand to the block.
Try the expand-region extension. It currently works for JavaScript and HTML. To select ever-increasing or decreasing scope.
A quicker way is selecting a line then expanding the selection like this:
Select line Ctrl + L
Expand selection Alt + Shift + →
Doing this inside a block (HTML element, JavaScript curly braces) will select the inner block (HTML element content, inside curly braces). Do step 2 again to select block including the container (HTML element, whole function, class, etc.)
In Visual Studio Code, there is a new option called Balance. First you can place the cursor in a suitable block. After that, you can press Ctrl + Shift + P. Type balance and it lists like below.
Now press Enter, it will select the related code block like below.
For simple use, you can add a shortcut key binding.
A real working solution:
Press Command + P and search for Select to Bracket
To bind it to a key, press the little Settings icon on the right. The "Keyboard Shortcuts" Window will appear as shown in the image. Double-click on Select to Bracket and press a Keyboard shortcut you like, for example Command + Shift + H.
Now, whenever you want to select code in a block, put your cursor inside the block and press your shortcut.
It is like magic.
⌃⇧⌘← or ⌃⇧⌘→is also useful for this purpose.
A real working solution:
Search for Select to Bracket and bind it to whatever keys you like.
It is like magic.
If you are using Java in Visual Studio Code and you don't want your block selection to include the brackets (or any other peripheral character) then do the following:
Go to Visual Studio Code settings by pressing Ctrl + ,.
Search for "Java selection range" and deselect it.
Related
When I place my cursor at any position inside a text like the string in this photo, vs code automatically mildly highlights the entire string. Is there any shortcut key for selecting and copying this entire text highlighted by vs code?
Example: String being mildly highlighted by vs code How to select/copy this with a keyboard shortcut?
Update:
Added gif to show the highlighting - gif showing the highlighting
There's not a single, builtin keyboard shortcut for the behavior you described, but you can use a combination of two to achieve the result you want:
The first is called "Expand Selection" in the VS Code app, and the online keybindings documentation describes it as "Expand AST Selection" (editor.action.smartSelect.expand). The default platform keybindings for this are:
linux: shift + alt + right
mac: shift + ctrl + cmd + right
win: shift + alt + right
If the highlighted string is one word, it will require one use, and if the string is multi-word, it will require two uses.
After that, the selection will be complete, and you can simply copy (cmd/ctrl + c).
Demo:
If in a string, triggering the command editor.action.smartSelect.grow a couple of times should select that entire string. And then you can copy the normal way Ctrl+C.
That command is unbound by default. You can assign a keybinding to it in the Keyboard Shortcuts editor by searching for smartSelect and click on the little pencil icon next to the command.
How to select the current word, that is where the caret is at.
Note: I am looking for the shortcut for Visual Studio Code(VS Code), the text editor, and not Visual Studio IDE.
On Mac OS: Cmd+D
On Windows & Linux: Ctrl+D
Above solved the purpose for me.
But ⌘D is defined as "editor.action.addSelectionToNextFindMatch", so if you press it more than once, it will try to search and select same word in the file which then can be used to do "multi word editing".
You are looking for Shrink/Expand Selection.
Trigger it with Shift+ Alt+Left and Shift + Alt+Right
Update:
This is now called Smart select API.
This feature uses semantic knowledge to intelligently expand selections for expressions, types, statements, classes, and imports.
It is Ctrl + D that works for me in latest Visual Studio Code on Windows.
Go to File -> Preferences -> Keyboard shortcuts, you will find this:
If you want to ctrl+w to behave the same as in Idea just go keyboard settings
Search for Expand selection. Set new shortcut cmd+w or ctrl+w depending on your OS.
Also re-bind other commands that use ctrl+w to use another shortcut that you want, for example cmd+f4
You can edit keybindings.json to avoid using UI.
Shift + Alt+Right Arrow if the word is in camelCase then you will have to click Right Arrow again to select the whole camelCase. Every time you press Right Arrow again while still holding Shift + Alt down you will select a further part of the code.
so:
first the word.
then if it's part of a camelCase then the camelCase.
then if it is in a string the whole string.
... (many other posibilities)
the whole line.
everything inside the parentheses code block
the whole file
at any given time you can go back to the last selection by clicking Left Arrow instead of Right Arrow
I don't know about CTRL + w in the old Visual Studio Code but in the JetBrains IDE's this is the equivalent to CTRL + w by holding down CTRL and clicking w to select more and holding down CTRL + Shift and clicking w to unselect.
Another possibility which helps to avoid selecting only one word in camelCase is CTRL + d this will just select the whole camelCase. This will however have the side-effect of also changing the current "find" criteria.
thanks Chandan Nayak for this extra shortcut.
An unpopular opinion: you can now have Resharper keybindings, if you come from Jetbrain's camp.
The Ctrl+W expansion grow and shrinks is different from expansion selection.
On "File/Preferences/Keyboard Shortcuts" I deleted the shortcut "Ctrl + W" to close the current tab action, because for this "Ctrl+F4" works for me.
Update (14 days later): Yesterday I installed VSCode 1.34.0 - I think since then the functionality is "Ctrl + D". I was very suprised.
For any editor, you can use the below shortcuts. These shortcuts work for every text area also.
Ctrl + Shift + LeftArrow/RightArrow - this will select text word by word
Shift + UpArrow/DownArrow - this will select text line by line
Ctrl + BackSpace - this will delete text word by word
Additional
in intellijIdea
Ctrl + w - use for the select current word, after giving second Ctrl + W it will select the second word also. Like that you can select the whole line.
Ctrl + d - you can duplicate current line.
With Visual studio Code if I'm in the middle some quote/braces/brackets/parenthesis is there a way to jump to after end of the current block?
Eg.
If
it allows me jump to the end of the quote
Or from:
to
April 2020 Update
Yes, use Ctrl+Shift+\, (or ⇧ + ⌘ + \ on Mac) to jump to closest bracket. If cursor is currently in-between the brackets, first it will jump to closing bracket, each consequent press will jump between opening and closing brackets.
You can reassign the binding to your liking in Keyboard Shortcuts using editor.action.jumpToBracket command.
Use ctrl+right it triggers the cursorWordEndRight command.
It moves the cursor by whole words. These "words" include spaces, parenthesis, commas and the likes.
You can modify the keybinding shortcut to what you desire.
I personally use ctrl+alt+space for now.
It's not perfect but it's the best alternative I have currently.
The TabOut extension doesn't do exactly what you're describing (I think), but comes very close.
Note: I'm still trying it out so I'm not sure if I like Tab meaning different things depending on the context, but so far it's getting me pretty close to what I want.
use Ctrl + Enter in Windows 10 if you want get outside and go downline. or Ctrl + Shift + Enter if you want get outside and go upline.
Finally find out on Mac to jump to closing bracket/parenthese :
⌘ + ⇧ + £
Anyone know of a set of hotkeys that can perform a find/replace in eclipse?
Currently the flow looks like:
Select line or lines
Ctrl+F
Type phrase
TAB
Type replacement
And then I have to do the unthinkable and grab my mouse, choose selected lines and then click on replace. It doesn't sound like much, but it seriously disrupts my flow when i'm doing a bunch of word replacement. I wish their was a way to choose "selected lines only" and "replace all" using keystrokes only besides having to hit TAB 12 times. Or maybe i'm using the wrong tool within eclipse for this sort of thing...
Using Ubuntu and Eclipse Luna 4.4.2
Using Find/Replace for refactoring seems like a smell. You should instead use the refactoring operations
Rename : Alt + Shift + R
Extract constant : Alt + Shift + K
Extract method : Alt + Shift + M
Extract variable: Alt + Shift + L
Inline : Alt + Shift + I
Change method signature : Alt + Shift +C
Introduce indirection
Introduce parameter object
and so on, which all do a kind of replacement by themself, but always work on the syntax tree and not on the text. However, the refactoring support depends much on the language used in the project, and while Java has really good support in Eclipse, this might not be the case for other languages.
I had been trying for this for a long time and ended up in multiple pages without help. I figured it out myself after playing around
For the first time, you need to do the below
Ctrl + F - to open the search box on the top right corner of the IDE (as in image)
You might have to drill down (using the small icon on the left of the search box) to see the replace text
This setup stays from now onwards.
Now you can simply use
Ctrl + F, Tab, Alt+Shift+Enter combinations to do the search and replace
I use eclipse 2020-03 on windows. I am pretty sure many of the previous releases had the same functionality on linux as well.
Screenshot of the feature:
I found thath ctrl+K works in my ide (Neon.3 Release (4.6.3) on windows)
First use Ctrl+f to set a term for search, then use ctrl+K to move to next.
If you need to replace something, keep in the clipboard the text and use ctrl+K, ctrl+v.
It's so easy to select a block of code and tab out, but how about the reverse?
Currently, I just search and replace for white space at the beginning of the line. Is there anything faster?
In Visual Studio and most other half decent IDEs you can simply do SHIFT+TAB. It does the opposite of just TAB.
I would think and hope that the IDEs you mention support this as well.
Shift-tab outdents again :)
The standard shortcut keys are covered in Standard Accelerators.
You'll find many of the more esoteric ones on FAQ What editor keyboard shortcuts are available?.
Here is a general answer for untab:
In Python IDLE: Ctrl + [
In Eclipse: Shift + Tab
In Visual Studio: Shift + Tab
In general, Shift + Tab works for any environment.
This workaround works most of the time. It uses Eclipse's 'smart insert' features instead:
Control + X to erase the selected block of text, and keep it for pasting.
Control + Shift + Enter, to open a new line for editing above the one you are at.
You might want to adjust the tabbing position at this point. This is where tabbing will start, unless you are at the beginning of the line.
Control + V to paste back the buffer.
I hope this helps until Shift + TAB is implemented in Eclipse.
Shift + Tab does that in Flex Builder (based on Eclipse), so it hopefully should work in regular Eclipse :)
In PyCharm, just use Shift + Tab to move a block of code left.
You can do this by going to the Window menu → Preferences, and then open the General list. Choose Keys.
Scroll down the list of keys until you see "Shift Left". Click that. Below that, you'll see some boxes, one of which lets you bind a key. It won't accept Shift + Tab, so I bound it to Shift + `. Apply Apply and Close, and you're all set.
Yes, in PyCharm: Shift + Tab works fine.
You can also change the shortcut. Use the Command + K, Command + S shortcuts to open the Keyboard Shortcut menu. Search for the "tab" and find the "outdent" in the list.