How to format code in Visual Studio Code on Windows - code-formatting

How can I format code in Visual Studio Code in the last update on Windows.
I tried Ctrl+ K, Ctrl + D doesn't work...
I also tried Shift + Alt + F. It didn't work either.
I tried the following solution, but that is not the issue:
How do you format code in Visual Studio Code?

If you are working on PHP you should download the PHP extension format code.
Press F1 and type:
ext install PHP Code Format
Then Shift + Alt + F will work.

You can also select the code you want to format and right click, find the format code menu item and it should have the keyboard command listed next to it.
By default it should be Shift + Alt/Option + F.

Simply use Ctrl + Shift + I
Or
Right Click on document and Click on Format Document

If it's for JavaScript, JSON, CSS, Sass, and HTML, there no better way than the Beautify extension. It is simple and very useful!
Once installed the way you do it are described here with good illustrations (to avoid content duplication):
How can I format PHP files with HTML markup in Visual Studio Code?
For others languages, you add the appropriate extensions and you can set keybinding (you need to get the appropriate command to execute, and add the keybinding to keybindings.json). I have explained that in the link above. Always read well the documentation of the extensions. There you can find all the possible configurations and so.
For specific languages you can search via Visual Studio Code in the extension marketplace. Enter just Beautify and you will see all the different Beautify extensions for the different languages. Also you can use formatting format formatter keywords, like PHP formatting and so.
Also, you can use the integrated formatting tool of Visual Studio Code. Mostly by clicking right and selecting formatting document, you can also format just a selection.
Here is the shortcut for formatting the whole document:
On Windows: Alt + Shift + F
On Mac: Shift + Option + F
On Ubuntu: Ctrl + Shift + I

As abdullam mentioned in his comment, the shortcut that worked for me is
Shift + Alt + F.
(The accepted answer didn't work for me. I am using Visual Studio Code on a Mac. I couldn't find the extension mentioned above i.e ext install PHP Code Format.)

Formatting any document in Visual Studio Code requires one to install a formatter plugin, like Prettier - Code formatted by Esben Petersen.
Install the plugin: Prettier - Code formatter from the Extensions window in Visual Studio Code.
You can open the extensions window from the left aligned sidebar or simply by pressing Ctrl + Shift + X
Post installation, from the required page you can try the below
Right click and choose Format Document;
or
Try Alt+Shift+F on Windows
The document should now be properly formatted.
PS: You can set "Prettier - Code formatted" as the default formatter for Visual Studio Code by performing the following:
Open Settings by pressing Ctrl + , and search for editor.defaultFormatter. Choose esbenp.prettier-vscode from the list and Save.
By default, now formatting any document with the above steps will use Prettier as the default formatter.

Related

How can I re-indent Vue.js code in VSCode?

The title tells it all. I have installed a couple of Vue.js related plugins for Visual Studio Code, but still can not format the code, as I used to do it easily in SublimeText.
Appreciate your hints?
You can either use an extension called "Prettier" or "Beautify", then follow the instruction to set it up/
Just open the Extension window and look it up there, after you installed it you can right click on the opened file window and choose "Format Document" or simply press "Ctrl + Alt + F"

Is there a shortcut to organize lines

Within the Cloud9 IDE, is there a shortcut to organize the lines of the Code, similar to the shortcut in Eclipse - Ctrl+A, Ctrl+I ?
see the next function (there is no meaning to the code) :
Before the Action
Now I do Ctrl+I and see the code now :
After The Action
Select the text you want to beautify and then press Ctrl+B (on PC/Linux). At time of writing, this only works for HTML, CSS, and JavaScript.
What you are looking for is in this section of their documentation. I am not quite sure what you are referring to when you say "organize lines of code", but all of the shortcuts for c9 are in the link.
https://docs.c9.io/docs/keybindings#section-code-manipulation
If you are referring to beautifying your code then this is what you are looking for is Shift + Ctrl + B this will beautify your text. Which is provided in the link.
Ctrl + A is just select all and should work as is.
***********UPDATE**************
With the information just provided, you are using C++ Here is a link to a plugin you can install to help with adding features for that language
https://github.com/invokr/c9.ide.language.cpp
there may be a better one out there, but there are some out there.

