Skip to content

Commit

Permalink
Fix cw with count. Fixes #57.
Browse files Browse the repository at this point in the history
It was only working without count or when the cursor was at the end of
the word.
  • Loading branch information
chaoren committed Sep 12, 2021
1 parent 0edeebd commit 0e82952
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions autoload/wordmotion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ function wordmotion#motion(count, mode, flags, uppercase, extra)
let l:pos = getpos('.')

let l:count = a:count
if l:cw
" cw on the last character of a word will match the cursor position
call search('\m'.l:pattern, l:flags.'cW')
let l:count -= 1
endif
while l:count > 0
if l:count == 1 && l:cw
let l:flags .= 'c'
endif
call search('\m'.l:pattern, l:flags.'W')
let l:count -= 1
endwhile
Expand Down
29 changes: 29 additions & 0 deletions tests/cw.vader
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ Then (Assert that cursor is at Tha[t]):
Expect (This changed to That):
That is some text

Do (c2w at [T]his is):
c2wThat's\<Esc>

Then (Assert that cursor is at That'[s]):
AssertEqual 6, col('.')

Expect (This is changed to That's):
That's some text

# first word of line, middle of word

Do (cw at T[h]is):
Expand All @@ -26,6 +35,16 @@ Then (Assert that cursor is at TTha[t]):
Expect (This changed to TThat):
TThat is some text

Do (c2w at T[h]is is):
l
c2wThat's\<Esc>

Then (Assert that cursor is at TThat'[s]):
AssertEqual 7, col('.')

Expect (This is changed to TThat's):
TThat's some text

# first word of line, end of word

Do (cw at Thi[s]):
Expand All @@ -38,6 +57,16 @@ Then (Assert that cursor is at ThiTha[t]):
Expect (This changed to ThiThat):
ThiThat is some text

Do (c2w at Thi[s] is):
e
c2wThat's\<Esc>

Then (Assert that cursor is at ThiThat'[s]):
AssertEqual 9, col('.')

Expect (This is changed to ThiThat's):
ThiThat's some text

# middle of line, start of word

Do (cw at [s]ome):
Expand Down

0 comments on commit 0e82952

Please sign in to comment.