Sed strings make VIM very powerful. You can use them to do many things. The changes will not be written to the file until you save the file, so you are safe to experiment a bit.
To delete lines 4-12:
:4,12 d
To delete the current line:
:d
To replace the word foo with the word bar starting at the line where the cursor is through the end of the file:
:.,$s/foo/bar/
To remove the spaces in the middle of a pip list output line and replace it with == so it can be used to install (if you have to recreate your pyenv):
1.) remove the header lines:
:1,2 d
2.) replace the spaces with double equals:
:%s/ +/==/g
To remove == and everything after from a pip list so that pip will install the newest version:
:%s/==.*//
To remove all lines that contain the strings error, warn, or fail (remove the /d
to show the lines that the command will delete):
:g/error\|warn\|fail/d
To remove all lines that don’t contain the strings error, warn, or fail (remove the /d
to show the lines that the command will delete):
:g!/error\|warn\|fail/d
v
can replace the g!
if you prefer:
:v/error\|warn\|fail/d
To reformat a paragraph in vim:
1. Use <CTRL-J>
to join all lines in the paragraph
2.
:gq
To remove all commented and blank lines from a file (remove the /d
to show the lines that the command will delete):
:g/\v^(#|$)/d