Custom keybindings in vscode devcontainer definition - visual-studio-code

I’m trying to add a couple of key-bindings to my codespace image. But I can’t find where to store the keybindings.json, when I open the file in an active codespace it’s located in /User/keybindings.json, but I can’t find it in bash or when I try to Open Folder that folder. It seems to be a virtual file.
Is there a way to add these to the devcontainer.json? Or a magic place I can send them to from my Docker File?

Based on a number of closed issues, keybindings are considered more a personal preference and are synced from the users' preferences as well as platform dependent.
To supply or override keybindings a custom extension must be created, published to the marketplace and installed through the devcontainer.json.

Related

How to add "onView" "Settings" Page as ActivationEvent for vscode Extension?

The title is the TL;DR, but I'll start off with intent, I'm working on a vscode extension that have configuration/settings that will have an initial auto-detection (on activation) and populated during runtime, eg. selectable version of application installed on the computer (such as LLVM that could have 13 and/or 14). The closest is something like the built-in git extension's executable path detection.
So basically this runtime detection means I cannot use the configuration contribution points as everything in package.json is hardcoded...
Back to activation, the extension can be activated on any few commands indicated in the activationEvents, but the main thing is the detection must be done prior to users opening the Preferences: Open Settings (UI), I've looked through the vscode repo and found onCommand:workbench.action.openSettings2 to be closest to what I need, however I found a niche scenario where if the user have "Settings" page opened prior to installing the extension and relaunching vscode will jump straight to the Settings page, this will not activate the extension.
I checked the built-in git extension and found that they have been using "*" which is not recommended, so I'm using onStartupFinished as a workaround for now.
I found onView may be what I am looking for, but how do I know what is the editor/webview name for "Settings" page - onView:xxx.openSettings?

How can I create a local configs for Neovim extending the global init.vim?

Suppose that I have a map on my init.vim that I want to change the behaviour depending on the folder that I am. How could you do that?
A more concrete example: I have a map on my F12 that runs the project that I am. So if I am on a python project, this F12 will run an ipython on a floaternew window, with the current file already imported. Though, if I am on a cpp project, the same F12 will build using Make and running the binary on a floaternew window as well.
Nowadays, I have these two behaviours mapped on different key bindings. But It is going to very nice if I have only one binding to "run the project". Even if I need to open neovim with some parameter in each project, like neovim --local-config mylocalconfig.vim (extending init.vim with some behaviour)
I am kind inspired by a behaviour like direnv but with .vim files.
Any ideas?
There is an option in vim set exrc which enables reading vim config files from current directory, it also works in neovim.
From docs (:h exrc)
Enables the reading of .vimrc, .exrc and .gvimrc in the current
directory. If you switch this option on you should also consider
setting the 'secure' option (see |initialization|). Using a local
.exrc, .vimrc or .gvimrc is a potential security leak, use with care!
also see |.vimrc| and |gui-init|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.

How to create settings.json and extensions.json outside of image and named config level for an ATTACHED VSCode Container

I'm using WSL 2 for Windows, and I'm currently working on a ddev repo where I am creating a development environment using ddev and VSCode. On initiation of the ddev environment, I am starting up all my containers. With my custom "ddev code" command, I am attaching VSCode to the web container via the hex representation of the web container using
'code --folder-uri="vscode-remote://attached-container+646465762d646465762d7673636f64652d646576636f6e7461696e65722d64727570616c392d74656d706c6174652d776562%/var/www/html"'
Now, I would like to automatically enable a bunch of extensions and settings. Currently, I am using workspace settings in my projects folder structure in the form of .vscode/settings.json and extension settings in the form of .vscode/extensions.json. But this is just a workaround, since VSCode will use these settings as "workspace settings" and not "devcontainer settings". I would like to define the settings and install the extensions directly on my attached VSCode container rather than in my workspace settings, since I can only use "recommendations" in the extensions.json, because it is seen as a workspace.
I know I can set the settings and extensions under "AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\imageConfigs" or "nameConfigs" but I would like to have them in Ubuntu or rather in my project's folder directory. I also know that there is the devcontainer.json for standalone VSCode Containers where you can set the Docker files and settings/extensions, but how can I use such a file for my attached container?
Another way would be to install the extensions via command after attaching VSCode using
code --install-extension <extension-id>
But this will only install them locally. And executing this command in the web Container via ssh will throw an error.
Maybe someone knows a solution? If further information is needed I can of course provide it :)
Here is the repository I am working on:
https://github.com/webksde/ddev-vscode-devcontainer-drupal9-template
EDIT: Maybe this issue from our repo can also give more insight:
https://github.com/webksde/ddev-vscode-devcontainer-drupal9-template/issues/28