Using Sublime Text 2 key bindings in PyCharm

I would like to use the Sublime Text 2 key bindings in Pycharm. I know how to edit it one by one. Is there a way to override the entire keymap in one shot?
Something like
export the key bindings from sublime text 2
convert it into Pycharm's format
import it into Pycharm
Pycharm has some pre-configured keymaps. If there's a text / XML / JSON file where these maps are stored, I can try to convert it myself.
PyCharm now has Sublime Text keymap inbuilt as an alternative to Default Keymap.
Go to Setting -> Keymap and select Sublime Text from Keymap dropdown.
Hope that helps.
After poking around, I feel there's no easy way to do this.
If you change the default bindings, PyCharm creates a file in user space that shows the format of keymap. Theoretically, one could override all the fields in this file. But the problem is, there's no standard way of describing the action performed by a shortcut. Someone will have to do it manually, for each macro, to establish a correspondence between the actions performed by PyCharm & Sublime Text.
There is an IntelliJ request for this in their Youtrack tracker: IDEA-111333 Provide Sublime Text keymap.
From that thread, I found a repository for another remapping project. The keybinding file that imitates most of Sublime text can be found at in the directory PHPStorm-SpacePeacock/win_linux-keymaps-only/keymaps/Default for GNOME copy.xml. From the README:
The key mapping has been updated to better fit Sublime Text
conventions. Because I didn't think that ctrl + shift + alt + t is a
reasonable key combination for something as frequently used as
Refactor This.
Additionally, "search everywhere" HAD to be changed because
double-tapping left-shift is a two stroke trigger. This is a problem
because as you're working the IDE will be busy with analyzing,
indexing, and all of the things that IDEs do. If it's busy when you
try to hit the first left-shift, then the second left-shift won't pop
up the window. As far as user interfaces go, you should never have any
lack of confidence that an action will trigger the appropriate
response. Once you have that, you have to visually check each
operation which is slow and creates cognitive overhead. Consequently,
this was changed to ctrl + p (also to match Sublime Text) which
completely removes this problem.
ctrl + p search everywhere
ctrl + r search methods in current file
ctrl + alt + p change projects
ctrl + shift + enter complete current statement
ctrl + alt + enter refactor this
alt + enter show intended actions (intentions are one of my favorite
part JetBrains software)
ctrl + n new thing dialog
ctrl + shift + f format code
ctrl + d select word at cursor, or if a word is selected the select
the next occurrence of the word (multiple-cursors)
ctrl + t run tests
ctrl + alt + h show local history
ctrl + alt + r git conflict merge tool
(Less popular) keymaps that can be used with JetBrains Rider but not included in the installation package.
https://github.com/JetBrains/rider-non-bundled-keymaps
Intalling keymaps
In releases, get the sublime-text-keymap.jar file for the desired keymap.
In your IDE, choose File | Import Settings... from the menu and select the sublime-text-keymap.jar file.

What is the shortcut key for replace text in all files in Sublime Text 2?

How do I execute the "Replace" command with a keyboard shortcut?
I can't seem to find the "command" in the default keymap for OS X.
I know the single file replace all shortcut is control + option + enter, but that doesn't work in this case. This is in OS X, but it probably applies to Windows.
20 minutes of research turned up nothing.
Attempts:
Opened up the Find in Files panel and tried lots of combinations. No luck.
Browsed the keybindings file for anything bound to the find_in_files panel. No luck
Browsed the official Sublime Text API. No luck.
Browsed the unofficial list of commands. No luck.
This feels like a big oversight...
update: This is not implemented. Here is the official feature request.
Ctrl + shift + F
now you can add files and folder where you want to find and replace in all files.
Ctrl + Alt + Enter works for me in the latest Sublime Text 2

