In a text file I need to comment out all lines by adding a ";" as first character of each line. What is a good way to do this? I thought of Vim's visual block mode, but I couldn't find a "select all" option and marking several hundred lines manually also isn't great ;-) Any idea? I have nano, vi and vim at hand, I would prefer one of those for this task.
|
In Vim: |
|||||||||||||
|
|
In Vim you can also just do the global replace on the start of all lines:
|
||||
|
|
For a simple task like this you could use
This preserves a copy of the original file as "*.old" and adds a ";" at the beginning of every line. In the event that your |
||||
|
|
I would add to jw013's answer by changing the replace to
That can be rerun as many times as you like and will not add semicolons endlessly to the beginning of lines already having it in the beginning. It can also be used with sed or perl with the colon and percentage sign removed. It replaces in all lines (%) every line that starts with something other than a semicolon to start with a semicolon and then the character that it started with originally (to keep it in the file). Both commands (mine and jw013's) should be done in command mode, which is the default start mode of vi/vim and can be accessed with the key when in Insert or replace modes. |
|||
|
|
