Vimscript - 获取当前行的缩进

时间:2017-09-07 07:54:24

标签: vim

vim-script 中,我如何可靠地为变量分配当前行的缩进?

curpos()获取 col 似乎不可靠,因为它只计算空格,我还需要考虑tabstops。

1 个答案:

答案 0 :(得分:5)

使用indent()功能;来自:help indent()

indent({lnum})  The result is a Number, which is indent of line {lnum} in the
                current buffer.  The indent is counted in spaces, the value
                of 'tabstop' is relevant.  {lnum} is used just like in
                getline().
                When {lnum} is invalid -1 is returned.