Key binding to wrap a selection with an html tag in VSCode - keyboard-shortcuts

Is there a default key binding in VSCode to wrap a selection in an HTML tag like the keyboard shortcut Shift+alt+W in Visual studio 2015? I could not find anything similar in documentation or in the default keyboard shortcuts that indicates its availability out of the box.

To automate this go to.
File > Preferences > Keyboard Shortcuts
and add this into your keybindings.json (right hand side window)
{
"key": "ctrl+shift+enter",
"command": "editor.emmet.action.wrapWithAbbreviation",
"when": "editorTextFocus && !editorReadonly"
}
You can replace ctrl+shift+enter with your own key combination.

you can use this extension:
https://github.com/Microsoft/vscode-htmltagwrap
or you can:
open the Command Palette: Command/Control+Shift+P (⇧⌘P)
type "wrap", then select "Wrap with abbreviation"
type the tag you want and press enter

Or simply search for the HTMLtagwrap extension in VScode, Make selection. Then use Alt + W. Then enter the new tag.

Related

What's the keyboard shortcut in visual studio code to complete statement like in IntelliJ?

Is exist keyboard shortcut to complete statement in current line in visual studio code, like in IntelliJ?
The complete statement is that Complete Statement, I can enter Shift + Ctrl + Enter to complete current line smartly.
The visual studio code support this function?
Complete Statement will help to some extent.
However, this extension lacks one feature - going inside the block. For example - for a if block if you use the shortcut to autocomplete the statement the cursor will still stay on the same line unlike Jetbrains IDE where it intelligently moves to the correct line.
Those who want to get the same feel as Jetbrains IDE's complete statement feature they can customize the keyboard shortcut like this:
Shortcut 1: Ctrl+ Shift+ Enter (to complete current statement)
Shortcut 2: Ctrl+ Shift (to go to next line)
It's just some extra keystrokes but still you can at least get it done!
You probably looking for IntelliSense feature of VSCode.
If you select the language that you coding with it (at right of bottom bar) and press ctrl + space, auto-complete & suggestion menu (according to your selected language) was shown.
Update: this extension for VSCode is probably what you want.
using macros,and create:
"macros":
{
"end_semicolon": // add ;\n
[
"cursorEnd",
{
"command": "type",
"args": {"text": ";\n"}
},
],
"end_colon": // add :\n\t
[
"cursorEnd",
{
"command": "type",
"args": {"text": ":\n\t"}
},
],
}

IntelliJ IDEA shortcut to switch 2 words

Is there a shortut (or a way to define one) in IntelliJ to switch 2 words?
Eg.
final static
Shortcut to switch to static final?
Under the "Edit" menu look for the "String Manipulation" flyout and there should be an entry called "Swap Characters/Selections/Lines/Tokens".
Selecting both words and then using this command will present you with a dialog. Typing space into the dialog and hitting return will swap two words.
Ctrl+Shift+A will get you a shortcut to this command if you type "swap" after its dialog comes up.
If the same pattern of words occurs multiple times it would be more effective to perform a replace with Ctrl+R.
I found it under "Code" menu : CTRL + ALT + SHIFT + ← or →
If your only issue is final static (and other) modifiers order, you can enable Missorted Modifiers inspection: Preferences | Editor | Inspections.
After that all missorted modifiers will be automatically highlighted, and you'll be able to fix it simply by either hitting Alt + Enter or doing Cleanup Code (also available to do via hotkey).

VSCode: How do you autoformat on save?

In Visual Studio Code, how do you automatically format your source code when the file is saved?
Enable "Format On Save" by setting
"editor.formatOnSave": true
And since version 1.49.0 editor.formatOnSaveMode has the option modifications that will just format the code you modified. Great when you change someone else code.
You can also set it just for one specific language:
"[python]": {
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.formatOnSave": true #
},
Since version 1.6.1, Vscode supports "Format On Save". It will automatically use a relevant installed formatter extension to format the whole document.
If you are modifying other users code and your team don't standardize a formatter, a nice option also is "editor.formatOnSaveMode": "modifications",. Unfortunately, the excellent black formatter does not support this feature.
Below are the steps to change the VS Code auto format on save settings:
Use [Ctrl]+[Shift]+[p]
Type "Preferences"
Select "Preferences: Open User Settings"
Search for "format"
Change "Editor: Format On Save" or "Editor: Format On Paste".
There are also Keyboard Shortcuts for formatting in VS Code. For instance, the default to format selected code should be [Ctrl]+K [Ctrl]+F (type both hotkeys in succession).
Below are the steps to change the auto format hotkey settings:
Use [Ctrl]+[Shift]+[p]
Type "Keyboard"
Select "Preferences: Open Keyboard Shortcuts"
Search for "format"
Change "Format Selection" or "Format Document".
Go to /.vscode/settings.json file and paste below code
{
"editor.formatOnSave": true,
}
It will format your code on save.
settings.json:
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications",
"editor.formatOnType": true,
"editor.formatOnPaste": true,
"formatOnSaveMode" is important to only format modified code, as I don't want to touch legacy code.
If I want to format the whole document, I'll call "Format Document" obviously.
"formatOnType" works after I enter a full stmt (e.g. for CPP, after ';')

