Vimscript-获取当前行的缩进

Guy*_*man 2 vim

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

curpos()要获得col似乎并不可靠,因为它仅计算空格,我也需要考虑tabstops。

Mar*_*oij 6

使用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.
Run Code Online (Sandbox Code Playgroud)