Intellij: Change project indent from 4 spaces to 2 spaces - intellij-idea

Currently, all of my project files are indented with 4 spaces. I want to change that to 2 spaces as my organization uses 2 as an standard, but can't find any answers.

Depending on your version of IDEA, it should be in your settings under:
Editor > Code Style > (Specific language)
**Edit: Example, in IDEA 2016:
If you don't see it there, I found mine by searching "indent" in the settings window.
Finally, for organization-wide code settings, I highly recommend EditorConfig. It's compatible with just about every IDE out there and lets you enforce code style settings without requiring everyone to manually change their settings to match. IDEA supports it out of the box, without a plugin.

Related

Intellij is using different indention within the same .vue file

In the <template> area Intellij is using 2 spaces for indention and for the <script> part it's using 4 spaces. I get errors running npm run dev because of the different indention.
I have set Intellij to use 4 spaces for all filetypes that I could find (not including JS or .vue). The project itself uses 2 spaces (I would like to change that).
However, now like I said it's using two different indention styles within the same file and that causes a whole lot of problems.
Code -> Reformat code changes the code to this style with 2 different indentions.
Any idea what's going on? Thanks!
First, make sure you don't have Detect and use existing file indents for editing enabled in Settings/Preferences | Editor | Code Style. If you do, when you auto-indent, it might apply the wrong settings.
Then, try reformatting the code using Control+Alt+L or Code -> Reformat Code.

Why are some buttons grayed out in the markdown plugin for IntelliJ?

I'm using this plugin as a markdown plugin in IntelliJ. I tried to make a quick unordered list, but the button is grayed out. In fact, most of the buttons are grayed out. The only ones available to me are simple functions like bold, italics, strikethrough, etc. Here's a screenshot for reference:
I've tried highlighting sections of text, moving my keyboard cursor around, different kinds of markdown--all without any luck of "unlocking" the lists, tables, etc. so I must be doing something wrong. Anyone know?
Enabling the enhanced features using trial license
Goto http://vladsch.com/product/markdown-navigator/try and get a trial license (which will be e-mailed to you).
Then in Intellij, goto Settings -> Language and Frameworks. I noticed that there was already a license installed for me after first installing the Markdown Navigator plugin. However, based on the available features this license is the Basic version only (and had a validity of 73 days for me).
Click on Remove License and then paste the license code that you received in the e-mail. After that you should see this:
From the comments on the official markdown plugin page, it appears that the official plugin is not very stable.
Other free options
I have found the Markdown Navigator plugin to be quite useful and well worth the 20 USD per annum fees. However, if you are looking for just that one off editing of markdown files, then there are other options as well.
The one I find most convenient is the online StackEdit for quick editing tasks:
Best of both the worlds
If your work involves a bit more frequent editing of markdown files and you are averse to paying the licensing fees for for the Markdown Navigator, then with just a bit of work, it's possible and comes close to the convenience of using the Markdown Navigator.
Step 1 - Add an external editor of choice
I have used Typora as an example here, however there are others like Write (Freemium), ReText (Open Source) which can be used in a similar manner.
Here is how to add Typora as an external tool in Intellij Idea:
Note that $Filepath$ should be quoted as "$FilePath$" if there are likely to be spaces in your project path. Would recommend quoting nonetheless.
Also, note that the Group was set to Markdown Editors. This is significant as the Group name will be the name of the Menu item later on.
Step 2 : (Optional but recommended) Add a keyboard shortcut for Typora
Step 3 : Use the external editor!
Typora will now be available both using the keyboard shortcut or using Tools -> Markdown Editors (Remember that Markdown Editors was the name of the group in Step1?)
The following shows using both the keyboard shortcut and the menu item:
Note that, thanks to Intellij's auto-reload/refresh, as soon as you are done editing in Typora and focus the file (Readme.md in the above), the changes are automatically reflected there.
Kind of Enhanced Features will be available only if you have license.
In IntelliJ File | Settings | Languages & Frameworks | Markdown in License Information section you can buy it or use free trial for 15 days.

