Sublime editor: how to force all files to use spaces or tabs? - sublimetext3

I use Sublime 3.0 editor and my editor switches to Spaces: 2 for any *.vue file and if I open a JS file, it switches to Tab: 4. This is causing issues with my linter. How can I set a standard for all files?

// Set to false to disable detection of tabs vs. spaces on load
"detect_indentation": true,
This setting defaults to being turned on, and when it is Sublime will analyze files as they're loaded to try and detect how they're indented. That will cause it to switch from using tabs to spaces if the file seems to be indented one way or the other, and for space indented files it can also adjust the tab_width setting as appropriate.
Turning the setting off will stop it from doing that, which will leave the settings as they are even if they don't match what the current file looks like.

Related

Text showing misaligned in Vim vs Cat

I've been using vim for a few weeks, and so far I've downloaded a few plugins including airline, nerdtree, and a colorscheme. When I downloaded some files with wget, I noticed that they weren't properly aligned. Text in the code files are normally supposed to be aligned in columns, and there generally shjouldn't be issues with indentation. As an example, when I try running the command cat filename.extension, I get this:
This is how the file is supposed to look. Everything is aligned neatly into columns without any issues. However, if I try editing the file in Vim, it instead looks like this:
The text for whatever reason is not aligned properly, and so far I am not sure how to resolve it...
The file appears to be using tabulations for indentation and alignment.
The de-facto standard width of a tabulation is 8 characters.
cat respects that "standard" to the letter, without the possibility of changing the tabulation width.
Vim also respects it by default but it allows the user to change the tabulation width and you tell it to use a tabulation width of 4 characters.
The file looks different because the two programs have different tabulation settings.
Therefore, if you want the file to look the same in the two programs, use the same tabulation settings. Since they can't be changed in cat, you will have to revert Vim's to their default values.
You didn't show us your vimrc so we don't know exactly what you did and we can't really tell you how to go about it.

Sublime Text 3 is automatically converting spaces to tabs on save, regardless of settings. How can I stop this?

I'm having trouble with Sublime Text 3.
Even if I select View > Indentation > Convert tabs to spaces and View > Indentation > Indent using spaces as soon as I save the file it all automatically gets converted to tabs.
How can I stop this behaviour from occurring?
I'm currently using default config settings for this:
// The number of spaces a tab is considered equal to
"tab_size": 4,
// Set to true to insert spaces when tab is pressed
"translate_tabs_to_spaces": false,
// If translate_tabs_to_spaces is true, use_tab_stops will make tab and
// backspace insert/delete up to the next tabstop
"use_tab_stops": true,
// Set to false to disable detection of tabs vs. spaces on load
"detect_indentation": true,
// Calculates indentation automatically when pressing enter
"auto_indent": true,
// Makes auto indent a little smarter, e.g., by indenting the next line
// after an if statement in C. Requires auto_indent to be enabled.
"smart_indent": true,
The problem for me was the EditorConfig plugin, when disabling it in PackageControl the problem went away.
Alternatively you can just edit the problematic .editorconfig file and just comment out (or set to false) the trim_trailing_whitespace option.
Use the indentation option under the tab View.
You can select Tab Width:2
My solution was to give up and switch to VSCode. I wasn't happy about it. I resisted. I cursed. But in the end I had to give in as it is way better. I spend far less time fiddling with editor config and more time coding.
You have two solutions:
To do "View > Indentation > Convert tabs to spaces" before saving
the file.
To replace them as a normal text by pressing Ctrl + H. >>> Find all Tabs >>> Replace with 4 spaces

SublimeText: Change line endings of all files in a project

Sublime Text 3 has a very useful feature to change Windows to Unix line endings on a file per file basis under View > Line Endings. Is it possible to do this for a whole project and/or directory at once?
Thanks
The Line​Endings plugin / package is small, but works like a charm Visit it's GitHub repository to get a few details, because on its Package Control page there is no description.
It not only works, but also gives you an additional functionality -- you can change not only line endings, but also indentation method of all open files in one step.
After installation:
1-Open all files, in which you want to convert / change line endings and/or indentation method.
2-Press Ctrl+Shift+P, to bring Command Pallete and start typing lin to locate Line Ending to all views: Windows (for example).
3-Select it, hit Enter, and... you're done!
4-Repeat step 2, but type spaces to locate Indentation: Convert to all views to Spaces or tabs to locate Indentation: Convert to all views to Tabs to change indentation method of all open files.

How can I save my vim split windows layout?

I like to split a window(about 10 lines, top of the screen) when I'm writing something, in order to reference some other files easily.
I want to save the windows layout(just the splitting layout without the editing files), so that I can start working quickly.
I tried to put
set sessionoptions-=blank
set sessionoptions-=tabpages
set sessionoptions-=winsize
in .vimrc and then
:mksession file.vim
but when I try to vim -S file.vim, I can't see the layout but a new windows, why?
Thank you
Try this:
:set sessionoptions=blank,winsize,tabpages,resize
When you do -=, you are removing those options from sessionoptions. I assume you probably want to use += instead. By default, sessionoptions is set to buffers,winsize,options,help,blank. By using =, you are getting rid of all the options you don't want.

How do I make commands like cat and less keep tab characters?

Is there a way to make cat, less etc. print tab characters instead of tabs being converted to spaces? I am annoyed by this when I copy code from the terminal to an editor.
I am seeing two problems here.
First, destination editor can covert TAB to number of spaces. Some
editor has default feature to convert TAB to number of spaces. If
you disable this feature TAB character you copied from terminal will
be copied as TAB(instead of space) to an editor.
Windows Notepad++ has similar feature
. If you are using vim, this page will be helpful for
vim tab and space conversion
Another, source file in your case terminal may be representing tab
as spaces, please check that first. You can use cat -t filename to
see if you have any TAB in source file or not. That command will
display TAB character as ^I.
It seems this is not possible with less (see answer to the same question on unix.stackexchange).
As a workaround, it works with cat or, for some minimal paging capabilities, with the more command.

Resources