Am 28.02.2010 15:13, schrieb Michael Ludwig:
For indenting at the beginning of the line, I want tabs. But in mid-line, I want them to be expanded to spaces. Can this be achieved in Vim?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)?
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 -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
