When expressions span multiple lines, you may want to line up the beginning of those lines with the beginning of the expression in the first line: If your non-Vim-using collaborators remain unconvinced, pass them these pointers, whichever is appropriate: smart tabs for Emacs, and IntelliJ IDEA has a built-in "smart tabs" option. The Smart Tabs plugin is just an added convenience. You do not need a "smart" editor to display or edit smartly tabbed files – that's the whole point. Different people can then use whatever shiftwidth and tabstop they want (provided these two values are equal) – the end result is the same, and is displayed correctly everywhere. When you press Tab in insert mode, a tab is inserted when indenting, and/or the correct number of spaces when aligning text (see continuation lines). The plugin ensures that tabs are only used for indentation, while spaces are used everywhere else. To use tabs in a more "semantic" way – i.e., the number of tabs equals the indentation level – install the Smart Tabs plugin or the newer vim-stabs plugin (which stands for smarter-tabs). The settings above use hard tabs as far as possible. If you want the commands to affect only the current buffer, replace set with setlocal (abbreviated as setl). However, note that in the case of continuation lines, some spaces may be added when the indentation is not a multiple of tabstop. The previous line is an abbreviated equivalent of these commands: If you want to use only tabs for indentation (not spaces), enter the following command (replace 4 with your preferred column width for each indent level): This illustrates that using tabs for indentation and spaces for alignment keeps the alignment unchanged when the tabstop is altered (for lines with the same indent). |-float average // (some people like it this way) Entering :set tabstop=4 makes the code appear as: In the above, " |-" represents a tab using the default :set tabstop=8. |-float average // (some people like it that way) |-int count // variable names are aligned Here is an example using tabs for indentation and spaces for alignment: If the tabstop size is changed, it is necessary to use spaces for alignment because that will maintain the alignment with a different tabstop, provided the lines with aligned text use the same number of tabs for indenting. However, different people like different indent sizes, so a common procedure is to use tabs for indentation so the indent size can easily be adjusted to suit whoever is working on the code. Using spaces for indentation means that the code will look the same on all systems, even if the tabstop option is changed. Apart from these considerations, whether you use tabs or spaces is generally a personal choice, or is determined by the coding style of the project. In large projects, using as many tabs as possible can significantly reduce the size of the source code, and in some rare cases (for example, make files), tabs must be used for indentation. Use tabs for indentation and spaces for alignment (" smart tabs").Use a mixture of tabs and spaces for indentation and alignment.Use tabs for indentation and alignment.Use spaces for indentation and alignment.Some procedures commonly used to write programs are: To align text (for example, so comments start in the same column).To indent blocks of code (for example, to show the code that is in a loop).Programs use whitespace (spaces or tabs) for two purposes:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |