Created
July 19, 2012 20:42
-
-
Save shreeshga/3146677 to your computer and use it in GitHub Desktop.
Revisions
-
shreeshga renamed this gist
Jul 19, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
shreeshga revised this gist
Jul 19, 2012 . 2 changed files with 27 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ The ex command <code>g</code> is very useful for acting on lines that match a pattern. You can use it with the <code>d</code> command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern. For example, to delete all lines containing "profile" (the first command is optional; it shows the lines that the second command will delete): <pre> :g/profile :g/profile/d </pre> More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace: <pre> :g/^\s*$/d </pre> To delete all lines that do ''not'' contain a pattern, use <code>g!</code>, like this command to delete all lines that are not comment lines in a Vim script: <pre> :g!/^\s*"/d </pre> Note that <code>g!</code> is equivalent to <code>v</code>, so you could also do the above with: <pre> :v/^\s*"/d </pre> The next example shows use of <code>\|</code> ("or") to delete all lines ''except'' those that contain "<code>error</code>" or "<code>warn</code>" or "<code>fail</code>" ({{help|pattern}}): <pre> :v/error\|warn\|fail/d </pre> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +0,0 @@ -
shreeshga created this gist
Jul 19, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ The ex command g is very useful for acting on lines that match a pattern. You can use it with the d command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern. For example, to delete all lines containing "profile" (the first command is optional; it shows the lines that the second command will delete): :g/profile :g/profile/d More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace: :g/^\s*$/d To delete all lines that do not contain a pattern, use g!, like this command to delete all lines that are not comment lines in a Vim script: :g!/^\s*"/d Note that g! is equivalent to v, so you could also do the above with: :v/^\s*"/d The next example shows use of \| ("or") to delete all lines except those that contain "error" or "warn" or "fail" (:help pattern): :v/error\|warn\|fail/d