aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/snippet.lua3
-rw-r--r--test/functional/lua/snippet_spec.lua26
2 files changed, 25 insertions, 4 deletions
diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua
index a1e3360b2d..37416c389f 100644
--- a/runtime/lua/vim/snippet.lua
+++ b/runtime/lua/vim/snippet.lua
@@ -459,8 +459,7 @@ function M.expand(input)
end
-- Add the base indentation.
if i > 1 then
- line = #line ~= 0 and base_indent .. line
- or (expandtab and (' '):rep(shiftwidth) or '\t'):rep(vim.fn.indent('.') / shiftwidth + 1)
+ line = base_indent .. line
end
lines[#lines + 1] = line
end
diff --git a/test/functional/lua/snippet_spec.lua b/test/functional/lua/snippet_spec.lua
index 74f0869200..83bd91bc71 100644
--- a/test/functional/lua/snippet_spec.lua
+++ b/test/functional/lua/snippet_spec.lua
@@ -246,7 +246,7 @@ describe('vim.snippet', function()
it('correctly indents with newlines', function()
local curbuf = api.nvim_get_current_buf()
test_expand_success(
- { 'function($2)\n$3\nend' },
+ { 'function($2)\n\t$3\nend' },
{ 'function()', ' ', 'end' },
[[
vim.opt.sw = 2
@@ -255,7 +255,16 @@ describe('vim.snippet', function()
)
api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
test_expand_success(
- { 'func main() {\n$1\n}' },
+ { 'function($2)\n$3\nend' },
+ { 'function()', '', 'end' },
+ [[
+ vim.opt.sw = 2
+ vim.opt.expandtab = true
+ ]]
+ )
+ api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
+ test_expand_success(
+ { 'func main() {\n\t$1\n}' },
{ 'func main() {', '\t', '}' },
[[
vim.opt.sw = 4
@@ -263,5 +272,18 @@ describe('vim.snippet', function()
vim.opt.expandtab = false
]]
)
+ api.nvim_buf_set_lines(curbuf, 0, -1, false, {})
+ test_expand_success(
+ { '${1:name} :: ${2}\n${1:name} ${3}= ${0:undefined}' },
+ {
+ 'name :: ',
+ 'name = undefined',
+ },
+ [[
+ vim.opt.sw = 4
+ vim.opt.ts = 4
+ vim.opt.expandtab = false
+ ]]
+ )
end)
end)