How to change indentation mode in Atom? - indentation

I haven't been able to figure this out yet. Atom seems to use spaces as the default indentation mode. I prefer to have tabs instead though. Sublime Text has built in functionality for switching and converting indentation.
Anyone found out how to change the indentation mode of Atom?
Some screenshots from Sublime Text:

See Soft Tabs and Tab Length under Settings > Editor Settings.
To toggle indentation modes quickly you can use Ctrl-Shift-P and search for Editor: Toggle Soft Tabs.

Go to File -> Settings
There are 3 different options here.
Soft Tabs
Tab Length
Tab Type
I did some testing and have come to these conclusions about what each one does.
Soft Tabs - Enabling this means it will use spaces by default (i.e. for new files).
Tab Length - How wide the tab character displays, or how many spaces are inserted for a tab if soft tabs is enabled.
Tab Type - This determines the indentation mode to use for existing files. If you set it to auto it will use the existing indentation (tabs or spaces). If you set it to soft or hard, it will force spaces or tabs regardless of the existing indentation. Best to leave this on auto.
Note: Soft = spaces, hard = tab

Add this to your ~/.atom/config.cson
editor:
tabLength: 4

OS X:
Go to Atom -> prefrences or CMD + ,
Scroll down and select "Tab Length" that you prefer.

You could try going to "Atom > Preferences > Editor" and set Tab length to 4.
This is for mac. For windows you will have to find the appropriate menu.

Adding #Manbroski answer here that worked for me:
try Ctrl-Shift-P Editor: Toggle Soft Tabs

