Is there a way to enable auto-wrapping only for comments? So far I only found the setting to enable auto-wrapping for everything.
Javadoc comments are covered by
Editor > Code Style > Java > JavaDoc > Wrap at right margin
(So called) single line comments such as ...
// this is a comment
... are another matter. There's no configuration item available in Editor > Code Style > <your_langauage> > Wrapping and Braces to control these.
Edit 1: based on your first reply to this answer: "I am looking for auto-wrapping only for JavaDoc."
Untick this item: Editor > Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded
Tick this item: Editor > Code Style > Java > JavaDoc > Wrap at right margin
Here's a pair of screenshots showing before and after formatting, with the above configuration in place:
Before
After
The IntelliJ formatter has not wrapped the code (because Editor > Code Style > Java > Wrapping and Braces > Ensure right margin is not exceeded is not ticked) but it has wrapped the Javaodc (because Editor > Code Style > Java > JavaDoc > Wrap at right margin is ticked).
IntelliJ IDEA 2019.1 - Wrap JavaDoc only
Settings > Editor > Cody Style > Java > Wrapping and Braces
Hard wrap at: [Your preferred value for JavaDoc wrapping]
Wrap on typing: No
Keep when reformatting > Ensure right margin is not exceeded: Disabled
If any setting here is set to Wrap if long or Chop down if long, then change it to Do not wrap.
Settings > Editor > Cody Style > Java > JavaDoc
Other > Wrap at right margin: Enabled
Unfortunately, you cannot use "Wrap on typing" for JavaDoc only, because it will wrap code too, even if code wrapping is completely disabled.
Use CTRL+ALT+L to wrap your JavaDoc (Reformat Code).
Settings > Editor > Cody Style > Java > Wrapping and Braces
Settings > Editor > Cody Style > Java > JavaDoc
For every typescript file visual studio code uses an auto indentation of 8 spaces. This is a bit too much for my taste but I can't find where to change it.
Maybe it's available as a setting but under a different name as I can't find anything related to indentation.
UPDATE
I'm currently using the Prettier code formatter and that solves all formatting problems by auto formatting on save (if there is no syntax error)
In the toolbar in the bottom right corner you will see a item that looks like the following:
After clicking on it you will get the option to indent using either spaces or tabs. After selecting your indent type you will then have the option to change how big an indent is. In the case of the example above, indentation is set to 4 space characters per indent. If tab is selected as your indentation character then you will see Tab Size instead of Spaces
If you want to have this apply to all files and not on an individual file basis, then override the Editor: Tab Size and Editor: Insert Spaces settings in either User Settings or Workspace Settings depending on your needs
Edit 1
To get to your user or workspace settings go to Preferences -> Settings. Verify that you are on the User or Workspace tab depending on your needs and use the search bar to locate the settings. You may also want to disable Editor: Detect Indentation as this setting will override what you set for Editor: Insert Spaces and Editor: Tab Size when it is enabled
You can change this in global User level or Workspace level.
Open the settings: Click the gear on the bottom left, then click Settings as shown below.
Then, do the following 2 changes: (type tabSize in the search bar)
Uncheck the checkbox of Detect Indentation
Change the tab size to be 2/4 (Although I strongly think 2 is correct for JS. Haha :))
To change the indentation based on programming language:
Open the Command Palette (CtrlShiftP | macOS: ⇧⌘P).
Type and select: Preferences: Configure Language Specific Settings... (command id: workbench.action.configureLanguageBasedSettings).
Select a programming language (for example TypeScript).
If Settings menu is opened (since 1.66.0):
4. Press → to place the cursor right beside the language filter (e.g. #lang:typescript).
5. Type Tab Size and enter your preferred value in the text box.
If settings.json file is opened:
4. Add this code:
"[typescript]": {
"editor.tabSize": 2
}
See also: VS Code Docs
Code Formatting Shortcut:
VSCode on Windows - Shift + Alt + F
VSCode on MacOS - Shift + Option + F
VSCode on Ubuntu - Ctrl + Shift + I
You can also customize this shortcut using preference setting if needed.
column selection with keyboard
Ctrl + Shift + Alt + Arrow
You might also want to set the editor.detectIndentation to false, in addition to Elliot-J's answer.
VSCode will overwrite your editor.tabSize and editor.insertSpaces settings per file if it detects that a file has a different tab or spaces indentation pattern. You can run into this issue if you add existing files to your project, or if you add files using code generators like Angular Cli. The above setting prevents VSCode from doing this.
In my case "EditorConfig for VS Code" extention is overriding VSCode settings.
If you have it installed, then check .editorconfig file in the root folder of the project.
Here is an example config. The "indent_size" sets the number of spaces for a tab.
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
How to turn 4 spaces indents in all files in VS Code to 2 spaces
Open file search
Turn on Regular Expressions
Enter: ( {2})(?: {2})(\b|(?!=[,'";\.:\*\\\/\{\}\[\]\(\)])) in the search field
Enter: $1 in the replace field
How to turn 2 spaces indents in all files in VS Code to 4 spaces
Open file search
Turn on Regular Expressions
Enter: ( {2})(\b|(?!=[,'";\.:\\*\\\/{\}\[\]\(\)])) in the search field
Enter: $1$1 in the replace field
NOTE: You must turn on PERL Regex first. This is How:
Open settings and go to the JSON file
add the following to the JSON file "search.usePCRE2": true
Hope someone sees this.
Simplified explanation with pictures for those that googled "Change indentation in VS Code"
Step 1: Click on Preferences > Settings
Step 2: The setting you are looking for is "Detect Indentation", begin typing that. Click on "Editor: Tab Size"
Step 3: Scroll down to "Editor: Tab Size" and type in 2 (or whatever you need).
Changes are automatically saved
Example of my changes
To set all existing files and new files to space identation to 2 just put it in your settingns.json (in the root of json):
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
}
you can add the language type of the configuration:
"[javascript]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
}
Setting the indentation in preferences isn't allways the solution. Most of the time the indentation is right except you happen to copy some code code from other sources or your collegue make something for you and has different settings. Then you want to just quickly convert the indentation from 2 to 4 or the other way round.
That's what this vscode extension is doing for you
Step 1: Open settings.json in vscode
Step 2: Add the lines as below for the programming language (an example is below)
For typescript and javascript
"editor.detectIndentation": false,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
},
"[javascript]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation":false
}
Problem: The accepted answer does not actually fix the indentation in the current document.
Solution: Run Format Document to re-process the document according to current (new) settings.
Problem: The HTML docs in my projects are of type "Django HTML" not "HTML" and there is no formatter available.
Solution: Switch them to syntax "HTML", format them, then switch back to "Django HTML."
Problem: The HTML formatter doesn't know how to handle Django template tags and undoes much of my carefully applied nesting.
Solution: Install the Indent 4-2 extension, which performs indentation strictly, without regard to the current language syntax (which is what I want in this case).
I wanted to change the indentation of my existing HTML file from 4 spaces to 2 spaces.
I clicked the 'Spaces: 4' button in the status bar and changed them to two in the next dialog box.
I use 'vim' extension. I don't how to re-indent without vim
To re-indent my current file, I used this:
gg
=
G
Check tabWidth if you are using a formatter, that was the issue in my case. It represents the number of spaces used in tabs.
Adding on: yes, you can use the bottom-right UI to configure the space settings. But if you have existing code that's not formatted to the new spacing, then you can right-click anywhere within the file and click Format Document. Took me a while to figure this out until I stumbled on this issue.
Format Document menu
For me it was docs-markdown andDocs Authoring Pack. Microsoft's many modules messing with each other yet again! Disabled the extensions and now good to go again 😀
The Problem of auto deintending is caused due to a checkbox being active in the settings of VSCode.
Follow these steps:
goto preferences
goto settings
search 'editor:trim auto whitespace'
Uncheck The box
The following search-and-replace regex changes the number of spaces per indentation level from 4 to 2 in existing files. It's relatively easy to understand, reliable, and doesn't require installing anything.
Instructions
Press CtrlH (or ⌥⌘F on macOS).
Make sure regex matching is on by clicking on the .* button in the search popup or pressing AltR (or ⌥⌘R on macOS).
In the Find field, enter ^(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?(?:( ) )?
In the Replace field, enter $1$2$3$4$5$6$7$8$9
Finally press CtrlEnter (or ⌘Enter on macOS) to apply to the current file.
You could also use this in the Search pane on the left to do this across all files in your project. However, note that this should only be run once per file. It will mess up the indentation of files that already use 2 spaces.
Extra Credit: How It Works
The way the regular expression works is it matches groups (?: ... ) of four spaces at a time at the beginning ^ ... of each line, only capturing ( ... ) the first two spaces. Each indentation level is optional ... ?, so it works for as many indentation levels as the pattern is repeated and there are in each line. Then it replaces the whole pattern with only the captured spaces $1, $2, ..., effectively replacing every four-space indentation level with two spaces.
This pattern only works up to 9 indentation levels (I'm not sure if $10 would work, but if so this could be expanded indefinitely).
Extra Extra Credit: Extending
You could adapt the pattern to decrease the number of spaces per indentation level in a file from any original number to another lower target number.
Put the target number of spaces inside the inner parenthesis. Then, put the remaining original number of spaces in the outer parenthesis, so the total number of spaces in the pattern is the original.
For example, if you want to change the indentation level from 6 to 4, repeat this search pattern as many times as you like:
^(?:( ) )? or ^(?:( {4}) {2})?
And use the same number of $1, $2 in the replacement pattern.
First, check if you have installed "EditorConfig for VS Code". It was overriding my editor settings. I spent all day correcting this problem.
In the project find .editorconfig file and ones changed there it will work.
I like these settings for indentation you can modify them according to need.
You can open VScode setting.json file by typing CTRL+SHIFT+P and paste below the JSON setting
setting.json
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"editor.wrappingIndent": "deepIndent",
"editor.autoIndent": "full"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"editor.wrappingIndent": "deepIndent",
"editor.autoIndent": "full"
}
With VSCode 1.75 (Jan. 2023), indentation is also customizable on VSCode terminals, not just VSCode views.
See issues 170432: "Add a terminal tab stop size (editor.tabSize) setting"
When a tab is printed in the terminal, it has a tab size of 8 spaces, regardless of the tab size setting.
Therefore, PR 170733 adds a new setting:
terminal.integrated.tabStopWidth: The number of cells in a tab stop
How do I make IntelliJ IDEA insert a new line at every end of file,
so that GitHub doesn't complain for example?
Change your Editor settings:
Settings → Editor → General → Ensure line feed at file end on Save
For MAC users:
Preferences > Editor > General > Ensure every saved file ends with a line break
IntelliJ IDEA 2016.3
Approach 1
File > Settings... > Editor > General > Ensure line feed at file end on Save
Approach 2
Help > Find Action... (Ctrl+Shift+A) > type "Ensure line feed" > switch the toggle to ON (using the mouse click or Enter) for "Other: Ensure line feed at file end on Save" line
Possible alternative with a number of handy features is EditorConfig
Just submit an .editorconfig file to your repo
[*]
insert_final_newline = true
And it will work natively not only in Idea, but in all major IDEs (some require a plugin).
Now all team members would have same configuration, eol, eof, and no more tabs vs spaces :)
For Mac Users: IntelliJ Idea version 2020.2
Option1:
IntelliJ Idea -> Preferences -> General -> Ensure an empty line at the end of a file on save
Option2:
⬆️ + ⌘ + A or Or just click on Help from menu bar -> Find Action and then type Ensu and choose Ensure an empty line at the end of a file on save
General -> Save Files For IntelliJ IDEA 2020.
Check the Bottom Right Corner:
In latest versions of IntelliJ, the setting has been renamed to 'Ensure an empty line at the end of a file on save', and it has been moved under Setting>Editor>General>Save Files
This should have been a comment, but I wanted to add the screenshot as well so wrote as an answer.
As Rider (IDEA's cousin for .NET) is driving me crazy, this might be helpful for those writing C# as Ensure line feed at file end on Save alone won't work. It needs
File → Settings → Editor → Code Style → C# → Line Breaks and Wrapping → Line feed at end of file.
I don't remember changing it and I haven't imported any settings for sure, so I guess it's by default disabled.
With the IntelliJ Idea version 2020.3:
Go to File > Sttings > Editor > General > On Save
And then select/deselect "Ensure every saved file ends with a line break"
With the Intellij version 2022.3.1
Preferences (cmd + ,) > Editor > General > Ensure every saved file ends with a line break
Check, apply, and click ok
intellij
How to make phpstorm display line numbers by default?
Couldn't find that option. It's kind of annoying to turn them on manually for each page.
Settings (or Preferences if you are on Mac) | Editor | General | Appearance and check Show line numbers.
Just now found where is it on Windows. Its View -> Active Editor -> Show Line Numbers (changes only for current document) and File -> Settings -> Editor -> Appearance -> Show Line Numbers (for all documents)
For Mac Version go to PhpStorm -> Preferences in menu.
In the preference window go to IDE settings -> Editor -> Appearance -> Show Line Numbers (To change setting for all documents)
OR if you want to quickly set show line number PER CURRENT WINDOW even easier - right click on the long white column (where breakpoints are set) then select Show Line Numbers.
Red dot on the screenshot is a place where you have to click
All the guys are right. I am just bringing the the current soultion with the images.
Go to File-> Settings
In the box in the top right corner type in line numbers, just below that choose Editor->Appearance, from the right checkboxes, find Show line numbers and check it.
After that hit Apply and OK
That should do the trick.
My version of PhpStorm is 6.0.3
If you're on a Mac:
PhpStorm -> Preferences... -> Editor -> Appearance -> Show Line Numbers
just double tap 'Shift'
and search for 'Line Numbers'
and there you will see a toggle option on or off
In PHPStorm 8 this setting is no longer under 'Appearance' but now in:
File -> Settings -> Editor -> Appearance -> Show line numbers
Follow the below steps:
Click on File->Settings->
In the Settings dialog box Expand Editor under IDE Settings
Click Apperance - > select Show line numbers.
Click Apply->Ok.
Simplest solution for line numbers in php storm..There are many other solutions but i think A big picture a good from 1000 words.
File -> Settings -> Editor -> General -> Appearance
check "Show Line Numbers"
This is the current location as of phpStorm 8.0.2 on Ubuntu 14.04
Settings -> editor | appearance | Show line numbers
Just right click on left side where line numbers generally show, select "show line numbers"
In PHPStorm 2016: File > Settings > Editor > General > Appearance > check "Show line numbers"
By typing command + shift + A you will get a search prompt and write line numbers . Now you can trigger button on or off
For PhpStorm version 9 on Windows.
File→Settings→Editor→General→Appearence then check Show line numbers
in the top right corner is a search button type show line numbers and you will see a toggle option. this way you never have to do it yourself. :)
File->settings->IDE Settings->Editor->Appearance
And just check the "Show line numbers" works with 8.0.1
On the Mac version 8.0.1 has this setting here:
PhpStorm > Preferences > Editor (this is in the second section on the left - i.e. IDE Settings NOT Project Settings) > Appearance > Show line numbers
You should go to: File -> Settings -> Editor -> General -> Appearance -> Show Line Numbers
As of the latest version:
PhpStorm > Preferences.. > Editor > General > Appearance > Show line numbers
Using SQLDeveloper 2.1.1.64, if you try typing the following code:
DECLARE
v_status_code NUMBER;
v_status_text VARCHAR2(30);
v_to_delete NUMBER := 5;
BEGIN
PACKAGE_NAME.Delete(v_to_delete, v_status_code, v_status_text);
END;
Pressing Enter after the PACKAGE_NAME.Delete(...) line will make Delete go into all caps (DELETE). I have turned off Case Change in the SQL Formatter options but this still happens. I get other problems similar to this one, where it will randomly reformat lines of code, but I couldn't think of an example as consistent as this. The specific package name doesn't matter, and it does this even if PACKAGE_NAME is in UpperCamelCase.
I don't know if this is a bug with SQLDeveloper or if I'm missing some settings somewhere. It seems as though the SQL Formatter settings under Tools > Preferences > Database > SQL Formatter > Oracle Formatting don't do it, so I don't know what to do. It's getting annoying having to catch some of these format changes, which I sometimes only notice when doing a diff.
Under Tools > Preferences > Code Editor > Completion Insight there is an option for 'Change case as you type'.
But I do not think it will do what you are looking for. Unchecked it will either make it all lower case or all uppercase depending on what you have inputted so far. I am not sure if it will do it the way you are wanting.
I believe you want to disable the annoying option that is changing to UPPERCASE text when you type. Go to Tools > Preferences > Code Editor > Completion Insight > Uncheck "Change case as you type"
Go to Tools > Preferences > Code Editor > Format > Advanced Format > General > change from "lower" to "Keep Unchanged"
Format using Ctrl + F7, it will not change identifier case.