Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vimscript - get current line's indentation

Tags:

vim

In vim-script, how would I go about reliably assigning to a variable the indentation for the current line?

curpos() to get the col does not seem reliable, as it only counts spaces, and I would need to take into account the tabstops as well.

like image 688
Guy Waldman Avatar asked Oct 12 '25 23:10

Guy Waldman


1 Answers

Use the indent() function; from :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.
like image 135
Martin Tournoij Avatar answered Oct 15 '25 10:10

Martin Tournoij