aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/edit.c6
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/testdir/test_tab.vim36
3 files changed, 40 insertions, 4 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 110494bb5c..31bb00a746 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -8206,7 +8206,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
want_vcol = (want_vcol / curbuf->b_p_sw) * curbuf->b_p_sw;
} else {
want_vcol = tabstop_start(want_vcol,
- curbuf->b_p_sts,
+ get_sts_value(),
curbuf->b_p_vsts_array);
}
@@ -8703,10 +8703,10 @@ static bool ins_tab(void)
temp = (int)curbuf->b_p_sw;
temp -= get_nolist_virtcol() % temp;
} else if (tabstop_count(curbuf->b_p_vsts_array) > 0
- || curbuf->b_p_sts > 0) {
+ || curbuf->b_p_sts != 0) {
// use 'softtabstop' when set
temp = tabstop_padding(get_nolist_virtcol(),
- curbuf->b_p_sts,
+ get_sts_value(),
curbuf->b_p_vsts_array);
} else {
// otherwise use 'tabstop'
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 2a09c664dd..70d4f02f5a 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -7347,7 +7347,7 @@ int get_sw_value(buf_T *buf)
}
/// Return the effective softtabstop value for the current buffer,
-/// using the effective shiftwidth value when 'softtabstop' is negative.
+/// using the shiftwidth value when 'softtabstop' is negative.
int get_sts_value(void)
{
long result = curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
diff --git a/src/nvim/testdir/test_tab.vim b/src/nvim/testdir/test_tab.vim
index b847dbd962..3be30245b9 100644
--- a/src/nvim/testdir/test_tab.vim
+++ b/src/nvim/testdir/test_tab.vim
@@ -1,3 +1,4 @@
+" Various tests for inserting a Tab.
" Tests for "r<Tab>" with 'smarttab' and 'expandtab' set/not set.
" Also test that dv_ works correctly
@@ -43,3 +44,38 @@ func Test_smarttab()
enew!
set expandtab& smartindent& copyindent& ts& sw& sts&
endfunc
+
+func Test_softtabstop()
+ new
+ set sts=0 sw=0
+ exe "normal ix\<Tab>x\<Esc>"
+ call assert_equal("x\tx", getline(1))
+
+ call setline(1, '')
+ set sts=4
+ exe "normal ix\<Tab>x\<Esc>"
+ call assert_equal("x x", getline(1))
+
+ call setline(1, '')
+ set sts=-1 sw=4
+ exe "normal ix\<Tab>x\<Esc>"
+ call assert_equal("x x", getline(1))
+
+ call setline(1, 'x ')
+ set sts=0 sw=0 backspace=start
+ exe "normal A\<BS>x\<Esc>"
+ call assert_equal("x x", getline(1))
+
+ call setline(1, 'x ')
+ set sts=4
+ exe "normal A\<BS>x\<Esc>"
+ call assert_equal("x x", getline(1))
+
+ call setline(1, 'x ')
+ set sts=-1 sw=4
+ exe "normal A\<BS>x\<Esc>"
+ call assert_equal("x x", getline(1))
+
+ set sts=0 sw=0 backspace&
+ bwipe!
+endfunc