Is it possible to chain key binding commands in sublime text 2?

There are times in Sublime Text when I want to reveal the current file in the side bar and then navigate around the folder structure.
This can be achieved using the commands reveal_in_side_bar and focus_side_bar however they have to be bound to two separate key combinations so I have to do 2 keyboard combinations to achieve my goal when ideally I'd like just one (I'm lazy).
Is there any way to bind multiple commands to a single key combination? e.g. something like this:
{
"keys": ["alt+shift+l"],
"commands": ["reveal_in_side_bar", "focus_side_bar"]
},
Solution
Based on #artem-ivanyk's and #d_rail's answers
1) Tools → New Plugin
import sublime, sublime_plugin
class RevealInSideBarAndFocusCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("reveal_in_side_bar")
self.window.run_command("focus_side_bar")
Save as RevealInSideBarAndFocus.py
2) Sublime Text 2 → Preferences → Key Bindings — User
Bind it to shortcut:
{ "keys": ["alt+shift+l"], "command": "reveal_in_side_bar_and_focus" }
Although the question is a year old, this might help people that are still looking for an answer.
Recently, a new package was developed by jisaacks, called Chain of command. It has the primary task to do exactly what you request, to chain several commands at once.
The package can be found here:
https://github.com/jisaacks/ChainOfCommand
An example of the working can be found below.
Let's say you wanted a key binding to duplicate the current file. You could set this key binding:
{
"keys": ["super+shift+option+d"],
"command": "chain",
"args": {
"commands": [
["select_all"],
["copy"],
["new_file"],
["paste"],
["save"]
]
}
}
This would select all the text, copy it, create a new file, paste the text, then open the save file dialog.
Source: https://sublime.wbond.net/packages/Chain%20of%20Command.
Updating #Artem Ivanyk's answer. I do not know what changed in Sublime, but that solution did not work for me, but I got this to work:
import sublime, sublime_plugin
class RevealInSideBarAndFocusCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("reveal_in_side_bar")
self.window.run_command("focus_side_bar")
.
{ "keys": ["ctrl+shift+8"], "command": "reveal_in_side_bar_and_focus" }
Btw, I'm using Build 2220
Stumbled upon similar problem. When trying to record macros, which involved „Save“ command, console threw at me „Unknown macros command save“ message.
Worked my way around with elementary plugin.
1) Tools → New Plugin
import sublime, sublime_plugin
class MyChainedActionsCommand():
def run(self):
self.view.run_command("reveal_in_side_bar")
self.view.run_command("focus_side_bar")
You need to use upper camel case notation for the class name. ST2 exposes this class for the command name with „Command“ suffix removed and the rest converted into the lowercase-underscore notation. I.e. in this example MyChainedActionsCommand could be run in sublime's console typing: view.run_command("my_chained_actions")
2) Sublime Text 2 → Preferences → Key Bindings — User
Bind it to shortcut:
{ "keys": ["alt+shift+l"], "command": "my_chained_actions" }
Heed commas.
Take a look at this gist.
I've been trying to implement this in a long time and found this by accident.
Don't forget to read the "documentation" provided. I kept trying to make this work, until I reallized I was not passing the "context" key.
You can create a macro to do this. For Sublime Text, macros are essentially just chained commands. You then create a keybinding for that macro. You can create a macro by using Tools > Record Macro, then executing your commands (beware that macros record keystrokes as well, so you'll want to use the commands from the menu bar to not cause conflicts), then Stop Recording, then Save Macro. After you save the macro, you can open it back up in Sublime Text to make sure that it recorded only what you want.
Building on Artem Ivanyk reply, here is a version of ChainedActions that works with arguments. It takes two arguments for actions and args. Both are lists and each command in the list gets executed with the corresponding arguments. This admittedly stupid example inserts two snippets: view.run_command("chained_actions", {"actions":["insert_snippet","insert_snippet"],"args":[{"contents": "($0)"},{"contents": "1($0)"}]})`
import sublime
import sublime_plugin
class ChainedActionsCommand(sublime_plugin.TextCommand):
def run(self, edit, actions, args):
for i, action in enumerate(actions):
self.view.run_command(action, args[i])
I've tried to use the same command but I ended up with a bug that when the file's folder was already unfolded sublime moved my focus sidebar's top, where I can see the open files. To improve this behavior I've wrote a new plugin that ensures it'll behave as I want to, here it is https://github.com/miguelgraz/FocusFileOnSidebar
I am using Sublime text3 build - 3083. It solves the problem just by 'Reveal it in side bar', the focus comes automatically.
I have added a custom keyboard shortcut for 'Reveal in sidebar' by adding the following statement under Preferences->Key Bindings-User :
[
{ "keys": ["ctrl+shift+r"], "command": "reveal_in_side_bar"}
]
The option - 'Reveal in sidebar' was missing for image file types, since the context menu doesn't appear with the right click of the mouse. The custom keyboard shortcut comes handy in this situation.
Starting from Sublime Text Build 4103 the feature is supported natively:
"Added the chain command, which accepts a list of commands to run in its "commands" argument. This allows binding a key to run multiple commands without having to use a macro"
See Changelog on https://www.sublimetext.com/dev

webmatrix list of keyboard shortcuts

List of keyboard shortcuts supported by Microsoft webmatrix.
Official list from Microsoft here:
http://www.microsoft.com/web/post/webmatrix-keyboard-shortcut-guide
Also, you can use the Alt key to display top level key tips. The top level key tips are show below:
Then, press Alt plus a top level key (such as H for Home as shown above) to show all of the keys that can be used on that tab. Use the displayed key value to access the related functionality.
For instance, Alt + H then T will allow you to print.
Just for those who happen upon this post, please check out the up to date list here:
http://www.microsoft.com/web/post/webmatrix-keyboard-shortcut-guide
Here are some additional ones that work inside the editor. Mind these are in an internal format that maps hotkeys to command codes. Its fairly readable though.
If you save this file in the WebMatrix config folder (typically c:\program files (x86)\Microsoft WebMatrix\Config), the editor will pick up modifications you make to this file. * Use at your own risk *
None;Right;RIGHT
None;Left;LEFT
None;Up;UP
None;Down;DOWN
None;PageUp;PAGEUP
None;Next;PAGEDN
None;Home;HOME
None;End;END
None;Escape;CANCEL
None;Delete;DELETE
None;Back;BACKSPACE
None;Insert;INSERT
None;Return;RETURN
None;Tab;TAB
Shift;Back;BACKSPACE
Shift;Right;RIGHT_EXT
Shift;Left;LEFT_EXT
Shift;Up;UP_EXT
Shift;Down;DOWN_EXT
Shift;Home;HOME_EXT
Shift;End;END_EXT
Shift;PageUp;PAGEUP_EXT
Shift;Next;PAGEDN_EXT
Shift;Tab;BACKTAB
Shift;Return;RETURN
Alt, Shift;Right;RIGHT_EXT
Alt, Shift;Left;LEFT_EXT
Alt, Shift;Up;UP_EXT
Alt, Shift;Down;DOWN_EXT
Alt, Shift;Home;HOME_EXT
Alt, Shift;End;END_EXT
Control, Shift;Right;CTLMOVERIGHT
Control, Shift;Left;CTLMOVELEFT
Control, Shift;Home;TOPLINE_EXT
Control, Shift;End;BOTTOMLINE_EXT
Control, Shift;L;DELETELINE
Control, Shift;Oem6;GOTOBRACE_EXT
Control, Shift;Space;PARAMINFO
Control, Shift;P;SELUPCASE
Control, Shift;W;SELLOWCASE
Control;Space;COMPLETEWORD
Control;J;SHOWMEMBERLIST
Control;Back;DELETEWORDLEFT
Control;Delete;DELETEWORDRIGHT
Control;A;SELECTALL
Control;Right;WORDNEXT
Control;Left;WORDPREV
Control;Home;TOPLINE
Control;End;BOTTOMLINE
Control;Up;SCROLLUP
Control;Down;SCROLLDN
Control;C;COPY
Control;X;CUT
Control;V;PASTE
Control;Z;UNDO
Control;Y;REDO
Control;OemPlus;ZOOMIN
Control;Add;ZOOMIN
Control;OemMinus;ZOOMOUT
Control;Subtract;ZOOMOUT
Control;D0;ZOOM1X
Control;NumPad0;ZOOM1X
Control;Oem6;GOTOBRACE
Control;L;CUTLINE
Control;T;TRANSPOSECHAR
Control,Control;K,D;FORMATDOCUMENT
Control,Control;K,F;FORMATSELECTION
Control,Control;K,I;QUICKINFO
Control,Control;K,C;COMMENT_BLOCK
Control,Control;K,U;UNCOMMENT_BLOCK
Control,Control;M,M;OUTLN_TOGGLE_ALL
Control,Control;M,U;OUTLN_TOGGLE_CURRENT
Control,Control;M,O;OUTLN_COLLAPSE_TO_DEF
Control,Control;M,P;OUTLN_STOP_HIDING_ALL
Control,Control;M,S;OUTLN_START_AUTOHIDING
CTRL-C
CTRL-V
CTRL-O
CTRL-S
CTRL-A
CTRL-W
CTRL-T moves a letter one step to the left?
CTRL-Z
CTRL-U
CTRL-I search in file (direction down)
CTRL-F find
CTRL-G go to line
CTRL-H replace
CTRL-X
CTRL-N new file
To view the current file in the browser instead of the site root.
CTRL+F12
As the Webmatrix 2 'Run' button opens the root index html file.