tpope / vim-sleuth

sleuth.vim: Heuristically set buffer options
https://www.vim.org/scripts/script.php?script_id=4375
1.92k stars 86 forks source link

Add instructions on how to set default indenting as in issue #50 #55

Closed dylan-chong closed 2 years ago

dylan-chong commented 6 years ago

Hopefully a good enough for now fix for #50

tpope commented 6 years ago

I think instead of the guard, you probably want to use :setglobal for the top level definitions.

dylan-chong commented 6 years ago

@tpope fixed

dylan-chong commented 6 years ago

@tpope I just realise that your solution of using set global is actually a equivalent to removing those lines altogether.

Using set globals, when I open a new file indenting is still set to tabs. Should I just revert the changes back to what it was before with the guard?

aleclarson commented 6 years ago

Why does the file type-specific command go before the globals? (not a vim expert)

Do I put the setglobal commands before something like vim-plug?

edit: Looks like setglobal doesn't work with vim-plug. I'm using vim 8.0.

dylan-chong commented 6 years ago

@aleclarson i have just updated the instructions can you have a look at it again

aleclarson commented 6 years ago

@dylan-chong set works great. Thanks!

dylan-chong commented 6 years ago

@aleclarson Would you mind hitting approve once you are confident that it works perfectly? I assume @tpope is a little busy, so hopefully this might speed up getting this merged

aleclarson commented 6 years ago

Just noticed an issue. Setting tabstop causes changes to JSON files (eg: adding a new property to a JSON object via a new line) to be indented wrong. You need to add the JSON property, do :wq, then re-open the file to see what I mean.

Here's what I'm doing:

set expandtab
set tabstop=2
set shiftwidth=2
dylan-chong commented 6 years ago

@aleclarson extendtab?

Could you clarify what you mean? I am not sure i understand what you mean

aleclarson commented 6 years ago

@dylan-chong That was a typo. I meant expandtab

dylan-chong commented 6 years ago

i'm still not understanding the problem you're having.

aleclarson commented 6 years ago

You've tried reproducing what I said above?

If you follow those instructions, you should see the newly added JSON property is indented more than it should be.

It may be caused by another plugin if you can't reproduce it.

dylan-chong commented 6 years ago

Sorry I don't understand your instructions. Could you provide your Json file and provide an exact list of commands/keystrokes to run?

minhduc0711 commented 3 years ago

I tried this and it overrides vim-sleuth detection for some reason. I'm not really sure about _has_set_default_indent_settings, idk where it is set in sleuth.vim...

dylan-chong commented 3 years ago

@minhduc0711 _has_set_default_indent_settings is defined only in the snippet

minhduc0711 commented 3 years ago

I see, then how does it know if vim-sleuth has detected the indent settings or not?

dylan-chong commented 3 years ago

It does not :( . iirc it relies on running before sleuth detection is triggered (because the vimrc is loaded before the file being edited is loaded)

minhduc0711 commented 3 years ago

Hmm in that case I don't know why this is not working for me. If I open this tab-indented snippet https://pastebin.com/raw/LHvPPuW8, it would ignore the tabs and default to 4 spaces. Could you please try with your setup?