How to mimic Visual Studio's CTRL-X, CTRL-V functionality in Notepad++?

I'm using Notepad++ for some projects and miss Visual Studio's Ctrl + X, Ctrl + C functionality that cuts or copies the entire current line when no text is selected. The cut line shortcut seems to be Ctrl + L, which is not as convenient as Ctrl + X and the copy shortcut seems to be Ctrl + D, Ctrl + L, which is even less convenient.
Although a similar question has been asked before, the way to do this in Notepad++ was not provided and I cannot find a solution on the Notepad++ site or on its forums.
I've created a Notepad++ plugin that does this (without the need of python). An archived version of it can be found at https://bitbucket-archive.softwareheritage.org/projects/za/zastrowm/notepad-visualstudiolinecopy.html.
Synthesizing all other answers and comments, plus some additional necessary steps that haven't been mentioned:
Scintilla provides a "copyAllowLine" command that does this. Notepad++ doesn't expose that command in the shortcut mapper, but you can call it from a Python script and map Ctrl + C to that script. There is no corresponding command for "cutAllowLine", but a bit of extra Python code will do it. These scripts must be added to the menu and Notepad++ must restart before they will become available in the shortcut mapper.
Install Python Script plugin(can be done with Notepad++ Plugin Manager)
Create the following two python scripts using the menu Plugins -> Python Script -> New script
copyAllowLine.py
editor.copyAllowLine()
cutAllowLine.py
if editor.getSelectionStart() == editor.getSelectionEnd():
editor.lineCut()
else:
editor.cut()
Python Script -> Configuration
under User Scripts, add a menu item for each script.
Restart notepad++ (important)
Settings -> Shortcut Mapper...
under Scintilla Commands, remove the existing associations for Ctrl + C and Ctrl + X.
under Plugin commands, find the scripts you just created and map your shortcuts to them.
Note: when installed via plugin manager, version 1.0.6 was installed. When I attempted to run anything python related in Notepad++ I got an unknown exception from plugin manager. The solution was to manually download and install the 1.0.8 .msi from here: 1.0.8 installer
Install NppPython plugin (can be done with Notepad++ Plugin Manager)
Create this python script using the menu Plugins -> Python Script -> New script:
if editor.getSelectionStart() == editor.getSelectionEnd():
editor.lineCut()
else:
editor.cut()
Restart notepad++ (important)
Go to Menu Settings -> Shortcut Mapper -> Plugin commands
Find the script you just created in the list and set CTRL+X shortcut for it
Enjoy!
Go to Settings->Shortcut Mapper and click on the "Scintilla commands" tab at the top. Under there you should be able to change the Ctrl + L command to Ctrl + X.
You can add a script with the Python Script Notepad++ plugin, and assign Ctrl + C to the script (remove the Ctrl + C mapping from SCI_COPY in shortcut mapper, Scintilla Commands tab)
The script is just:
if editor.getSelectionStart() == editor.getSelectionEnd():
line = editor.getCurLine()
editor.copyText(line)
else:
editor.copy()
Obviously just add another similar script for Ctrl-X that removes the line instead.
The plugin from MackieChan: notepad-visual studio line copy
has to be still setup-ed as follow:
Put it into notepad++/plugin folder
open notepad++ (restart)
in Settings -> Shortcut Mapper
under Scintilla Commands, remove the existing associations for Ctrl + C,X
under Plugin commands, find the scripts you just created and map your shortcuts to them.
There is a plugin for it at https://github.com/kbilsted/NppPluginCutNCopyLine its open source and the code is easy to modify if you have extra needs.
you can write a program with a global key event hook, which every time you make a Ctrl + X checks if notepad++ is the foremost application running, grabs the screen, checks if any text is selected (by looking at the screenshot and your notepad++ color settings), and sends a WM_KEYPRESS message to the notepad++ window simulating a Ctrl + L (assuming you're using windows).
(this won't put the line into the clipboard though, you'll have to make some character recognition to allow it)