Vim Tips Wiki
m (Statusline Tab Level Function Ruler TVIM moved to Statusline tab level ruler: Page moved by JohnBot to improve title)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=303
 
|id=303
  +
|previous=302
|title=Statusline Tab Level Function Ruler TVIM
 
  +
|next=304
|created=August 8, 2002 2:05
+
|created=August 8, 2002
 
|complexity=basic
 
|complexity=basic
|author=TVIM Tamed Vim
+
|author=TVIM
 
|version=6.0
 
|version=6.0
 
|rating=-1/3
 
|rating=-1/3
 
}}
|text=
 
I use this function to let me know if my cursor is on a TAB column.
+
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
+
The <tt>t*</tt> on the ruler means I am not. But <tt>t3</tt> means the cursor is on tablevel 3
   
  +
<pre>
~vimrc ----------------------- My Ruler ------------------------ r4,c13,t3
+
~vimrc ----------------------- My Ruler ------------------------ r4,c13,t3
   
~vimrc ----------------------- My Ruler ------------------------ r4,c14,t*
+
~vimrc ----------------------- My Ruler ------------------------ r4,c14,t*
  +
</pre>
   
If you want to change a tab level you can drag or push the first character
+
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.
of a line to a desired tab level. (more on that later)
 
   
 
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:
This ruler replacement will let you know where you are, whether you
 
   
  +
<pre>
like to use space tabs (see [[VimTip12]] ) or regular tabs. My function is set
 
 
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,...
  +
</pre>
   
 
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.
to four space tabs stops and only goes 9 levels but can be easily modified.
 
   
 
==Comments==
 
Looks like the tab level is basically set to ( col( '.' ) - 1 ) / 4. The 4 is probably the value of &amp;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:
   
  +
<pre>
 
let TabLevel = ( col( '.' ) - 1 ) / &amp;ts
 
if ( ( TabLevel * &amp;ts + 1 ) != col( '.' ) )
 
let TabLevel = '*'
 
endif
  +
</pre>
   
 
Works for all levels of tabs. The proof and verification thereof is left to the reader as an exercise.
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
 
 
 
 
"--------------------cut------------------
 
 
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,...
 
 
"-------------------cut-------------------
 
 
 
 
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 :-)
 
 
In case I write something else you may search on the key word TVIM
 
 
Best Wishes TVIM Tamed Vim paradocs@frontiernet.net
 
}}
 
 
== Comments ==
 
Looks like the tab level is basically set to ( col( '.' ) - 1 ) / 4. The 4 is probably the value of &amp;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 ) / &amp;ts
 
if ( ( TabLevel * &amp;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(TM).
 
 
salmanhalim--AT--hotmail.com
 
, August 8, 2002 7:32
 
----
 
well, the 2nd example didnty work for me... so,
 
 
fu ShowTab()
 
let TabLevel=(col('.')-1)
 
if TabLevel == 0
 
let TabLevel='*'
 
endif
 
return TabLevel
 
endf
 
 
   
sputnik
 
, May 20, 2003 14:14
 
 
----
 
----
 
The 2nd example didn't work for me, so
and finaly i found THE solution......
 
   
  +
<pre>
fu ShowTab()
 
 
fu ShowTab()
let TabLevel = (indent('.') / &amp;ts )
 
if TabLevel == 0
+
let TabLevel = (indent('.') / &amp;ts )
let TabLevel='*'
+
if TabLevel == 0
 
let TabLevel='*'
endif
 
  +
endif
return TabLevel
 
 
return TabLevel
 
endf
 
endf
  +
</pre>
   
sputnik
 
, May 20, 2003 14:26
 
 
----
 
----
 
[[VimTip477]]
 
[[VimTip477]]
   
'''Anonymous'''
 
, May 22, 2003 14:53
 
 
----
 
----
<!-- parsed by vimtips.py in 0.559091 seconds-->
 

Revision as of 12:19, 2 November 2007

Tip 303 Printable Monobook Previous Next

created August 8, 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

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

VimTip477