Skip to content

Commit

Permalink
Merge pull request #32 from preservim/fix-replace
Browse files Browse the repository at this point in the history
Fix longstanding bug in replace
  • Loading branch information
telemachus authored Feb 10, 2022
2 parents 5550ed2 + 258bb2d commit 164629d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
9 changes: 5 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[vq]: /~https://github.com/reedes/vim-quotable

While Vim is renown for its text manipulation capabilities, it
While Vim is renowned for its text manipulation capabilities, it
nevertheless retains a bias towards ASCII that stretches back to its vi
roots on Unix. This can limit Vim’s appeal for those who prefer
typographic characters like “curly quotes” over ASCII "straight quotes" in
Expand Down Expand Up @@ -187,10 +187,11 @@ map <silent> <leader>qc <Plug>ReplaceWithCurly
map <silent> <leader>qs <Plug>ReplaceWithStraight
```

Both _Normal_ and _Visual_ modes are supported by this feature.
Both _Normal_ and _Visual_ modes are supported by this feature. (In
_Normal_ mode, quotes in the current paragraph are replaced.)

To transform all quotes in a document, use _Visual_ mode to select all the
text in the document.
To transform all quotes in a document, use _Visual_ mode to select the
entire document.

### Surround support

Expand Down
2 changes: 1 addition & 1 deletion autoload/textobj/quote/replace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function! textobj#quote#replace#replace(mode, visual)
if len(a:visual) > 0
execute "normal! gv\"" . textobj#quote#replace#getDefaultReg() . "y"
else
execute "normal! vi\"" . textobj#quote#replace#getDefaultReg() . "py"
execute "normal! vip\"" . textobj#quote#replace#getDefaultReg() . "y"
endif
let l:text = getreg(textobj#quote#replace#getDefaultReg())

Expand Down
42 changes: 28 additions & 14 deletions tests/replace.vader
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,58 @@ Execute (Clean up test environment):
map <silent> \ <Plug>ReplaceWithStraight

###########################################################
# This test is failing
Given:
"It's 'Dr.' Evil, thank you very much."
"It's 'Dr.' Evil, thank you very much," he said. Then I said, "What do you
know about it anyhow. You aren't very nice, are you?" Then he stormed off,
and I haven't seen him since.

Do (Curl quotes without visual):
Do (Curl quotes in normal mode):
;

Expect:
“It’s ‘Dr.’ Evil, thank you very much.”
“It’s ‘Dr.’ Evil, thank you very much,” he said. Then I said, “What do you
know about it anyhow. You aren’t very nice, are you?” Then he stormed off,
and I haven’t seen him since.

###########################################################
# This test is failing
Given:
“It’s ‘Dr.’ Evil, thank you very much.”
“It’s ‘Dr.’ Evil, thank you very much,” he said. Then I said, “What do you
know about it anyhow. You aren’t very nice, are you?” Then he stormed off,
and I haven’t seen him since.

Do (Clear quotes without Visual):
Do (Straighten quotes in normal mode):
\

Expect:
"It's 'Dr.' Evil, thank you very much."
"It's 'Dr.' Evil, thank you very much," he said. Then I said, "What do you
know about it anyhow. You aren't very nice, are you?" Then he stormed off,
and I haven't seen him since.


Given:
"It's 'Dr.' Evil, thank you very much."
"It's 'Dr.' Evil, thank you very much," he said. Then I said, "What do you
know about it anyhow. You aren't very nice, are you?" Then he stormed off,
and I haven't seen him since.

Do (Curl quotes with visual):
Do (Curl quotes in visual mode):
vip;

Expect:
“It’s ‘Dr.’ Evil, thank you very much.”
“It’s ‘Dr.’ Evil, thank you very much,” he said. Then I said, “What do you
know about it anyhow. You aren’t very nice, are you?” Then he stormed off,
and I haven’t seen him since.


Given:
“It’s ‘Dr.’ Evil, thank you very much.”
“It’s ‘Dr.’ Evil, thank you very much,” he said. Then I said, “What do you
know about it anyhow. You aren’t very nice, are you?” Then he stormed off,
and I haven’t seen him since.

Do (Clear quotes with Visual):
Do (Straighten quotes in visual mode):
vip\

Expect:
"It's 'Dr.' Evil, thank you very much."
"It's 'Dr.' Evil, thank you very much," he said. Then I said, "What do you
know about it anyhow. You aren't very nice, are you?" Then he stormed off,
and I haven't seen him since.

0 comments on commit 164629d

Please sign in to comment.