Editing (section) Insert line numbers 0 We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free. ==Using Vim== The [[Search and replace|:s]] command can be used to insert line numbers before each line: <pre> :%s/^/\=printf('%-4d', line('.')) </pre> The pattern <code>^</code> matches the start of every line, and the replacement <code>\=</code> is the result of evaluating the following expression. That expression uses <code>printf()</code> to format the number of the current line: <code>%-4d</code> is a left-aligned decimal number, padded if necessary by adding spaces to a 4-column width (<code>%4d</code> is right-aligned, and <code>%04d</code> inserts leading zeroes). To number a section, specify which lines should be numbered with a [[Ranges|range]]. For example, press <code>V</code> to select the first line, then press <code>j</code> to extend the selection down until all required lines are selected. Then type the following command (do not type <code>'<,'></code> as that is inserted by Vim): <pre> :'<,'>s/^/\=printf("%d.\t", line(".") - line("'<") + 1) </pre> The above example has a format string of <code>"%d.\t"</code> which inserts a left-aligned number, followed by a period and a tab character. Each line in the selected range is numbered. Use the following if you want to only number non-blank lines (it finds the start of a line followed by a character that is not whitespace): <pre> :'<,'>s/^\S/\=printf("%d.\t", line(".") - line("'<") + 1) </pre> In the above, blank lines are counted, but do not have a number inserted (the inserted numbers would be 1, 2, 3, 5, 6 if line 4 was blank). The following alternative does not number blank lines and does not skip line numbers: <pre> :'<,'>g/^\S/s/^/\=printf("%d.\t", Inc()) </pre> The above requires the <code>Inc()</code> function from [[Making a list of numbers|here]]. In addition, you need to set the value for the first line number before selecting any lines. To do that enter: <pre> :let i = 1 </pre> Loading editor Below are some commonly used wiki markup codes. Simply click on what you want to use and it will appear in the edit box above. Insert: – — … ° ≈ ≠ ≤ ≥ ± − × ÷ ← → · § Sign your username: ~~~~ Wiki markup: {{}} | [] [[]] [[Category:]] #REDIRECT [[]] <s></s> <sup></sup> <sub></sub> <code></code> <blockquote></blockquote> <ref></ref> {{Reflist}} <references/> <includeonly></includeonly> <noinclude></noinclude> {{DEFAULTSORT:}} <nowiki></nowiki> <!-- --> <span class="plainlinks"></span> Symbols: ~ | ¡ ¿ † ‡ ↔ ↑ ↓ • ¶ # ¹ ² ³ ½ ⅓ ⅔ ¼ ¾ ⅛ ⅜ ⅝ ⅞ ∞ ‘ “ ’ ” «» ¤ ₳ ฿ ₵ ¢ ₡ ₢ $ ₫ ₯ € ₠ ₣ ƒ ₴ ₭ ₤ ℳ ₥ ₦ № ₧ ₰ £ ៛ ₨ ₪ ৳ ₮ ₩ ¥ ♠ ♣ ♥ ♦ View this template This field is a spam trap. DO NOT fill it in! Edit summary Preview Mobile Desktop Show changes