How to read vscode keybindings within an extension - visual-studio-code

I am writing an extension that does things with keyboard shortcuts. I would like to read all current shortcuts and act accordingly. Currently I am reading them from this file:
~/Library/Application Support/Code/storage.json
Is there a way to pull that from vscode module instead?

You need to perform some steps, once you tested the current implementation.
Set a contribution point.
Create a manifest as shown here
Use a command on the VS code API to perform your action
Publish it to the extensions market place. Alternatively package it
into a VSIX. More info.

Related

NerdTREE in VSCODE

In VIM there is a pluggin called NerdTREE that is to move between folders, I am looking for something similar for vscode, where I can move between files but with the keyboard.
As I write this, there is an extension available in VSCode with the same name you mention.
This recently released extension has only basic commands such as creating folders and files, moving between them, copying, pasting, renaming or opening a file.
Well, it also has very few configuration options so maybe that is discouraging, but in short I consider it a good alternative for the moment to have some of that vim pluggin, and maybe over time the developer will add new features.
Here is the repository of this extension so you can take a look at it: https://github.com/61130061/NERDTree

Where can I enable or implement full-line and file name completion in VSCode?

In Vim, I love using:
Ctrl+X, Ctrl+F to trigger code completion using local file names.
Ctrl+X, Ctrl+L to trigger completion of full lines from open files.
I'd like to have the same features in VSCode. A Google and SO search did not show me any extensions that provide this feature.
Is there an VSCode extension that does this?
What is the best way of adding this feature? Should I write my own extension or is there an existing commonly used "intellisense" extension where I easily contribute these features?
The extension Path Autocomplete does file name completion.
If you search for autocompletion in the marketplace there are other extensions as well which might provide the line completion that you're looking for.
I use vscode.vim extension which is a vim emulator for VSCode. It has most of the features of vim, including the completion of full lines from open files with the same keyboard shortcut: Ctrl+X, Ctrl+L.

Is it possible to synchronize vscode terminal emulator's working directory with an editor's?

I'll like to have the terminal automatically change directory to the editor's current directory anytime I switch editor.
I'm used to this in Emacs so I was thinking if it was possible to make VSCode have this same behavior.
I do not believe this is supported out of box as of VS Code 1.24. However this could be implemented by an extension (see discussion here)
Implementing this will likely require this VS Code extension API addition: https://github.com/Microsoft/vscode/issues/46192
I have implemented a simple extension that does just this. Take a look at https://marketplace.visualstudio.com/items?itemName=maciejdems.terminal-sync.

Fuzzy file opening in vscode

I am exploring vscode after using atom for a long while. One of the things I'm missing is an equivalent of the lovely package advanced-open-file. Is there something similar to this in vscode?
I found the advanced-new-file extension, but it is only helpful when it comes to new files. I would like to be able to quickly open files from all over my local files (not only the workspace).
Edit: I found the option of workbench.action.quickOpen; but it doesn't allow opening files from the whole file system.
Sorry, but currently the answer is no. The problem is that input box doesn't provide a way to listen to key events:
GitHub issue,
so even the extensions can't do that currently. Here's the comment from advanced-new-file extension creator:
Because VSCode extensions don't yet have the ability to do type-ahead autocomplete within the text input box (See https://github.com/Microsoft/vscode/issues/426), we work around this limitation and provide autocomplete using a two-step workflow of selecting existing path, then providing new filename/path relative to the selection.
The good news is that there is a new API addressing this issue, but it's currently in 'proposed' state and can't be used for published extensions.
One workaround could be typing code -r some/path in integrated terminal and using 'tab' for autocomplete.
The Fuzzy search extension seems to work for me.
It adds a new action to the command palette which allows you to search for files in the current project and open them.

How to edit existing VS Code Snippets

Is there a way to remove or edit some of the default code snippets in Visual Studio CODE ?
For example when i type req+TAB i need require not requestAnimationFrame
The extensions snippets can be found inside each snippet directory below:
(if there are snippets in the extension)
Mac/Linux: $HOME/.vscode/extensions/
Windows: %USERPROFILE%\.vscode\extensions/
Select the extension you want to modify and then dive into the javascript.json file in snippets/ directory in there, and change whatever you like.
Just remember that if/when you choose to download and update the extension someday, all your personal modifications will get overwritten/replaced out with the updated version of the file.
(unless of course you squirrel away your changes outside of the extension's directory...)
Edit/Aside:
Looking closely at all the copied editions already present in this directory, it appears that at least some of the extension updates keep the former version around. If this is the case, when you update an extension when a new version is released, you wouldn't need to worry about storing a copy of your modified file somewhere else; returning a file to active duty might just be as easy as a copy-paste from the old into the appropriate, newer, higher numbered directory.
Resources/citations/acknowledgements:
Thanks to here for helping initially pointing me towards the relevant directory.
The suggestion item requestAnimationFrame is coming from the JavaScript language service. It's not coming from the snippets.
However, you can define your own snippets and tell Visual Studio Code to show the snippets first. How to do it:
Go to File -> Preferences -> User Snippets and select JavaScript in order to edit snippets for that language
Add this entry to the opened file javascript.json and save it
"require": {
"prefix": "req",
"body": [
"require"
],
"description": "Add 'require'"
}
Add the following line to your preferred settings.json (user or workspace settings) and save it
"editor.snippetSuggestions": "top"
Now you get your self defined require suggestion in first place as soon as you type req in a .js file.
On my Windows10 machine the log and other default javascript snippets can be found in :
C:\Users\$USER\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json
On my Windows installation the default/built-in JavaScript snippets are located in
C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\javascript\snippets\javascript.json
I renamed that snippet to "logx" (requires admin privileges to modify the file) and restarted vsCode and now have just my user "log" snippet.
There are some threads about this on the issue tracker -
https://github.com/Microsoft/vscode/issues/10565
https://github.com/Microsoft/vscode/issues/48315
Attention everyone!
This is now possible in the latest vscode. Solution here: https://github.com/microsoft/vscode/issues/10565#issuecomment-721832613
That solution tells you how to disable any snippet (including built-in or extension snippets). While this is technically not editing the snippet, disabling the snippet and then creating your own user snippet accomplishes the same exact goal. Yay!
I found mine at ~/.config/Code/User/snippets
If you want to create a global snippet, create a file named snippet_name.code-snippets
If you want a language specific snippet, create it like php.json
Hiding default VSCode snippets is easy:
you can hide specific snippets from showing in IntelliSense (completion list) by selecting the Hide from IntelliSense button to the right of snippet items in the Insert Snippet command dropdown.
https://code.visualstudio.com/docs/editor/userdefinedsnippets#_can-i-remove-snippets-from-intellisense