bla.callSomeMethod( eins, zwei ); // jau
bla.callAnotherMethod( eins, zwei, drei ); // jaujau
The reason for this is that while it all looks fine given my
personal tabstop setting of 4, and possibly others for this
particular piece of text; but in general the end-of-line
comments will not look justified for each and every setting
of tabstop. Spaces are more robust here.
Is there a setting in Vim to expand tabs depending on whether
I'm at the beginning of a line (indenting), or in the middle
of the line (formatting)?
--
Michael Ludwig
The first has general principles; the second is on your point:
http://vim.wikia.com/wiki/Indenting_source_code
http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_spaces
John
Thanks! I had read the first but not the second. Excellent
documentation!
Smart Tabs (ctab.vim) 1.4.1 does exactly what I want.
The newer version 2.1, however, seems to be less robust. I got
the following error messages right after hitting "o" to insert
lines:
=<SNR>12_CheckAlign(line('.'))."\<END>"
Error detected while processing function <SNR>12_CheckAlign:
line 25:
E121: Undefined variable: inda
Press ENTER or type command to continue
Error detected while processing function <SNR>12_CheckAlign:
line 25:
E15: Invalid expression: inda / 50
Press ENTER or type command to continue
Error detected while processing function <SNR>12_CheckAlign:
line 26:
E121: Undefined variable: inda
Press ENTER or type command to continue
Error detected while processing function <SNR>12_CheckAlign:
line 26:
E15: Invalid expression: inda % 50
Press ENTER or type command to continue
Error detected while processing function <SNR>12_CheckAlign:
line 28:
E121: Undefined variable: indatabs
Press ENTER or type command to continue
Error detected while processing function <SNR>12_CheckAlign:
line 28:
E15: Invalid expression: indatabs*&tabstop + indaspace == indb
Press ENTER or type command to continue
Posting this only for informative purposes - so far, I'm happy
with version 1.4.1.
Thanks again!
--
Michael Ludwig
Here is a thread from Oct 2007:
Subject: expandtab after non-blanks only
http://groups.google.com/group/vim_use/browse_thread/thread/eb86a0cb32690a14
My old suggestion temporarily sets expandtab before the Tab is inserted
and resets it afterwards (btw: maybe it should use :setlocal instead of
:set).
The alternatives (mainly: scripts) manually calculate the amount of
spaces to be inserted. The following code does it the same way:
func! TabOrSpaces()
if !&expandtab && virtcol(".")-1 > indent(".")
" actual tabstop
let ats = &sts>0 ? &sts : &ts
return repeat(" ", ats - (virtcol(".")-1) % ats)
else
return "\<Tab>"
endif
endfunc
ino <silent> <Tab> <C-R>=TabOrSpaces()<CR>
... and is short enough to be put in the vimrc.
In the old thread I linked to
Converting tabs to spaces http://vim.wikia.com/wiki/VimTip12
which in turn mentions
Clever Tabs : Using tabs for indent only on start of line
http://www.vim.org/scripts/script.php?script_id=2308
(I just wanted to mention it).
What's left -- some backdraws of the above code:
- <Tab> no longer expands abbreviations
- <BS> (after non-blanks) only deletes one Space at a time
- probably conflicts with the SuperTab plugin (although I don't use it)
--
Andy