From 86b899632ba294e03f9311f8beb32ba2595c520c Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Wed, 28 Oct 2015 15:33:45 -0500 Subject: [PATCH] Add Match The Beginning And End Of Words as a vim til. --- README.md | 1 + vim/match-the-beginning-and-end-of-words.md | 22 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 vim/match-the-beginning-and-end-of-words.md diff --git a/README.md b/README.md index 069d38a..ab210e1 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/vim/match-the-beginning-and-end-of-words.md b/vim/match-the-beginning-and-end-of-words.md new file mode 100644 index 0000000..7e0e70d --- /dev/null +++ b/vim/match-the-beginning-and-end-of-words.md @@ -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/\/admin/ +``` + +See `:h /\<` and `:h /\>` for more details.