From 2146511ab4bc5d83156809d0c202690e26496433 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 14 Mar 2021 14:29:21 -0700 Subject: [PATCH] vim note, range patterns --- 82ded935.md | 37 +++++++++++++++++++++++++++++++++++++ b926d9bd.md | 1 + 2 files changed, 38 insertions(+) create mode 100644 82ded935.md diff --git a/82ded935.md b/82ded935.md new file mode 100644 index 0000000..6e364d4 --- /dev/null +++ b/82ded935.md @@ -0,0 +1,37 @@ +--- +date: 2021-03-14T14:12 +tags: + - vim +--- + +# command mode ranges based on patterns + +In command mode you can specify a range of lines to operate on, based on patterns, +rather than absolute (or relative line numbers). This can be a great way +to isolate changes without looking up the individual line numbers. + +```vim +:/start/,/end/cmd +``` + +On a Python file, this might look like: + +```python +def main(): + foo = do_something() + bar = do_something_else(foo) + return bar +``` + +```vim +:/def main/,/return/s/foo/baz/g +``` + +results in: + +```python +def main(): + baz = do_something() + bar = do_something_else(baz) + return bar +``` diff --git a/b926d9bd.md b/b926d9bd.md index 5d1f5ab..2a2c5c4 100644 --- a/b926d9bd.md +++ b/b926d9bd.md @@ -3,3 +3,4 @@ - [[[56653cb1]]] - [[[fa6a31b4]]] - [[[b364352b]]] +- [[[82ded935]]]