In Sublime text cmd+shift+v will paste and indent the code. Can this be done in visual studio code?
Workaround
I've made an extension that will let you paste and format with cmd/ctrl+shift+v.
Search for pasteandformat
https://marketplace.visualstudio.com/items?itemName=spoeken.pasteandformat
Currently, Visual Studio Code doesn't provide this specific functionality.
We could vote for this feature at Visual Studio's UserVoice website.
There's already a ticket open for this feature: Paste and auto align code. If you've got an account, you can vote for this feature so it gets more attention. If it has enough attention, Visual Studio Code's developers could take notice of this and maybe develop it.
Current workaround
After pasting the code,
You could use CTRL+E, CTRL+D for windows or ALT+SHIFT+F for mac.
But note that this will reformat the whole document, indenting according to the available rules for the source type.
If you only want this to be applied to the pasted code, select the code after pasting and then use CTRL+E, CTRL+D for windows or ALT+SHIFT+F for mac. Now the indenting/formatting is only applied to the pasted lines.
Since version 1.9.0, editor.formatOnPaste landed in VSCode.
Open settings.json via Code -> Preferences - Settings and search for formatOnPaste
// Controls if the editor should automatically format the pasted
content. A formatter must be available and the formatter should be
able to format a range in a document.
"editor.formatOnPaste": true,
Modify false to true since the default value is false
Source: Changelog update 1.9.0
Related
I am learning to build a Website on Python Django, but when I create a HTML file in VS code, this Editor don't recognize this file. You can see in following picture. I don't know how to solve this problem. Pls help me if you know, thank you very much
Try to install any HTML extension
Turn on HTML5 suggestion in settings.json file:
"html.suggest.html5": true
Follow this post
No HTML suggestions in Visual Studio Code
Note that in the bottom right-hand corner of your screen, the document language is Python Django, but if you click that and change the language to HTML, you will get HTML language features.
if necessary, sometimes it can be useful to compose a document in a side-by-side window that has the language type you need, to get the hinting and auto completion features, and then copy that into the adjoining document.
After installing and activating Django extension;
File - Preferences - Settings
Then find "Emmet:Include Languages" (You can use CTRL + F for that)
After that arrange "Item" and "Value":
Item = django-html
Value = html
Then click OK
In this way, it will be solved I guess
When copying and pasting HTML, VS helpfully renames all my variables to things like "Div1" & "Img1". Why!
I remember when using VS 2010 I think it was, there was a setting that allowed us to turn this "feature" off. Seems that feature no longer exists.
Are there any plugins or extensions or workarounds for this problem?
Seems that people have been complaining about this for years now:
How do I prevent Visual Studio from renaming my controls?
Disable "Auto ID elements" in Visual Studio 2013
https://connect.microsoft.com/VisualStudio/feedback/details/806446/asp-net-web-forms-development-unable-to-disable-auto-id-generation-on-paste-using-new-version-of-visual-studio-2013
You can use the following command (Language: C#) for my Visual Commander extension to paste text as is without renaming variables:
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
ts.Insert(System.Windows.Clipboard.GetText());
}
Here is the simplest workaround.
Simply make a comment first, then paste into the comment. When uncommenting, it will not apply Auto ID.
As a keyboard shortcut, it's CTRL+K,C,V,K,U on a new line.
Comment (KC), Paste (V), Uncomment (KU).
You can disable this auto-tag closing in Options > Text Editor > HTML u can find here everything about html editor.Search for AutoTag or Format Html on paste!
I'm using Visual Studio Code (1.17.1, on MacOS 10.13 AND Windows 10) developing an asp.net core mvc web app using razor templating.
Visual Studio Code supports Emmet (https://code.visualstudio.com/docs/editor/emmet)
My issue is that Emmet works correctly in HTML files, but will not work in razor CSHTML files.
I've found:
To enable the Emmet abbreviation expansion in file types where it is not available by default, use the emmet.includeLanguages setting. Make sure to use language ids for both sides of the mapping.
https://code.visualstudio.com/docs/editor/emmet
but it doesn't indicate where to find a list of "language ids". I tried searching for it, but you can imagine what happens when you search for programming language id!
Is there a way to tell Emmet in VS Code to treat cshtml files as html files? Is there any other way to get this to work (besides renaming the files, which is another solution out there)?
According to this link, the corresponding language for *.cshtml files is razor, thus you need to specify it in the emmet mappings as follows:
"emmet.includeLanguages": {
"razor": "html"
}
updated:
Press Ctrl+K than M (Ctrl+K,M) than select highlighter from the dropdownlist you want this is a common shortcut. very useful. even works for any file types. ie. create a new file and code some xml or what language you want than Ctrl+K,M you can specify/override ide hilighter on the fly. very useful shortcut. try it. you won't forget Ctrl+K,M. one of most useful hotkey combination I ever use in vscode. by this way code-completion wakes up and works as language you selected.
in vscode > settings.json
I added the related codes mentionel above. emmet worked for cshtml files.
"emmet.includeLanguages": {
"razor":"html",
"aspnetcorerazor":"html"
}
In Tools > Options, I cannot find the setting to disable auto-renaming of elements which are pasted in HTML source view.
It used to be: Tools > Options > Text Editor > HTML > Miscellaneous > Auto ID elements on paste in Source view. But that option is gone in Visual Studio 2013.
How can I disable the auto-renaming?
For now the best solution seems to be a workaround that was posted by a user on the Microsoft Connect website which is to paste the code as a comment.
Fool the IDE that we're not pasting code (thus he won't alter it). How ? Paste a comment ! How to do that in real life ? Here is how I do it (feel free to suggest other ways!):
1) Place cursor where I want to paste code
2) ctrl-k, ctrl-c (i.e.
comment region. Since no region was selected, an empty comment is
inserted and our cursor Inside of it) 3) ctrl-v (paste content that is
believed to be a comment by the IDE) 4) ctrl-k, ctrl-u (i.e.
un-commenting the current comment we're in!
The auto ID assigning is made only if the ID is used by another control on the same page.
Copy the code and paste in external editor like Notepad++, then copy it again from NP++ and paste it in the code editor page, the ID should remain the same.
Is it possible to auto-format your code in Dreamweaver like in Visual Studio (ctrl+k+d)
A quick Google search turns up these two possibilities:
Commands > Apply Formatting
Commands > Clean up HTML
Commands > Apply Source Formatting.
Works a treat.
For the 2017 CC release this has been moved (after many years of habit development). Find it now at:
Edit > Code > Apply Source Formatting.
It may be prudent to set up a keyboard shortcut if this is something you'll need regularly.
Edit > Keyboard Shortcuts
Following works perfectly for me:
-*click on COMMAND and click on APPLY SOURCE FORMATTING
- *And click on Clean Up HTML
Thank you PEKA
This is the only thing I've found for JavaScript formatting in Dreamweaver. Not many options, but it seems to work well.
JavaScript source format extension for dreamweaver: Adobe CFusion
I tried some of the sources online and finally, the below selection works fine for me (Dreamweaver on Mac). For versions above Adobe Dreamweaver CC 2017 and above:
Adobe says:
Edit > Code > Apply Source Formatting
Moreover, full documentation with other supporting information for tasks such as setting defaults, etc. on https://helpx.adobe.com/dreamweaver/using/format-code.html.
And for JavaScript source format you can use Dreamweaver JavaScript source formatting extension.(available on adobe)
Auto formatting can be done by
Select View > Code View Options
Click the View Options button in the toolbar at the top of Code view or the Code inspector.
Auto Indent Makes your code indent automatically when you press Enter while writing code.
source
Please use shortcut key alt+c+a
Please click on "edit" -> then keyboard shortcuts. It`s straight forward from there. Just select the command from the list, and press the + button.
You will need to create a duplicate set, then select it again from the list. And finally set a keyboard shortcut!
Now, before saving, press the shortcut you just created!
Coding toolbar (Edit > Toolbars > Coding) and select Code Format Settings to set your preferred formatting.
You can also access the formatting option from Commands > Apply Source Formatting or only apply it to a select block of code by selecting the Apply Source Formatting to Selection option.
http://www.hongkiat.com/blog/10-useful-dreamweaver-tips-for-beginners/
ctrl+a->(click)commands->cleanup word HTML