Late to the party, but a clean way to do this on a per-project basis, is to add a .editorconfig file to the root of the project. Saves you from having to change Atom's settings when you're working on several projects simultaneously.
This is a sample of a very basic setup I'm currently using. Works for Atom, ST, etc...
http://editorconfig.org/
# Automatically add new line to end of all files on save.
[*]
insert_final_newline = true
# 2 space indentation for SASS/CSS
[*.{scss,sass,css}]
indent_style = space
indent_size = 2
# Set all JS to tab => space*2
[js/**.js]
indent_style = space
indent_size = 2

This is built into core: See Settings ⇒ Tab Type and choose auto:
When set to "auto", the editor auto-detects the tab type based on the contents of the buffer (it uses the first leading whitespace on a non-comment line), or uses the value of the Soft Tabs config setting if auto-detection fails.
You may also want to take a look at the Auto Detect Indentation package. From the docs:
Automatically detect indentation of opened files. It looks at each opened file and sets file specific tab settings (hard/soft tabs, tab length) based on the content of the file instead of always using the editor defaults.
You might have atom configured to use 4 spaces for tabs but open a rails project which defaults to 2 spaces. Without this package, you would have to change your tabstop settings globally or risk having inconsistent lead spacing in your files.

I just had the same problem, and none of the suggestions above worked. Finally I tried unchecking "Atomic soft tabs" in the Editor Settings menu, which worked.

If you are using the version 1.21.1:
Click on Packages / Settings View / Open
Select "Editor" on the left side panel
Scrool down until you see "Tab Length"
Edit the value. I like to set it to 4.
Now, just close the active tab pane and you are done.

Tab Control gives nice control in a similar manner to that described in your question.
Also nice, for JavaScript developers, is ESLint Tab Length for using ESLint config.
Or if you're using an .editorconfig for defining project-specific indentation rules, there is EditorConfig

If you're using Babel you may also want to make sure to update your "Language Babel" package. For me, even though I had the Tab Length set to 2 in my core editor settings, the Same setting in the Language Babel config was overriding it with 4.
Atom -> Preferences -> Packages -> (Search for Babel) -> Grammar -> Tab Length
Make sure the appropriate Grammar, There's "Babel ES6 Javascript Grammar", "language-babel-extension Grammar" as well as "Regular Expression". You probably want to update all of them to be consistent.

If global tab/spaces indentation settings no longer fit your needs (I.E. you find yourself working with legacy codebases with varied indentation formats, and you need to quickly switch between them, and the auto-detect isn't working) you might try the tab-control plugin, which sort of duplicates the functionality of the menu in your screenshot.

When Atom auto-indent-detection got it hopelessly wrong and refused to let me type a literal Tab character, I eventually found the 'Force-Tab' extension - which gave me back control.
I wanted to keep shift-tab for outdenting, so set ctrl-tab to insert a hard tab. In my keymap I added:
'atom-text-editor':
'ctrl-tab': 'force-tab:insert-actual-tab'

Changing language-specific configuration
I changed the default tab settings, and it still did not impact when I was editing my files, which were Python files. It also did not change when I modified the "*" setting in ~/.atom/config.cson . I don't have a good explanation for either of those.
However, when I added the following to my config.cson, I was able to change the tab in my Python files to 2 spaces:
'.source.python':
editor:
tabLength: 2
Thanks to this resource for the solution: Tab key not respecting tab length

All of the most popular answers on here are all great answers and will turn on spaces for tabs, but they are all missing one thing. How to apply the spaces instead of tabs to existing code.
To do this simply select all the code you want to format, then go to Edit->Lines->Auto Indent and it will fix everything selected.
Alternatively, you can just select all the code you want to format, then use Ctrl Shift P and search for Auto Indent. Just click it in the search results and it will fix everything selected.

Yet another answer: If you are using Atom Beautify note that it has its own settings to determine the "Indent Char".

Related

Kate Text Editor regexp for CNC code alteration on PC

When using some CAM software, the CNC code is usually generated properly with spaces.
But for example when moved to "Citizen Cincom L20" machine via USB or network and edited there it lose spaces and also lose semicolons while preserving new lines which does work as semicolons anyway.
But since editing of CNC program happens in 3 places: CAM Software(ESPRIT in this case), CNC machine controller and also via text editor on the computer as postprocessor in ESPRIT is garbage.I've come up with this regex
([0-9]{1,2})([A-Z])
\1 \2
so
G1G99X5.4Z-.5F.12
Becomes
G1 G99 X5.4 Z-.5 F.12
that works in Kate to space everything back again for clearer reviwing of code. The only issue about it is that I need to do that manually for every file and I would like to automate it, preferably via Kate, so it would happen upon opening any ????.PRG plain text files.
But I do not exactly know how such happening should be called is it like macro or what ?
I'm looking for some suggestions to accomplish this. Or maybe some alternative solutions
First, go to View -> Tool Views -> Show Search and Replace. You will see
Make sure you:
Enable {} regex option on the right as you are using a regex
Enable "AB" option on the right that enables case sensitive matching
Select In Folder value from the dropdown on the right
Fill out the regex, replacement, Folder and the Filter fields with the appropriate values
Click Search button.
You will see the results in a separate pane and Replace / Replace Checked buttons will become enabled.
Review the replacements and click Replace Checked:
Then you may check the updated file contents, and if you are satisifed with the results, use Save All, also by pressing CTRL+L.

Navigate to the file from output in the terminal - WebStorm

Is it possible to tune WebStorm so that when I have something like this in my terminal window, then I just click on the filename and jump to it.
Not possible using built-in terminal (please vote for IDEA-118566 and IDEA-154439).
Awesome Console plugin might be a solution; but it doesn't support built-in terminal (https://github.com/anthraxx/intellij-awesome-console/issues/23)
there is also Output Link Filter plugin that provides similar functionality, but it looks outdated and (also) doesn't work in built-in terminal
Update (2022): IDEA-118566 is already fixed, links should work. Please note that providing links for particular output needs adding specific logic handing such output. Thus, if you encounter missing links in a particular output, please file a separate issue request describing link output format and steps to reproduce such output.
Webstorm does in fact now have this functionality.
Note that the bug about this functionality being missing (linked in another answer) has been marked as fixed: https://youtrack.jetbrains.com/issue/IDEA-118566.
It's not quite a single click solution, but what I do, is double click the text so that it auto selects and copies the path, including line and char numbers to clipboard. Then use the shortcut for Goto File.... Hit paste (cmd+v) then Enter and it will take you to the exact location.
For me, the shortcut for Goto File... is cmd+shift+O - you can check your shortcut in the menu Navigate -> File...
You can use the following format to output text in the terminal via console.log and the path will be clickable:
at ($FILE_FULL_PATH:$LINE_NUMBER:$SYMBOL_NUMBER)
Example with the full path to the file:
at (/home/ubuntu/project/index.js:12:55)
However, if you're running WebStorm with exact file path's project's folder, you can use the following format:
at (./project/index.js:12:55)
I installed Awesome Console plugin and with this plugin, all files and links in the console and terminal will be highlighted and can be clicked. Source code files will be opened in the IDE, other links with the default viewer/browser for this type.
You can jump to files from the terminal with left click
Just select file path (dblclick) & press "shift" twice (search everywhere) & press "enter"...

netbeans blank line after if statement

In netbeans how can one format it so that after if-blocks there is a blank line? I have been searching through the formatting options and trying different things to no avail.
e.g.
if ($lifegivesyoulemons) {
echo "say f' it and bail";
}
if ($if_they_take_my_stapler) {
echo "i will set the building on fire";
}
Not specifically for if-else loop this should work for all methods also.
In your Netbeans IDE goto Tools - then select Editor tab.
Under Editor tab select Formatting select language PHP (as per your if-else loop in question) and Category Blank Lines
And then scroll down in After Function field change value 0 to 1 like this
Click on Apply and Ok
Now select On Save tab. Select language PHP
Uncheck Use all language settings. After that from drop down select All Lines. Click on Ok
Now you type code hit Ctrl + S Netbeans automatically formats your code with one blank line after } brace (bracket). (As of I know this should work both methods and loops also).

JetBrains WebStorm ignores Indentation Settings

In Settings > Code Style > JavaScript I've set Tab size and Indent to 4. Why is WebStorm still ignoring these settings, as you can see in the preview window:
What settings could override these?
If you have EditorConfig plugin enabled (which should be by default) and have .editorconfig files in your project (or maybe even above the project root) then settings from there will override your Code Style (which is expected as this is the whole point of such plugin).
Why such behaviour? What can be done?
Please check what .editorconfig files are for -- they meant to be editor-independent. It meant to override your internal settings to provide consistency across different IDEs/editors used without the need to configure your IDE/editor just for this project/folder
You are editing Code Style settings and not actual EditorConfig settings
With .editorconfig you can do things that are not currently possible with Code Style (e.g. different right margins / trailing white space handling per different file types, even if they are not supported by Code Style)
Code Style is applied to the whole project (all files) while .editorconfig can be configured differently for each sub-folder and even have exclusions.
IDE should be showing you the notice (using light GUI theme it would be green bar on top of the editor window) where it would tell that "Settings may be overridden by EditorChonfig." -- I'm just not sure if it's available in WebStorm v11, or is it since v12 only.
If you go one level up in your settings (just Code Style and not Code Style > JavaScript as on your screenshot) you will see mention of this moment as well
You may file Feature Request ticket for such "update .editorconfig file while editing Code Style" idea at JetBrains' Issue Tracker.
Example .editorconfig file:
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false

Is it possible to use different tags files for omnicomplete and general tag browsing in Vim?

I've been using ctags in Vim for years, but I've only just discovered omnicomplete. (It seems good.)
However, I have a problem: to get omnicomplete working properly I have to use the --extra=+q option when generating the tags, which is fine, but this then changes the behaviour of general tag browsing in ways that I do not like.
For example, when tab-completing tag names in Vim I don't want to tag "into" the "hierarchies" of classes - that is, when tab completing "Clas" get "ClassA, ClassA::var1, ClassA::var2, ClassB", instead of "ClassA, ClassB" - but that's what happens when using --extra=+q.
So I guess I'm after one of two things. Either:
1. The ability to disable tab-completing into "tag hierarchies" even though those hierarchies do exist in the tags file. Or,
2. The ability to use differently named tags files (ie. generated with different options) for omnicomplete and general tag browsing.
Any ideas would be much appreciated!
Cheers,
thoughton.
OK, I think I've actually come up with an answer to my own question.
Firstly, I generate two tags files: tags_c_vim and tags_c_omni.
In my _vimrc I have:
let tags_vim='tags_c_vim'
let tags_omni='tags_c_omni'
exe "set tags=".tags_vim
to setup some variables pointing to the different tags files, and to set the "vim" tags to be the default tags.
Then I also have this, again in the _vimrc:
imap <F8> <ESC>:exe "set tags=".tags_omni<CR>a<C-X><C-O>
autocmd InsertLeave * if pumvisible() == 0|exe "set tags=".tags_vim|endif
the first line here maps F8 so it changes the tags setting to point to the "omni" tags before then invoking the omnicomplete popup menu, and the second line resets the tags setting to the "vim" tags when insert mode is next left after the popup has closed.
It's going to need some extensive use to make sure it's robust enough, but it does seem to work after some quick testing.
Two improvements I'd still like to make:
Map the setting of the "omni" tags to the omnicomplete C-X,C-O command instead of a new F8 mapping. (I think I need to set the tags and then call omni#cpp#maycomplete#Complete(), but I couldn't work out how to do this)
Hook the resetting of the "vim" tags into either omnicomplete itself finishing or the popup menu closing
Anyway, I just thought I'd share.
Cheers,
thoughton.
You could try the OmniCppComplete plugin.