[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to change indent in vim



In <[🔎] 4A31939D.4040601@symantec.com>, Bob McGowan wrote:
>Boyd Stephen Smith Jr. wrote:
>> In <[🔎] 20090610160715.GA22215@tomgeorge.info>, Thomas H. George wrote:
>>> I want indent set to 3, the default setting 8 uses up too much space.
>>>
>>> There is a plethora of information in /usr/share/vim/vim71 but it all
>>> seems to relate to turning indent on for various situations.  Somewhere
>>> there must be a simple line indent=8 that I can change but I haven't
>>> found it.
>> Your ~/.vimrc, ~/.virc, or ~/.exrc (the first one that exists) can be
>> used to run any command each time vim is started.
>>
>> Ben gives possibly correct commands.  Use ":help 'tabstop'" and ":help
>> 'shiftwidth'" from within vim to determine is those are the settings you
>> want.
>The settings Ben gives are the ones I use.

>One caveat is that the tab character is still used for the indentation,
>which means when you or someone else looks at the text using a different
>tabstop setting, things may indent in odd ways.

This is an intentional feature of the tab character: allowing the viewer of 
the document to choose tab stops that provide them the correct amount of 
horizontal white space to ease their reading.

With proper discipline, it is possible to use tab character for indentation, 
space characters for alignment and have everything "line up" independent of 
the viewers tab settings.

To aid it using proper indentation procedures, I use the 'list' option of 
vim so that spaces and tabs are visually displayed identically.

>I add "set expandtab" in my Vim rc file, which forces tabs to expand to
>spaces.  This keeps the relative indentation the same no matter what an
>application's tab stop setting is.

It also makes it very difficult for others to read.  I don't need much 
horizontal white space, so I use 2 character tab stops.[1]  However, others 
may not be able to quickly identify what lines start on the same column 
unless they have 4+ character tab stops.

'expandtab' should NEVER be used if you intend to track the file(s) in a 
VCS.  It will balloon your patches with useless whitespace "fixes" that 
actually break the code layout for anyone that doesn't use your chosen tab 
stop size.

Being disciplined with tabbing (indentation), spacing (alignment), and line-
breaking/word-wrapping can allow your code/text to be beautiful independent 
of the viewers tab stop settings or terminal width.
-- 
Boyd Stephen Smith Jr.           	 ,= ,-_-. =.
bss@iguanasuicide.net            	((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy 	 `-'(. .)`-'
http://iguanasuicide.net/        	     \_/

[1] Actually, I use the default list characters, so a tab shows up as "^I" 
so matter what I was 'ts' set to.  In deference to users expecting large 
tabs on small screens, I try to make my code fit on 80 character lines even 
if your tab stops are every 8 characters.  To do so, I set 'ts' to 8 so that 
my status bar ruler gives a correct "maximum column".  I also set 'sw' to 8 
so that pressing the <TAB> key results in the insertion of one tab 
character.

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: