Useful Sed strings to use in Vim

To delete lines 4-12 in Vim:

:4,12 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):

:%s/([^ ]+ ) +/\1==/g
:%s/ ==/==/

To remove == and everything after from a pip list so that pip will install the newest version:

:%s/==.*//

To reformat a paragraph in vim:
Use <CTRL-J> to join all lines in the paragraph
:gq

To remove all commented and blank lines from a file:

:g/\v^(#|$)/d

About vicki

Welcome to the Sovereign Republic of Vickistan. I am the President here. Lucky me! No taxes or laws yet. Lucky you!
This entry was posted in Linux. Bookmark the permalink.