#VIM #text-editing #protocol
Dealing with text is part of our daily tasks as it is a common medium for communication and building digital artefacts. The many situation we are presented with, either text we wrote ourself or taken from an existing source, and the transformation necessary for it to get into the right shape keep challenging our knowledge of editing features and most optimized ways to achieve a certain effect in a repeatable manner. In a sense, text editing is still an open problem otherwise we wouldn't be text editing but circuit designing text transformations.
Along the lines of [[Good Solutions to Common Problems should be Protocolized|protocolizing good solutions]], I thought that I should list all the common use cases and the different approaches to deal with them using VIM's base features.
# Substituting Text within a Selection
1. First, enter Visual mode by pressing `v` (for character-wise selection) or `V` (for line-wise selection) 2. Select the text you want to work with using movement keys 3. Press `:` while the text is selected 4. You'll see `:'<,'>` appear automatically in the command line 5. Then type your substitution command, for example: `s/old/new/g` So the full command would look like:
```
:'<,'>s/old/new/g
```
You can also use other flags like:
- `c` for confirmation on each substitution
- `i` for case-insensitive matching
- `I` for case-sensitive matching
# Bookmark on-the-go to Quickly Move and Back
1. While at the position you want to bookmark, press:
```
m<letter>
```
2. To return to a local mark, press:
```
'<letter>
```
For ease of use, let `<letter>` be `q`.
%%
# Select the Content between Enclosures
# Select All Occurrences of a Given Word
%%