When expandtab
is set, how to let the indent function defined in file vim/indent/xxx.vim
use tabs, rather than spaces to indent lines?
Edit:
Here is the background. I have use vim's built-in CHANGELOG
syntax to write some change log, using a tab to indent but use spaces to align (|------>
means a tab):
1.0.1 - 2021-03-21 lxvs
|------>* BUGFIX: some-bug...
|------>* IMPROVEMENT: quite a long long long
|------> improvement.
I want to let vim auto format the line 5 as shown above by means of the indent function and thought of a workaround that let the line indent one less space and insert a tab into the begining of the line:
function! ClogIndent(lnum)
let l:prevlnum = prevnonblank(a:lnum-1)
if l:prevlnum == 0
return 0
endif
let l:prevl = getline(l:prevlnum)
let l:thisl = getline(a:lnum)
let l:previ = indent(l:prevlnum)
let l:ind = l:previ
if l:thisl =~ '\*\s\a\+:\s'
return l:ind
endif
if l:prevl =~ '\*\s\a\+:\s'
if matchstr(l:thisl, '\%1c.') !~ '\t'
call setline(a:lnum, substitute(l:thisl, '^', '\t', ""))
endif
let l:word = match(l:prevl, '\(\*\s\a\+:\s\)\@<=\w')
let l:ind = l:word - 1
endif
return l:ind
endfunction
I'm quite sure that call setline(a:lnum, substitute(l:thisl, '^', '\t', ""))
was called, but it seems has no effect. Howevert, it works well when typed manually. Why is that?