About: Commenting out a range of lines   Sponge Permalink

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

It's very common to need to comment out a range of lines, let's say in a shell script. One way to do this is to move to the first line and type: I# (insert # as the first non-blank character of the line) Then use a series of: j. (moving down and repeat the previous command/change) However, this is tedious; using j.j.j. ... Another way is to determine the line numbers of the first and last line. You can use the :f ex command to display these; or you can temporarily use :set nu to enable "number mode" and :set nonu to disable when you're done. For example:

AttributesValues
rdfs:label
  • Commenting out a range of lines
rdfs:comment
  • It's very common to need to comment out a range of lines, let's say in a shell script. One way to do this is to move to the first line and type: I# (insert # as the first non-blank character of the line) Then use a series of: j. (moving down and repeat the previous command/change) However, this is tedious; using j.j.j. ... Another way is to determine the line numbers of the first and last line. You can use the :f ex command to display these; or you can temporarily use :set nu to enable "number mode" and :set nonu to disable when you're done. For example:
Version
  • 5(xsd:double)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 979(xsd:integer)
Category
  • Automated Text Insertion
Author
  • JimD
Complexity
  • basic
Created
  • 2005(xsd:integer)
ID
  • 981(xsd:integer)
NEXT
  • 982(xsd:integer)
Rating
  • 28(xsd:integer)
abstract
  • It's very common to need to comment out a range of lines, let's say in a shell script. One way to do this is to move to the first line and type: I# (insert # as the first non-blank character of the line) Then use a series of: j. (moving down and repeat the previous command/change) However, this is tedious; using j.j.j. ... Another way is to determine the line numbers of the first and last line. You can use the :f ex command to display these; or you can temporarily use :set nu to enable "number mode" and :set nonu to disable when you're done. Whatever method you use to find the line numbers they can be used as a range for a substitute command: :xx,yy s/^/# / This is a bit tedious because you have to look up the numbers and re-type them. So we want a method that is less repetitive than j.j.j. and involves less manual fussing with line numbers than the ex range/substitute command. The solution is as old as vi/ex itself though it's often overlooked. Move to the first line and set a mark with: ma (where "a" is any letter you choose) Move to the last line and issue the following ex command: :'a,. s/^/# / This works on the range of lines between the mark (single quote, register letter) and the current line (.) substituting each beginning of line with the string "# " (octothorpe, space). More elaborate sequences of pure old ex commands can also be used to create boxes around C/C++ blocks; but they are really horrid to type every time so they have to be mapped to some key sequence and entails consistently using the same register every time. For example: map gC :'a,. s/^/ */^M:. s/\(.*\)/\1^V^V^M **************\//^M:'a s/\(.*\)/\/**************^V^V^M\1/^M maps the sequence gC to a macro which wraps a block of text, from the current line back to the line marked by the "a" in a C style comment like: /************************ * * .... * .... ************************/ The example is a little crude - it doesn't indent the comment block at all, for example; and it could use some extra blank lines. However, it illustrates the point of what we can do even with plain old vi/ex commands.
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