Selecting text code visualstudio with hot key - visual-studio-code

I installed code visualstudio 1.54.1 and having some line of code
if cursor is located on string
$adImageItemImgProps = AdImage::readAdImageProps($adImageItem->ad_id, $adImageItem->image, true);
inside of readAdImageProps method name, but when no chars selected and clicking hot key
all readAdImageProps method name is selected
and next clicking hot key
AdImage::readAdImageProps is selected.
and so on...
In similar way in PhpStorm work hot keys Ctrl+W...
MODIFIED :
I manually added proposed key lines in /home/username/.config/Code/User/keybindings.json
and see in the file : https://prnt.sc/10lc240
I restarted code visualstudio and "ctrl+shift+alt+w" and this function works in not way I expect.
Say I have in control php file with no test selected : https://prnt.sc/10lc53f
When I click "ctrl+shift+alt+w" - it works as I expect only for the first time : https://prnt.sc/10lc77h
But not next time when I clcik trhis hot key : https://prnt.sc/10lc7w0 and https://prnt.sc/10lc8xr
Is something wrong in my config ?
Thanks!

You can use the extension Select By
It is a 2 phase solution.
If no selection yet use the command editor.action.addSelectionToNextFindMatch to select the word under the cursor
If selection then extend at the begin to the next parent scope
Ad this to your keybindings.json file
{
"key": "ctrl+shift+alt+w",
"when": "editorTextFocus && !editorHasSelection",
"command": "editor.action.addSelectionToNextFindMatch"
},
{
"key": "ctrl+shift+alt+w",
"when": "editorTextFocus && editorHasSelection",
"command": "selectby.regex",
"args": {
"backward": "[a-zA-Z0-9_]+::",
"backwardInclude": true
}
}
Edit
I removed the forward search because it was taken care of by the no-selection case.

Related

How to make backspace behave as backspace in Visual Studio Code

In Visual Studio Code I indent using two manually inserted blanks. When I press backspace this deletes two blanks at the same time.
How can I turn off this behavior? I want a backspace to "eat up" exactly ONE blank, especially if the blank is a blank and not a tab.
The question is just the opposite to Deleting tabs when using tabs as spaces.
with extension multi-command you can create a keybinding that does what you want
add to keybindings.json (at the end) this will overrule the default backspace behavior
{
"key": "backspace",
"command": "extension.multiCommand.execute",
"when": "editorTextFocus && !editorHasSelection",
"args": {
"sequence": [
"cursorLeft",
"deleteRight"
]
}
}
Edit
Added && !editorHasSelection to get the default behavior when there is a selection

Copying a line when selection is empty does not work

When I try to Ctrl+C to copy the entire line that my cursor is on does not work, it simply doesn't change the current item in my clipboard. As soon as I make a selection, it manages to copy. I haven't changed much of the configurations, I only tried some stuff and my keybindings.json looks like this:
{
"key": "ctrl+numpad_divide",
"command": "macros.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+c",
"command": "editor.action.clipboardCopyAction"
},
{
"key": "ctrl+insert",
"command": "-editor.action.clipboardCopyAction"
}
Also worth mentioning is that I have tried with all the extensions disabled and the user-related keybindings.json and settings.json lines commented out. It just refuses to copy the line.
I think there could be a workaround by using the macros extension to create a macro to select the entire line and copy, then deselect it only when the selection is empty; however, I believe there should be a native fix for this as it is a trivial problem.

How can I get line break on enter even when the search field is open (but not focused) in VS Code?

If I have the search field open and press enter in my code it automatically tries to search instead of giving me a line break. I've heard that there is a way to turn off this behavior and only search when the search field has focus. Anyone know how? Currently I have to hit ESC to close the search before I can add a line break and I forget to do it 95% of the time and my editor jumps to a different section of the code. Thanks!
Changing findWidgetVisible to findWidgetFocus in my keyboard shortcuts settings fixed it!
/**
* amVim Finder Fix
**/
{
"key": "enter",
"command": "editor.action.nextMatchFindAction",
"when": "findWidgetFocus"
},
{
"key": "shift+enter",
"command": "editor.action.previousMatchFindAction",
"when": "findWidgetFocus"
},

VS Code : create custom snippet/shortcut

I would like to have the following feature on VSCode and I don't know if it is possible. For example, if I have this line :
I would like to emphasize this.
I would just select this, clic on a shortcut like ctrl+i and then this appears :
I would like to emphasize {i}this{/i}.
I use a lot of {i} and {/i} tags in my project so this would help me save an incredible amount of time !
I know VSCode already does something similar when you select a word and clic on "
Find your keybindings.json file and insert the following snippet:
{
"key": "ctrl+i",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "{i}$TM_SELECTED_TEXT{/i}"
},
"when": "editorTextFocus && editorHasSelection"
}
Key bindings can be found by pressing Ctrl+Shift+P > type "Keyboard shortcuts", full name being: Open Keyboard Shortcuts (JSON).

When clause to map <enter> to stage a file in VSCode

I'm trying to switch to VSCode and one of the things that's bothering me is that I can't hit enter to stage one or more selected files. What is the correct when clause to use?
If you have the file selected in the Source Control: Changes panel this seems to work:
{
"key": "enter",
"command": "git.stage",
"when": "sideBarFocus && activeViewlet == 'workbench.view.scm'"
}
from vscode when clauses: active views/panels. This assumes the source control panel and a file therein has focus.