From 059209861a1fe596b4b3715f6ee175ed4b444c3f Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 12 Jun 2015 16:05:05 -0500 Subject: [PATCH] Add Swap Occurrences Of Two Words as a vim til. --- README.md | 1 + vim/swap-occurrences-of-two-words.md | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 vim/swap-occurrences-of-two-words.md diff --git a/README.md b/README.md index 9fa0332..7372e8a 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Scrolling Relative to the Window](vim/scrolling-relative-to-the-window.md) - [Set Your Color Scheme](vim/set-your-color-scheme.md) - [Split Different](vim/split-different.md) +- [Swap Occurrences Of Two Words](vim/swap-occurrences-of-two-words.md) - [Tabs To Spaces](vim/tabs-to-spaces.md) - [The Vim Info File](vim/the-vim-info-file.md) - [View Commit History of a File](vim/view-commit-history-of-a-file.md) diff --git a/vim/swap-occurrences-of-two-words.md b/vim/swap-occurrences-of-two-words.md new file mode 100644 index 0000000..ba2214b --- /dev/null +++ b/vim/swap-occurrences-of-two-words.md @@ -0,0 +1,22 @@ +# Swap Occurrences Of Two Words + +If I have a file with `foo` and `bar` all over the place and + +Imagine I have a file with `foo` and `bar` all over the place. The tables +have turned and now I want all occurrences of `foo` to be `bar` and all +occurrences of `bar` to be `foo`. + +Reaching for a simple substitution won't work because after flipping all the +occurrences of `foo` to `bar`. I will no longer be able to distinguish +between the new `bar`s and the `bar`s that need to be flipped. + +[Abolish.vim](https://github.com/tpope/vim-abolish) enhances Vim's +substitution capabilities making it easy to flip these strings in one +relatively simple command. + +``` +:%S/{foo,bar}/{bar,foo}/g +``` + +Notice the uppercase `S` as well as the ordering of `foo` and `bar` in the before +and after sequences.