Recover lost settings + extensions and more?

I was playing around with my VSCode Settings Sync, and accidentally replaced my settings.json file with another one from a fresh install, as a consequence, I lost my entire settings.json configuration.
Is there a way to recover the lost settings.json file?
I checked my backups, however, it seems that I one cannot go back into the /Users/mf/Library/Application Support/Code/User/Sync folder.
Yes you can get them back.
They are saved on the hard-drive if your settings are set to their default values.
The universal method (works the same for all systems) is to hit the [F1] key, then type the command below into the input, until you see the option. When you do see the option click on it to open the directory.
Settings Sync: Open Backups Folder
The other option you have is to view the data in VSCode using the following VSCode command from your quick input using the [F1] key followed by the same instructions for the command above.
Settings Sync: Show Synced Data
There should be several saved versions of your settings, unless you have changed your configuration for settings sync in the settings menu, or in your user/workspace settings.json file.
Personally I like to just open backup folders and pullout what I need. If you are like me, and you use Ubuntu then the path below is the path used by VSCode to store backed-up keybindings & Settings.json instances. You can pullout what ever you need from that directory.
~/.config/Code/User/settings.json
If you need to restore the backed up files, you can visit this link, it demonstrates how to return to a previous editor configuration:
RESTORE PREVIOUS VS CODE CONFIGURATION:
https://code.visualstudio.com/docs/editor/settings-sync#_restoring-data

How to change folder that opened by default in VSCode?

I have small problem with VSCode folder, that opened by default.
Problem description: I start new instance of VSCode (trough File->New Window), and then if I choose File->Open Folder it opens dialog with my Windows user folder as starting point (C:\Users\MyUser)
Question: How can I change that folder in settings (if it possible)? So by default it will show as start point for example D:\development\ ?
At the time I write this answer, this is not possible. There are two problems on Windows, and one problem on Mac and Linux:
VS Code does not provide a default path to the file dialog 1. It does remember the last folder that you opened a file in, but that path cannot be used as a default because it is overwritten constantly.
On Windows only, Electron ignores the default path when creating a file dialog if the default path is a directory 2.
An extension also cannot solve this, because extensions are not allowed to modify the File menu 3.
I think the best option at this point is to pin a folder to the Quick Access area in Windows Explorer, as suggested in a comment, or to put an actual shortcut in the user profile folder.
Workspaces and File > Open Recent may also be helpful if you often open the same folders.
Your main problem is that you are unable to open your specific folder in VScode.
To solve that you can simply open the terminal/cmd in that specific window by just typing cmd in your search bar or just by pressing shift+right-click in that folder.
Now your cmd is open and you just have to type "code ." in the cmd and press enter to open the current folder in your VSCode.
In case that code . doesn't work for you then you have to add the Vscode in the environment variables of your windows.
Visual Studio doesn't provide a specific feature to open a specific path. But there is a solution to your problem. You are saying that you want D:\develpment as a default when you open VS Code. You can go to that specific directory or create shortcut to desktop then click right click on that folder and then click on open with code. If you didnot see open with code then reinstall your VS code and check on open with code when you are reinstalling VS Code.
make a shortcut on the desktop for vscode and then modify it and add the folder after the .exe command. This will default open that folder when you double click on it.
Visual Studio Code can be installed in two ways - User setup and System setup. I strongly believe you have User setup installed in your PC. Try re-installing it System-wide. That should probably fix your problem.
For more information: https://code.visualstudio.com/docs/setup/windows#_user-setup-versus-system-setup
PS: A lot more information is needed, you can share a screenshot of the window and elaborate more on it.