## FANDOM

1,639 Pages

Tip 303 Printable Monobook Previous Next

created 2002 · complexity basic · author TVIM · version 6.0

I use this function to let me know if my cursor is on a TAB column.

The `t*` on the ruler means I am not. But `t3` means the cursor is on tablevel 3

```~vimrc ----------------------- My Ruler ------------------------ r4,c13,t3

~vimrc ----------------------- My Ruler ------------------------ r4,c14,t*
```

If you want to change a tab level you can drag or push the first character of a line to a desired tab level (more on that later).

This ruler replacement will let you know where you are, whether you like to use space tabs (see VimTip12) or regular tabs. My function is set to four space tabs stops and only goes 9 levels but can be easily modified.

Actually I just wanted to learn how to use a function in my _vimrc and this was my first attempt. Add this to your _vimrc:

```set laststatus=2
"This makes sure the ruler shows. See help laststatus
set statusline=%f\ ---------\ My\ Ruler\ ----------\ r%l,c%c,t%{ShowTab()}
"See help statusline (I toggle between 12 helpful rulers -- more on that later)
fu ShowTab()
let TabLev='*'
let Col=(col("."))
if Col == 1 | let TabLev='0' | en
if Col == 5 | let TabLev='1' | en
if Col == 9 | let TabLev='2' | en
if Col ==13 | let TabLev='3' | en
if Col ==17 | let TabLev='4' | en
if Col ==21 | let TabLev='5' | en
if Col ==25 | let TabLev='6' | en
if Col ==29 | let TabLev='7' | en
if Col ==33 | let TabLev='8' | en
if Col ==37 | let TabLev='9' | en
return TabLev
endf
"The ruler (statusline) shows a t* unless you are on col 1,5,9,13,...
```

This function ShowTab() gets called and updates the ruler with every cursor move but it does not slow things down as I type. Perhaps a speed typist may complain.

## Comments Edit

Looks like the tab level is basically set to ( col( '.' ) - 1 ) / 4. The 4 is probably the value of &ts instead. Of course, this always returns a value even if you're in the middle of a tab (not actually ON a tabstop), so something like this:

```let TabLevel = ( col( '.' ) - 1 ) / &ts
if ( ( TabLevel * &ts + 1 ) != col( '.' ) )
let TabLevel = '*'
endif
```

Works for all levels of tabs. The proof and verification thereof is left to the reader as an exercise.

The 2nd example didn't work for me, so

```fu ShowTab()
let TabLevel = (indent('.') / &ts )
if TabLevel == 0
let TabLevel='*'
endif
return TabLevel
endf
```

Community content is available under CC-BY-SA unless otherwise noted.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7315906,"math_prob":0.7510109,"size":2306,"snap":"2019-51-2020-05","text_gpt3_token_len":663,"char_repetition_ratio":0.20156386,"word_repetition_ratio":0.027149322,"special_character_ratio":0.36253253,"punctuation_ratio":0.08405172,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9855405,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-12T05:58:51Z\",\"WARC-Record-ID\":\"<urn:uuid:c6c9b8ee-b0e3-48f1-826f-5db6b2584aac>\",\"Content-Length\":\"169014\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:91835ca7-0b8d-4e2d-add3-d6ff89c19a6d>\",\"WARC-Concurrent-To\":\"<urn:uuid:58f91879-d116-4f10-a297-b2512264fb79>\",\"WARC-IP-Address\":\"151.101.0.194\",\"WARC-Target-URI\":\"https://vim.fandom.com/wiki/Statusline_tab_level_ruler?veaction=edit\",\"WARC-Payload-Digest\":\"sha1:U7N5DKSBAC64F4ZMEYT7K5Z7QZSTXM5K\",\"WARC-Block-Digest\":\"sha1:K4W5JASYM6ED56P7UKLNICL4H7KLUNPL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540537212.96_warc_CC-MAIN-20191212051311-20191212075311-00497.warc.gz\"}"}