Can I make IntelliJ IDEAs auto indent ignore previous lines?

Auto-indenting in IntelliJ IDEA seems to automatically takes lines previous to the selection in to consideration. This means that if the indentation is incorrect in the part of the file you're working on (e.g., 3 or 5 spaces where there should be 4, or even worse, a mix of tabs and spaces) it's annoyingly difficult to add correctly indented code.
Both new lines I'm adding and lines I use auto-indent on because I've changed them anyway get messed up like this. Since the file I'm working on is being worked on by someone else as well on another branch, I really don't want to modify over a third of the file just to indent everything correctly, but I would still like the lines that I'm actually modifying/adding to be correct - I don't see any reason to perpetuate the error when it's not necessary.
Currently the best mechanism for fixing it I've found is to manually do the spaces on a line and go from there, but it's really quite annoying, especially since I can't use the tab key or IntelliJ will immediately move to the incorrect indentation. It's barely better than copy/pasting the text to Sublime Text, fix the indentation there and paste it back without formatting.
My apologies if this has already been asked, I've tried to search for it, but it's very hard to search for this as there's so many auto-indent questions.
IntelliJ IDEA recently added a feature (in v14 or 1v4.1 if I recall) where it will detect indentation that is different from your settings. It will honor those indentations (in order to keep the file consistent). Usually as soon as you start editing the file, you get a banner, although that can be turned off. The banner looks like this:
This allows you to modify this setting on a per file basis, or turn it off completely (i.e. the "Show Settings" option).
I suspect this feature is what is causing you the issue. I am not sure how it handles a case where a file has mixed indentation (e.g. most of the file is 4, but some sections are 3 or 5 spaces). You can try turning this feature off in Settings > Editor > Code Style > "Detect and use existing file indents for editing"

IntelliJ auto detect indentation for each file

I recently switched from Sublime Text to IntelliJ and I trying to figure out, if there's a way for IntelliJ to auto detect what indentation the current file is using and use that instead of the default
I have to deal with a lot of 3rd party code, which can have different indentation settings, which I'm not allowed to change for obvious reasons.
Sublime Text was able to detect and abide to the indentation for the current file, which is quite intuitive and unobtrusive. IntelliJ on the other hand just sticks to it's own settings, resulting in mixed tabs and spaces, wrong indentation levels and wrong merge conflicts.
Is there a way to make IntelliJ behave, other than having to manually change the indentation settings every time I get a file with different indentation.
Thanks
In recent versions of Intellij there is a Detect and use existing file indents for editing setting for this:
Each project you open in IntelliJ has it's own settings. You will need to set the indent style the first time you open up the project, but it will be saved after that (and can be different for every project you work on). From the IntelliJ help site:
Project settings are stored with each specific project as a set of xml files
under the .idea folder. If you specify the
default project settings,
these settings will be automatically used for each newly created project.
You can edit the indent settings for the project in the Code Style dialog.

intellij messes up with tabs in non-program files

so i just spent some time fussing over why my String.split call in scala failed - i was trying to split on a tab.
Problem wasn't what i was doing, but rather the fact that intelliJ changes tabs to spaces. Fair enough, but can i tell intelliJ to not do that for some files - like say random text files I might be using for test/learning purposes?
First, I would turn on Settings > Editor > Appearance > Show whitespaces, that way you're SURE what white space characters are there.
Next, under Settings > Code Style > General there should be a Use tab character check box. This says "use tabs for anything that's not Java, Scala, HTML, etc.". Just make sure Java, Scala*, etc. Use tab character setting is set to what you want.
Unfortunately, I don't know of any way to be more fine grained with what file types do and do not use tabs vs. spaces.
*I'm assuming the IntelliJ Scala plugin adds a tab in Settings > Code Style.