Save with "Retry as Sudo" using keyboard commands - visual-studio-code

Anytime I try to save a file (using Ctrl+S) that requires elevated permissions, I get the popup with the button to "Retry as Sudo". This is fine, but there does not seem to be any way to select "Retry as Sudo" using the keyboard. I have to use the mouse to actually click the "Retry as Sudo" button. I have tried tabbing, but cannot seem to select this button without using the mouse. Does anyone know if there is anyway to save a file as sudo without using the mouse?

From https://github.com/microsoft/vscode/issues/90661#issuecomment-586422989:
Create keyboard shortcut for command notifications.focusToasts
When the Retry as Sudo toaster appears you can now:
Press the assigned shortcut
Press Tab
Press Enter

I wanted to include an example to complement the other answers.
To add a keybinding open the command pallet:
ctl+shift+p Windows
cmd+shift+p MacOS
Search for >Open Keyboard Shortcuts (JSON) and press enter.
https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization
Below is an example that you can copy and paste as is into the json document. If there are no existing custom bindings just place it in between the [ ] brackets. If there are existing bindings (denoted by { } brackets) make sure you use a comma to separate them.
{
"key": "ctrl+shift+l",
"command": "notifications.focusToasts",
}
To be clear you will need to first save to bring up the "save as sudo" notification. Then you press the hotkey combination (which focuses the notification), then press TAB to highlight the "save as sudo" button, then press Enter to save.
It's not ideal, but it works.

Related

Problem control tabbing in Visual Studio Code

When I press Ctrl Tab the windows cycle through most recently used order.
This is winding me up!
So I read up the solution:
To achieve this in Visual Studio Code, you have to edit keybindings.json. Use the Command Palette with CTRL+SHIFT+P, enter "Preferences: Open Keyboard Shortcuts (JSON)", and hit Enter.
Then add to the end of the file:
[
// ...
{
"key": "ctrl+tab",
"command": "workbench.action.nextEditor"
},
{
"key": "ctrl+shift+tab",
"command": "workbench.action.previousEditor"
}
]
That's all good. But then when I try to edit the file, I get this message 'Cannot edit in read-only mode editor'.
OK... so I'll use another editor. I right click on the tab and there is an option 'Open in other editor...' (or something like that). When I click that, nothing happens.
When I search for solutions on 'Cannot edit in read-only mode editor' I get answers to other problems.
I have searched for a file called keybindings.json - can't find it.
Where am I going wrong?
Thanks.
To be able to control the CTRL Tab action
Open the GUI part of the settings responsible for that - Ctrl+K Ctrl+S (the command is named Preferences: Open Keyboard Shortcuts); from there you can either either change those shortcuts or you can open the JSON file (to do the latter you can press Ctrl+O by default or look for the icon in the right end of the tab bar).
As for the JSON, I think the bindings there are evaluated in order (so if you repeat something, the last thing takes precedence) and if you override a default shortcut through the GUI, it would explicitly write a binding that unbinds the command, i.e. same command, but with a minus in front of it.

Ctrl+D equivalent in DBeaver

