See great page on VIM RegEx: http://www.softpanorama.org/Editors/Vimorama/vim_regular_expressions.shtml
(copying in case it gets moved)
Examples:Simple Find and Replace:Search for text cool and replace it with groovy. Do this as many times as necessary for each line.
:%s/cool/groovy/g Add a carriage return before the word text. Only do this once per line.
:%s/text/[Ctrl+v][Return]text/ find any number matching a patternSearch for all dates (ie: 5-20-2000), and delete:
:%s/\d\+-\d\+-\d\+//g find and replace with regex "
:%s/\(\w\) \(\d\)/\1\t\2/
Find some non-printed stuffDelete all empty lines:
:g/^$/d (same as above with spaces)
:g/^\S$/d Find, copy, and pastefind some text and store it in register $1, then paste it later
:%s/interface \(\S\+\)\n / \1, /
Delete lines containing matchany line with the word match should be deleted :g/match/d Scriptsif you create a text file (in this example called " xl.vim ", and in this example putting it in your home directory), and in that text file put a bunch of search and replace statements that you want to do (like such): :%s/^!#.*\n//g :%s/\t//g :%s/<t>/ /g :%s/<p>/\r/g then in your current file that you want to run this script against, call the script by the following command: :source ~/xl.vim Keyboard Cheat Sheet:Quick list of what each key does:Configuration Settings:VIMRC:Config files and good standards for them.
References:How-Tos:
Links:
|
Home > unix/linux >