tabstop vs. tabwidth

Programming, for all ages and all languages.
Post Reply
lovelyshell
Posts: 16
Joined: Thu May 10, 2018 1:05 pm

tabstop vs. tabwidth

Post by lovelyshell »

When I pressed tab key in insert mode, I found vim forward the cursor to the nearest column aligned on value tabstop . And I guess this is how tabstop got its name.

But why does vim design tab behavior like this, why not simply forward cursor by tabwidth (rather than named tabstop)columns discarding alignment? This seems to be the traditional behavior of tab key.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: tabstop vs. tabwidth

Post by iansjack »

My experience of the TAB key is that, in almost all software, it behaves as you describe - i.e. moves to fixed columns rather than moving by a fixed amount. It's the way that tabs on old-fashioned typewriters worked. (Tab being short for tabulator - i.e. something designed to produce tables.)

This is exactly what you want in, for example, a text editor where you want the starts of lines to be aligned or if you are creating tables where the columns need to be aligned..
lovelyshell
Posts: 16
Joined: Thu May 10, 2018 1:05 pm

Re: tabstop vs. tabwidth

Post by lovelyshell »

iansjack wrote:My experience of the TAB key is that, in almost all software, it behaves as you describe - i.e. moves to fixed columns rather than moving by a fixed amount. It's the way that tabs on old-fashioned typewriters worked. (Tab being short for tabulator - i.e. something designed to produce tables.)

This is exactly what you want in, for example, a text editor where you want the starts of lines to be aligned or if you are creating tables where the columns need to be aligned..
Thanks. I have mistaken its behavior for so many years. :roll:
I just test in emacs and xterm, and all behaves in same way, except in xterm( I used command 'printf"), tab key never fowards cursor to next line.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: tabstop vs. tabwidth

Post by Love4Boobies »

With regards to Vim, there are things you should care about: tabstop, tabwidth and shiftwidth. Look up hard vs soft tabstops to understand the difference. For instance, I have the following line in my .vimrc:

Code: Select all

set shiftwidth=0 tabstop=4
(The zero means that shiftwidth is equal to whatever tabstop is so it's a matter of maintainability.)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply