37 lines
646 B
Markdown
37 lines
646 B
Markdown
---
|
|
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<CR>
|
|
```
|
|
|
|
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<CR>
|
|
```
|
|
|
|
results in:
|
|
|
|
```python
|
|
def main():
|
|
baz = do_something()
|
|
bar = do_something_else(baz)
|
|
return bar
|
|
```
|