Adding Text at the Beginning of Multiple Lines
- Go the line you want to select the text.
- Press V (upppercase
V) to state Visual line mode. - Select multiple line using arrow or j/k keys.
- Press
:after selecting the desired lines. This will open the line range command:'<,'>. - Type
s/^/<text>/, where “<text>” is the text you want to add at the beginning of each fo the selected lines.(^)indicates the will be added to the beginning of the line.
Example 1: Add text to the selected lines
Adding comments // to each line in verilog.
:'<','>s/^/\/\/ /
Example 2: Add text to the entire files
:%s/^/\/\/ /
- Press
Escto navigate to normal mode. %applies the command to all the lines in the file.
Removing Text at the Beginning of Multiple Line
- Press
Escto navigate to normal mode. - Press V (upppercase
V) to state Visual line mode. - Select multiple line using arrow or j/k keys.
- Press
:after selecting the desired lines. This will open the line range command:'<,'>. - Type
s/^..//, where(^)indicates the start of the line and(..)will select excatly two characters and(//)will delete them.
Example 1: Delete the first two characters from the selected lines
Remove the comments // for the selected lines.
:<','>s/^..//
Example 2: Delete the first two character from all the lines in a file
:%s/^..//
- Ensure you in the normal by pressing
Escbefore executing the above command. %applies the command to all the line in the file.
Adding Text to End of Multiple Line
- Go the line you want to select the text.
- Press V (upppercase
V) to state Visual line mode. - Select multiple line using arrow or j/k keys.
- Press
:after selecting the desired lines. This will open the line range command:'<,'>. - Type
s/$/value/, where “value” is the text you want to add at the beginning of each fo the selected lines.($)indicats the will be added to the end of the line.
Example
Adding comments ; to each line in verilog.
:'<','>s/$/; /
Removing Text at the End of Multiple Line
- Press
Escto navigate to normal mode. - Press V (upppercase
V) to state Visual line mode. - Select multiple line using arrow or j/k keys.
- Press
:after selecting the desired lines. This will open the line range command:'<,'>. - Type
s/..$//, where($)indicates the end of the line and(..)will select excatly two characters and(//)will delete them.
Example 1: Delete the first two characters from the selected lines
Remove the comments // for the selected lines.
:<','>s/..$//
Example 2: Delete the first two character from all the lines in a file
:%s/..$//
- Ensure you in the normal by pressing
Escbefore executing the above command. %applies the command to all the line in the file.