Skip to content

Commit 9edac64

Browse files
committed
Set shiftwidth to 0 (defaults to tabstop value)
The current behavior is to set both shiftwidth and tabstop/softtabstop. shiftwidth gets set to the same value as tabstop. If I open a file that editorconfig indents with 8-space hard tabs, then ":set tabstop=4", my shiftwidth will still be 8, meaning that when I indent I will get two tabs. Set shiftwidth to 0, which defaults to the value of tabstop, and doesn't set softtabstop either. This should have the same end result with less complication. This removes the g:EditorConfig_softtabstop_space and g:EditorConfig_softtabstop_tab options, as we now don't need to touch softtabstop at all.
1 parent 1d54632 commit 9edac64

File tree

3 files changed

+15
-50
lines changed

3 files changed

+15
-50
lines changed

doc/editorconfig.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,6 @@ max_line_length is set:
173173
<
174174
This option defaults to 0.
175175

176-
*g:EditorConfig_softtabstop_space*
177-
When spaces are used for indent, Vim's 'softtabstop' feature will make the
178-
backspace key delete one indent level. If you turn off that feature (by
179-
setting the option to 0), only a single space will be deleted.
180-
This option defaults to 1, which enables 'softtabstop' and uses the
181-
'shiftwidth' value for it. You can also set this to -1 to automatically follow
182-
the current 'shiftwidth' value (since Vim 7.3.693). Or set this to [] if
183-
EditorConfig should not touch 'softtabstop' at all.
184-
185-
*g:EditorConfig_softtabstop_tab*
186-
When tabs are used for indent, Vim's 'softtabstop' feature only applies to
187-
backspacing over existing runs of spaces.
188-
This option defaults to 1, so backspace will delete one indent level worth of
189-
spaces; -1 does the same but automatically follows the current 'shiftwidth'
190-
value. Set this to 0 to have backspace delete just a single space character.
191-
Or set this to [] if EditorConfig should not touch 'softtabstop' at all.
192-
193176
*g:EditorConfig_verbose*
194177
Set this to 1 if you want debug info printed:
195178
>

plugin/editorconfig.vim

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ if !exists('g:EditorConfig_enable_for_new_buf')
6464
let g:EditorConfig_enable_for_new_buf = 0
6565
endif
6666

67-
if !exists('g:EditorConfig_softtabstop_space')
68-
let g:EditorConfig_softtabstop_space = 1
69-
endif
70-
71-
if !exists('g:EditorConfig_softtabstop_tab')
72-
let g:EditorConfig_softtabstop_tab = 1
73-
endif
74-
7567
" Copy some of the globals into script variables --- changes to these
7668
" globals won't affect the plugin until the plugin is reloaded.
7769
if exists('g:EditorConfig_core_mode') && !empty(g:EditorConfig_core_mode)
@@ -395,31 +387,21 @@ function! s:ApplyConfig(config) abort " Set the buffer options {{{1
395387
endif
396388
endif
397389

398-
if s:IsRuleActive('tab_width', a:config)
399-
let &l:tabstop = str2nr(a:config["tab_width"])
400-
endif
401-
402390
if s:IsRuleActive('indent_size', a:config)
403-
" if indent_size is 'tab', set shiftwidth to tabstop;
404-
" if indent_size is a positive integer, set shiftwidth to the integer
405-
" value
406-
if a:config["indent_size"] == "tab"
407-
let &l:shiftwidth = &l:tabstop
408-
if type(g:EditorConfig_softtabstop_tab) != type([])
409-
let &l:softtabstop = g:EditorConfig_softtabstop_tab > 0 ?
410-
\ &l:shiftwidth : g:EditorConfig_softtabstop_tab
411-
endif
412-
else
391+
" When shiftwidth is 0 it uses the value of tabstop
392+
let &l:shiftwidth = 0
393+
if a:config["indent_size"] != "tab"
413394
let l:indent_size = str2nr(a:config["indent_size"])
414395
if l:indent_size > 0
415-
let &l:shiftwidth = l:indent_size
416-
if type(g:EditorConfig_softtabstop_space) != type([])
417-
let &l:softtabstop = g:EditorConfig_softtabstop_space > 0 ?
418-
\ &l:shiftwidth : g:EditorConfig_softtabstop_space
419-
endif
396+
let &l:tabstop = l:indent_size
420397
endif
421398
endif
399+
endif
422400

401+
if s:IsRuleActive('tab_width', a:config)
402+
if a:config["indent_style"] == "tab"
403+
let &l:tabstop = str2nr(a:config["tab_width"])
404+
endif
423405
endif
424406

425407
if s:IsRuleActive('end_of_line', a:config) &&

tests/plugin/spec/editorconfig_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ def test_instance(vim)
3535
it '3_space.py' do
3636
test_editorconfig vim, '3_space.txt',
3737
expandtab: '1',
38-
shiftwidth: '3',
38+
shiftwidth: '0',
3939
tabstop: '3'
4040
end
4141
end
4242

4343
it '4_space.py' do
4444
test_editorconfig vim, '4_space.py',
4545
expandtab: '1',
46-
shiftwidth: '4',
47-
tabstop: '8'
46+
shiftwidth: '0',
47+
tabstop: '4'
4848
end
4949

5050
it 'space.txt' do
5151
test_editorconfig vim, 'space.txt',
5252
expandtab: '1',
53-
shiftwidth: vim.echo('&l:tabstop')
53+
shiftwidth: '0'
5454
end
5555

5656
it 'tab.txt' do
@@ -61,14 +61,14 @@ def test_instance(vim)
6161
it '4_tab.txt' do
6262
test_editorconfig vim, '4_tab.txt',
6363
expandtab: '0',
64-
shiftwidth: '4',
64+
shiftwidth: '0',
6565
tabstop: '4'
6666
end
6767

6868
it '4_tab_width_of_8' do
6969
test_editorconfig vim, '4_tab_width_of_8.txt',
7070
expandtab: '0',
71-
shiftwidth: '4',
71+
shiftwidth: '0',
7272
tabstop: '8'
7373
end
7474

0 commit comments

Comments
 (0)