About: Insert line numbers   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

The :s command can be used to insert line numbers before each line: :%s/^/\=printf('%-4d', line('.')) The pattern ^ matches the start of every line, and the replacement \= is the result of evaluating the following expression. That expression uses printf() to format the number of the current line: %-4d is a left-aligned decimal number, padded if necessary by adding spaces to a 4-column width (%4d is right-aligned, and %04d inserts leading zeroes). :'<,'>s/^/\=printf("%d. ", line(".") - line("'<") + 1) :'<,'>s/^\S/\=printf("%d. ", line(".") - line("'<") + 1) :let i = 1

AttributesValues
rdfs:label
  • Insert line numbers
rdfs:comment
  • The :s command can be used to insert line numbers before each line: :%s/^/\=printf('%-4d', line('.')) The pattern ^ matches the start of every line, and the replacement \= is the result of evaluating the following expression. That expression uses printf() to format the number of the current line: %-4d is a left-aligned decimal number, padded if necessary by adding spaces to a 4-column width (%4d is right-aligned, and %04d inserts leading zeroes). :'<,'>s/^/\=printf("%d. ", line(".") - line("'<") + 1) :'<,'>s/^\S/\=printf("%d. ", line(".") - line("'<") + 1) :let i = 1
Version
  • 7(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 27(xsd:integer)
Complexity
  • intermediate
Created
  • 2001(xsd:integer)
ID
  • 28(xsd:integer)
NEXT
  • 29(xsd:integer)
Rating
  • 159(xsd:integer)
abstract
  • The :s command can be used to insert line numbers before each line: :%s/^/\=printf('%-4d', line('.')) The pattern ^ matches the start of every line, and the replacement \= is the result of evaluating the following expression. That expression uses printf() to format the number of the current line: %-4d is a left-aligned decimal number, padded if necessary by adding spaces to a 4-column width (%4d is right-aligned, and %04d inserts leading zeroes). To number a section, specify which lines should be numbered with a range. For example, press V to select the first line, then press j to extend the selection down until all required lines are selected. Then type the following command (do not type '<,'> as that is inserted by Vim): :'<,'>s/^/\=printf("%d. ", line(".") - line("'<") + 1) The above example has a format string of "%d. " 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): :'<,'>s/^\S/\=printf("%d. ", line(".") - line("'<") + 1) 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: :'<,'>g/^\S/s/^/\=printf("%d. ", Inc()) The above requires the Inc() function from here. In addition, you need to set the value for the first line number before selecting any lines. To do that enter: :let i = 1
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software