Reputation: 5194
In Visual Studio, if you hold CTRL and click on word, it selects the entire word. If you drag, it selects text word-by-word.
I find this feature of Visual Studio very useful when I'm copy pasting small bits of code, since I can just keep holding CTRL, select words, and press C, X, or V to move stuff around.
In VS Code, you can't do this. Instead, CTRL+CLICK is bound to "Go To Definition".
Is there any way to match the behavior of VS Code with Visual Studio in this context?
Upvotes: 48
Views: 9538
Reputation: 486
I am the author of the source code change mentioned in the other reply. It appears my code will not be merged since it has been over a year.
My code changes can be found here if you want to build from source, but I also uploaded compiled binaries for Windows which can be downloaded in the Release tab.
If you build your own version you will need to modify product.json to get the Extension Gallery to work as described here. You can also install the extension Visual Studio Keymap to get similar key bindings to Visual Studio.
Once in Visual Studio Code you can enable the feature or add the JSON property:
"editor.wordSelection": true
Upvotes: 4
Reputation: 5215
For any AutoHotkey users, here's a script that will give you the functionality (but not the +drag variant, unfortunately).
#IfWinActive ahk_exe Code.exe
~^LButton:: Send {LButton up}{Ctrl up}{Click}^{Left}^+{Right}
You'll still need to follow Wappenull's instructions to change Multi Cursor Modifier to 'ctrlCmd'.
The good thing about doing it this way is that you can use the same script for multiple programs.
Upvotes: 0
Reputation: 1379
Update for 2022. (Spoiler alert, it is still not here) but there are few catch:
The only promising attempt I found is this attempt on github issue to modify vscode source code to support control click select.
But to really test this you need to be able to build vscode. At the time of writing, his commit is now 10 months old (10000 commits) behind latest and he did not provide any binary build, and I failed to build vscode from source myself so I cannot test this. (npm and yarn is not my domain here)
Which link to this code commit
Although not really a solution to what OP asked. I decided to include this in my answer as other answer did not mention it yet.
For now you can turn off this Ctrl+Click feature with workaround by setting following editor setting to 'ctrlCmd' so that it won't interfere with your copy paste action.
Upvotes: 3
Reputation: 13
Using a keyboard hook, you could do something like this:
// release CTRL
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wVk = VK_CONTROL;
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(input));
// double click in place
POINT client;
client.x = msStruct.pt.x;
client.y = msStruct.pt.y;
ScreenToClient(hWnd, &client);
const auto mouseLParam = MAKELPARAM(client.x, client.y);
SendMessage(hWnd, WM_LBUTTONDOWN, 0, mouseLParam);
SendMessage(hWnd, WM_LBUTTONUP, 0, mouseLParam);
SendMessage(hWnd, WM_LBUTTONDOWN, 0, mouseLParam);
SendMessage(hWnd, WM_LBUTTONUP, 0, mouseLParam);
// press CTRL
input.ki.dwFlags = 0;
SendInput(1, &input, sizeof(input));
I have implemented said feature and provided it as a free 3rd party open-source app: https://github.com/dougbenham/CtrlClick
Upvotes: 0
Reputation: 146
As @phuzi said in the comments you can use double click to select the word or double click and drag to select word to word (it will snap on the last character of each word). If you triple-click on a line or click on line num, it will select the whole line (with the invisible character at last '\n').
If you press CTRL + D
it will select the word where the cursor is. Also if there are multiple instance of same word you can select them all one after another using CTRL + D
.
Upvotes: 9
Reputation: 1930
You can set multiples cursor by doing ALT+CLICK. You will then select multiples parts of your text/code that you could copy and paste very easily.
Upvotes: 0