1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Match The Beginning And End Of Words as a vim til.

This commit is contained in:
jbranchaud
2015-10-28 15:33:45 -05:00
parent d18d130608
commit 86b899632b
2 changed files with 23 additions and 0 deletions

View File

@@ -257,6 +257,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
- [Jump To The Next Misspelling](vim/jump-to-the-next-misspelling.md)
- [List All Buffers](vim/list-all-buffers.md)
- [List Of Plugins](vim/list-of-plugins.md)
- [Match The Beginning And End Of Words](vim/match-the-beginning-and-end-of-words.md)
- [Marks Across Vim Sessions](vim/marks-across-vim-sessions.md)
- [Moving To A Specific Line](vim/moving-to-a-specific-line.md)
- [Navigating By Blank Lines](vim/navigating-by-blank-lines.md)

View File

@@ -0,0 +1,22 @@
# Match The Beginning And End Of Words
Often when doing a substitution for an exact word, say `user` to
`admin`, I will include spaces on either end of the regex pattern to avoid
unintentional replacements. For example, I may use something like
```
:%s/ user / admin /
```
in order to avoid a substitution like `username` to `adminname`.
In this case, the spaces can be replaced with zero-width regex characters
that match the beginning and end of a word. These are `\<` and `\>`,
respectively. Utilizing these, the previous substitution can be achieved
with
```
:%s/\<user\>/admin/
```
See `:h /\<` and `:h /\>` for more details.