I checked the DBeaver shortcuts docs page and Googled a lot but couldn't find any info on this...
Does DBeaver have a Ctrl+D equivalent (I am referring to Ctrl+D in VS Code, where it multi-selects by adding the current selection)?
Background
I work with BigQuery a lot, and in BigQuery Console and VS Code they both have the Ctrl+D functionality but not in DBeaver (at least not by default with the same hotkey)
DBeaver does not come with this functionality working by default, but you can very easily add this shortcut yourself with the following 4 steps:
On the top context menu, click Window -> Preferences. Then select User Interface -> Keys.
The command you want to add a binding to is the Multi selection down relative to anchor selection. So, on the filter text box, write multi. Select it, then on the bottom pane select the Binding text box, and press the shortcut keys down (In this case, press Ctrl+D).
Make sure that the When column changes to Editing Text. Otherwise, change this yourself. It will look like the iamge below
The Ctrl+D shortcut is already taken by the "Delete Line" command, so you need to unbind them. On the filter textbox, write ctrl+d. Then click on row that shows Delete Line, and click the Unbind Command button.
Click Apply and Close and have fun.
I believe it is Ctrl+Alt+Down (from https://dbeaver.com/docs/wiki/Shortcuts/)

Can I configure VS Code to disable Breakpoint by middle click?

I am switching from PyCharm to VS Codium. I want to be able to disable breakpoints by middle mouse click, like in pycharm.
Currently, I can disable a breakpoint by right click at breakpoint and select Disable Breakpoint:
Another way is to disable it in list in Breakpoints view.
But I want to be able to quickly enable/disable it by just clicking with mouse wheel (middle button). Is it possible to configure VS Code this way? Currently, when I middle click on breakpoint, this is ignored, and instead a text from selection clipboard is pasted (it is the default behavior in linux). Visual Studio Code version is 1.66.1.
There is no way at the moment to customize mouse click events. There are a few hardcoded options you can change in the settings, but it is extremely limited like pressing ctrl and the mouse wheel for zoom. As far as I am aware, disabling breakpoints is not among those options.
Check out: https://github.com/microsoft/vscode/issues/3130
I currently use the following workaround.
Remap the middle click to some button.
For wayland several utilities can be used for that. Let's take kbct.
Add such config (edit for your needs)
/etc/kbct/config.yml:
- keyboards: [ "Logitech MX Master" ]
keymap:
btn_middle: f15
Then start kbct.service.
Create the ruler script
Make the file choose_press.sh:
#!/bin/bash
class=$(xdotool getactivewindow getwindowclassname)
if [ "x$class" == "xVSCodium" ]; then
ydotool click 0xC1 # right click
sleep 0.2
ydotool key 107:1 107:0 28:1 28:0 # End, Enter
else
ydotool click 0xC2 # middle click
fi
Do not forget to add executable permissions.
Bind shortcut to the script
To assign a command to shortcut in KDE, go to System Settings -> Shortcuts -> Custom Shortcuts, right click, choose New -> Global Shortcut -> Command/URL. Go to Action tab and fill in the command. In this case it will be the path to choose_press.sh. Note: do not use ~ there.
And in Trigger tab assign the shortcut. In this case we use f15 (use some way to simulate it, if it is not presented on the keyboard).
Start VS Codium
Use vs codium in X11 mode. This is because I currently do not know how to get active window class in wayland.
Result
Now if you middle click in vscodium window, it will receive the sequence of input that leads to enabling/disabling breakpoint. In any other window, the middle click will behave as normal.
There is debug.enableOrDisableBreakpoint in codium, but toggling that with shortcut only works when the cursor is on the line with breakpoint. I did not found a way to move cursor to the line where you pressed (method to get the mouse over line?). So I made that complex thing with ydotool choose_press.sh.
I also tried to start stop kbct by window activation, but that is unfortunately broken in kde wayland currently.

vscode `ctrl + tab` needs confirmation first

when I press ctrl + tab it doesn't move the file right away but rather shows a list of all open files
I need the default behavior where it takes me right away to the last opened file without having to press enter
PS: if this helps in any way I'm using Linux Mint (LMDE 4 (debbie) x86_64)
You don't have to press Enter, just release the Ctrl key. That will take you to the last file you were in.
For instance, if you're in FileA and you have FileB and FileC open and you were last in FileC, Ctrl+Tab shows the list, and when you release Ctrl, you're taken to FileC. Do it again (releasing Ctrl) and you'll be back in FileA.
Check your keyboard shortcuts. Find the command:
workbench.action.quickOpenNavigateNextInEditorPicker
By default it is set to Ctrl-Tab, if yours is not, set it that keybinding by clicking on the pencil icon to the left of the command on hover and enter Ctrl-Tab into the dialog box.
That command should also be using the when clauses: inEditorsPicker && inQuickOpen

VSCode: Disable mouse+ctrl interaction

I often double-click to select followed by ctrl+c to copy. I am finding in vscode that ctrl press with the mouse over a word can perform an action. In some cases it selects the whole line, and in others it jumps to the definition of what is underneath. Is there a way to turn this off?
Note that if you move the mouse cursor off the word then it appears the action is not performed.
You could click on Visual Studio code->Preferences->KeyBoard Shortcuts. Keyboard Shortcuts page opens up. You could change any of the keyboard short cuts, by click on edit icon on the left as shown below
You can change the behavior of these features or disable them altogether by going to Tools > Options > Text Editor.
https://devblogs.microsoft.com/cppblog/productivity-structure-visualizer-ctrl-click-to-go-to-definition/