|
Hi, Is that possible? It solves the tab/space indentation debate, but how is this done in Vim? For example, the code: int main() { <tab>if (1) <tab><tab>int a = test( <tab><tab>.............param1, <tab><tab>.............param2, <tab><tab>............); } would look perfectly fine no matter what tabwidth is, in whatever editor. How do I enable this? It seems that Vim coerces all indentation whitespace to tabs plus some spaces that aren't long enough for the width of a tab. Does Vim also make this language dependent? (E.g. For python, I would assume it has a different scheme of handling automatic indentation.) Thanks, Oliver --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
On Mon, Dec 22, 2008 at 01:22:17PM -0800, Oliver Zheng wrote:
> > Hi, > > Is that possible? It solves the tab/space indentation debate, but how > is this done in Vim? For example, the code: > > int main() { > <tab>if (1) > <tab><tab>int a = test( > <tab><tab>.............param1, > <tab><tab>.............param2, > <tab><tab>............); > } > > would look perfectly fine no matter what tabwidth is, in whatever > editor. How do I enable this? 1. http://www.vim.org/scripts/script.php?script_id=231 -- v4sw5RUYhw2ln3pr5ck0ma2u7Lw3+2Xm0l6/7Gi2e2t3b6AKMen5+7a16s0Sr1p-8.12/-6.56g6OR |
|
On Mon, Dec 22, 2008 at 1:57 PM, Erik Hahn <[hidden email]> wrote: > > Check out this [1] script. > > 1. http://www.vim.org/scripts/script.php?script_id=231 I did. However, it looks like this only "automatically converts" tabs to spaces during the middle of a line. For the example I gave: int main() { <tab>if (1) <tab><tab>int a = test( <tab><tab>.............param1, // [1] <tab><tab>.............param2, <tab><tab>............); } the script does not treat the param line [1] any differently than any other line. It's not really context aware of the programming language. Even if I *manually* space my way to param1 after the initial 2 tabs, Vim will convert my spaces to tabs when I >> or <<. Is there no way to let Vim recognize that spaces are a part of the contents and not indent? Of course, it would be much better if Vim could automatically insert spaces to the appropriate column when I break a statement into multiple lines. Cheers, Oliver --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
On Dec 22, 4:14 pm, "Oliver Zheng" <[hidden email]> wrote: > On Mon, Dec 22, 2008 at 1:57 PM, Erik Hahn <[hidden email]> wrote: > > > Check out this [1] script. > > > 1.http://www.vim.org/scripts/script.php?script_id=231 > > I did. However, it looks like this only "automatically converts" tabs > to spaces during the middle of a line. For the example I gave: > > int main() { > <tab>if (1) > <tab><tab>int a = test( > <tab><tab>.............param1, // [1] > <tab><tab>.............param2, > <tab><tab>............); > > } > > the script does not treat the param line [1] any differently than any > other line. It's not really context aware of the programming language. > > Even if I *manually* space my way to param1 after the initial 2 tabs, > Vim will convert my spaces to tabs when I >> or <<. Is there no way to > let Vim recognize that spaces are a part of the contents and not > indent? Of course, it would be much better if Vim could automatically > insert spaces to the appropriate column when I break a statement into > multiple lines. Make sure 'ts' is set the same as 'sw'. I agree that using tabs always for leading indent and spaces for subsequent alignment makes far more sense than mixing tabs and spaces at the beginning of a line. Fortunately, mixing of tabs and spaces happens only if your tabstop setting is not the same as your shiftwidth: e.g., ts=8, sw=4. I typically set both 'ts' and 'sw' to 4 since I prefer indents to appear as 4 spaces. To those who say "but a tab is supposed to be 8 spaces", I say "a tab isn't any amount of spaces - it is simply an indent level". If you use tabs only for leading indent, an indent level can be whatever you want it to be when you're viewing the file. Almost as importantly, it can be whatever someone else wants it to be when he's viewing the same file... > > Cheers, > Oliver --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Oliver Zheng-2
On 2008-12-22, Oliver Zheng wrote: > Even if I *manually* space my way to param1 after the initial 2 tabs, > Vim will convert my spaces to tabs when I >> or <<. Is there no way to > let Vim recognize that spaces are a part of the contents and not > indent? Of course, it would be much better if Vim could automatically > insert spaces to the appropriate column when I break a statement into > multiple lines. There is no way that I know of. The problem is the interface between the function that determines how much a particular line should be indented (based on the language, rules for that language, etc.) and the code that actually performs the indentation as you type or when you execute <<, >>, = and the like. That function returns one number: the number of spaces by which the line should be indented. There is no mechanism to split this into so-many tabs followed by so-many spaces. The 'preserveindent' and 'copyindent' options try to preserve the pattern of spaces and tabs used to indent a line, but I don't think they will do what you want. I think your best bet is to write a formatting function that will repartition the indenting whitespace code according to your rules after you have typed it. Regards, Gary --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Stahlman Family
Brett Stahlman 写道: > If you use tabs only for leading indent, an indent level can > be whatever you want it to be when you're viewing the file. Almost as > importantly, it can be whatever someone else wants it to be when he's > viewing the same file... No, this is a false illusion, you cannot expect a non-constant indent level anyway, consider the following code. suppose we have 4 space as indent level: { foobar1(); // comment1 if (fb2()) { // comment2 fb3(); // comment3 switch (x) { // comment4 case 1: fb4(); // comment5 break; default: // comment6 break; } } } now we change the indent level to 3: { foobar1(); // comment1 if (fb2()) { // comment2 fb3(); // comment3 switch (x) { // comment4 case 1: fb4(); // comment5 break; default: // comment6 break; } } } Got the idea? If anyone wants to change the indent level, the code is ruined anyway. Simply use only space for indent solves all problem above, personally I do recommend not to use tab size other than 8 at all. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Stahlman Family
Brett Stahlman 写道: > If you use tabs only for leading indent, an indent level can > be whatever you want it to be when you're viewing the file. Almost as > importantly, it can be whatever someone else wants it to be when he's > viewing the same file... > >> Cheers, >> Oliver (Sorry I had just learned how to set plain-text message in thunderbird, then send this message again.) No, this is a false illusion, you cannot expect a non-constant indent level anyway, consider the following code. suppose we have 4 space as indent level: > { > foobar1(); // comment1 > if (fb2()) { // comment2 > fb3(); // comment3 > switch (x) { // comment4 > case 1: > fb4(); // comment5 > break; > default: // comment6 > break; > } > } > } now we change the indent level to 3: > > { > foobar1(); // comment1 > if (fb2()) { // comment2 > fb3(); // comment3 > switch (x) { // comment4 > case 1: > fb4(); // comment5 > break; > default: // comment6 > break; > } > } > } Got the idea? If anyone wants to change the indent level, the code is ruined anyway. Simply use only space for indent solves all problem above, personally I do recommend not to use tab size other than 8 at all. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
On Mon, Dec 22, 2008 at 6:21 PM, pansz <[hidden email]> wrote: > Simply use only space for indent solves all problem above, personally I > do recommend not to use tab size other than 8 at all. That is very unfortunate that Vim does not support such an uncompromising way of solving the issue. (I know Emacs does =P) Is there plans for this feature? How do users submit feature requests anyway? Oliver --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
Oliver Zheng 写道: > On Mon, Dec 22, 2008 at 6:21 PM, pansz <[hidden email]> wrote: >> Simply use only space for indent solves all problem above, personally I >> do recommend not to use tab size other than 8 at all. > > That is very unfortunate that Vim does not support such an > uncompromising way of solving the issue. (I know Emacs does =P) > > Is there plans for this feature? How do users submit feature requests anyway? > > Oliver > Strange to hear that, that is the way I am using now, and I don't see any problems using only space for indent in Vim. What do you really want? -- Pan, Shi Zhu --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
On Mon, Dec 22, 2008 at 7:01 PM, pansz <[hidden email]> wrote: > Strange to hear that, that is the way I am using now, and I don't see > any problems using only space for indent in Vim. Different people have different preferences regarding tabs vs spaces, and mine are to use tabs for indentation since that what tabs are for. Spaces are used for indentation due to the limitation of editors (something I thought Vim of all editors could do) to interpret indentation vs alignment. Why tabs: http://www.movementarian.org/docs/whytabs/ http://www.derkarl.org/why_to_tabs.html > What do you really want? As my original email in the thread describes, I want tabs for indentation and spaces for alignment. Any whitespace that appears after non-whitespace should be spaces. The Vim script Smart Tabs handles this correctly. The problem is when there are *multi-line* statements, which as Gary mentioned Vim does not handle properly. When a statement is split over multiple lines, alignment should not be solved using indentation. E.g.: foo (int a, .....int b, .....int c); should not be foo (int a, <tab>int b, <tab>int c); I thought this would have been something Vim users would have complained about. Emacs has a fix for it (with a few line of configuration scripting), but it sounds like Vim's plugins cannot extend into the editor for language-specific support. Is this correct that this behavior cannot be reproduced in Vim with plugins? Regards, Oliver --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
Oliver Zheng 写道: > I thought this would have been something Vim users would have > complained about. Emacs has a fix for it (with a few line of > configuration scripting), but it sounds like Vim's plugins cannot > extend into the editor for language-specific support. Is this correct > that this behavior cannot be reproduced in Vim with plugins? > > Regards, > Oliver > Vim indent behavior for any specific language is scriptable of course, only c-style-indent is built-in since it is widely used. You can just disable the built-in c-style-indent and make your own indent script in ~/.vim/indent/c.vim So, I've just proved that vim is *capable* of doing what you want with some script work. The reason that you cannot do it now may have two reasons: 1. there is one script in vim.sf.net, but you cannot find it. 2. or nobody has written a script yet. Anyway, you can visit the vim homepage and registered as a vim user to vote or request new features. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Oliver Zheng-2
On 22/12/08 22:22, Oliver Zheng wrote: > Hi, > > Is that possible? It solves the tab/space indentation debate, but how > is this done in Vim? For example, the code: > > int main() { > <tab>if (1) > <tab><tab>int a = test( > <tab><tab>.............param1, > <tab><tab>.............param2, > <tab><tab>............); > } > > would look perfectly fine no matter what tabwidth is, in whatever > editor. How do I enable this? It seems that Vim coerces all > indentation whitespace to tabs plus some spaces that aren't long > enough for the width of a tab. Does Vim also make this language > dependent? (E.g. For python, I would assume it has a different scheme > of handling automatic indentation.) > > Thanks, > Oliver See :help 'copyindent' :help 'preserveindent' :help 'expandtab' For Python, Vim forces hard tabs to 8 columns, because that's what the Python standards say they are. You can still have "soft tabs" of a different width, of course, or use 'expandtabs' to convert tabs to spaces as you type them. Language-dependent settings of this kind are usually set by a filetype-plugin. See :help ftplugins :help filetype-plugins Best regards, Tony. -- What does it mean if there is no fortune for you? --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Oliver Zheng-2
On Mon, Dec 22, 2008 at 4:22 PM, Oliver Zheng wrote: > > Is that possible? It solves the tab/space indentation debate, but how > is this done in Vim? As of right now, it isn't possible without hacking vim's C code to change how cindent() and 'indentexpr' work. 'preserveindent' and 'copyindent' are steps in the right direction, but nowhere close to a working solution. ~Matt --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Erik Hahn
I use the following settings in my .vimrc: set softtabstop=4 set shiftwidth=4 set tabstop=4 set expandtab On Mon, Dec 22, 2008 at 1:57 PM, Erik Hahn <[hidden email]> wrote: > On Mon, Dec 22, 2008 at 01:22:17PM -0800, Oliver Zheng wrote: >> >> Hi, >> >> Is that possible? It solves the tab/space indentation debate, but how >> is this done in Vim? For example, the code: >> >> int main() { >> <tab>if (1) >> <tab><tab>int a = test( >> <tab><tab>.............param1, >> <tab><tab>.............param2, >> <tab><tab>............); >> } >> >> would look perfectly fine no matter what tabwidth is, in whatever >> editor. How do I enable this? > > Check out this [1] script. > > 1. http://www.vim.org/scripts/script.php?script_id=231 > > -- > v4sw5RUYhw2ln3pr5ck0ma2u7Lw3+2Xm0l6/7Gi2e2t3b6AKMen5+7a16s0Sr1p-8.12/-6.56g6OR > --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by panshizhu
On Dec 22, 7:41 pm, pansz <[hidden email]> wrote: > Brett Stahlman 写道: > > > If you use tabs only for leading indent, an indent level can > > be whatever you want it to be when you're viewing the file. Almost as > > importantly, it can be whatever someone else wants it to be when he's > > viewing the same file... > > No, this is a false illusion, you cannot expect a non-constant indent > level anyway, consider the following code. > > suppose we have 4 space as indent level: > { > foobar1(); // comment1 > if (fb2()) { // comment2 > fb3(); // comment3 > switch (x) { // comment4 > case 1: > fb4(); // comment5 > break; > default: // comment6 > break; > > } > } > } > > now we change the indent level to 3: > > { > foobar1(); // comment1 > if (fb2()) { // comment2 > fb3(); // comment3 > switch (x) { // comment4 > case 1: > fb4(); // comment5 > break; > default: // comment6 > break; > > } > } > } > > Got the idea? If anyone wants to change the indent level, the code is > ruined anyway. indent***". The distinction is very important. To align end of line comments within a block, you use spaces. Not only does using space for leading indent waste an excessive amount of space in source files with relatively short lines and high levels of indent, it also forces everyone viewing the file to use the indent level preferred by the original author. Brett Stahlman > > Simply use only space for indent solves all problem above, personally I > do recommend not to use tab size other than 8 at all. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Oliver Zheng-2
. . > > What do you really want? > > As my original email in the thread describes, I want tabs for > indentation and spaces for alignment. Any whitespace that appears > after non-whitespace should be spaces. The Vim script Smart Tabs > handles this correctly. As I mentioned in an earlier post, simply set ts and sw to the same value, and Vim will not mix spaces and tabs for leading indents. . . --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by panshizhu
On 2008-12-23, pansz wrote: > Oliver Zheng ??????: > > I thought this would have been something Vim users would have > > complained about. Emacs has a fix for it (with a few line of > > configuration scripting), but it sounds like Vim's plugins cannot > > extend into the editor for language-specific support. Is this correct > > that this behavior cannot be reproduced in Vim with plugins? > > > > Regards, > > Oliver > > > > Vim indent behavior for any specific language is scriptable of course, > only c-style-indent is built-in since it is widely used. You can just > disable the built-in c-style-indent and make your own indent script in > ~/.vim/indent/c.vim > > So, I've just proved that vim is *capable* of doing what you want with > some script work. The reason that you cannot do it now may have two reasons: > 1. there is one script in vim.sf.net, but you cannot find it. > 2. or nobody has written a script yet. I may be missing something, but for the reasons I gave before, I really don't see how a script can be used to get the requested behavior unless the script intercepts every keystroke and re-implements vim's internal formatting and indenting code. How are you thinking this could be done? Regards, Gary --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Stahlman Family
On Dec 23, 8:52 am, Brett Stahlman <[hidden email]> wrote: > > As I mentioned in an earlier post, simply set ts and sw to the same > value, and Vim will not mix spaces and tabs for leading indents. > True, but this is not what is being asked. The desired behavior is for Vim to automatically do something like this: {tab}{tab}{tab}if (a == b && {tab}{tab}{tab}....c == d && {tab}{tab}{tab}....e == f) {tab}{tab}{tab}{ {tab}{tab}{tab}{tab}foo(); {tab}{tab}{tab}} Note that actual TAB characters are used for indent, but spaces are used for alignment. As far as I know, the format on the 2nd and 3rd lines is not possible for Vim to do automatically. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
On Wed, Dec 24, 2008 at 00:32, fritzophrenic <[hidden email]> wrote: > As far as I know, the format on the 2nd and 3rd lines is not possible > for Vim to do automatically. :set copyident will preserve it once you do it manually. And I love how many other people are doing this. I always code with :set list and I often feel very alone.. ;) Richard --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
|
In reply to this post by Ben Fritz
fritzophrenic wrote: > > On Dec 23, 8:52 am, Brett Stahlman <[hidden email]> wrote: > >> As I mentioned in an earlier post, simply set ts and sw to the same >> value, and Vim will not mix spaces and tabs for leading indents. >> >> > > True, but this is not what is being asked. > > The desired behavior is for Vim to automatically do something like > this: > > {tab}{tab}{tab}if (a == b && > {tab}{tab}{tab}....c == d && > {tab}{tab}{tab}....e == f) > {tab}{tab}{tab}{ > {tab}{tab}{tab}{tab}foo(); > {tab}{tab}{tab}} > > Note that actual TAB characters are used for indent, but spaces are > used for alignment. > I'm curious how the distinction between 'indent' and 'alignment' has been made. I see them as exactly the same thing; as English words, I mean. It's obvious from the diagram above what is meant, but the purpose of the 'indent' is to 'align'... ...or am I missing something? How is the difference between the two instances above best described? Perhaps 'block indentation' as apposed to 'line-wrapping indentation'? I wonder if it's getting to the point where vim would have to be a compiler in order to make these distinctions accurately. Perhaps that's something that is easier for something like Emacs to do. I would like to be able to make use of a real compiler in order to do this kind of code parsing. I'm told that the gcc people, for example, aren't really interested in doing this. Max. --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~--- |
| Powered by Nabble | Edit this page |
