fix #36 vim mode: 'e' moves to the beginning of the next word (#64)

I updated the switch in vim.go to treat 'w' and 'W' differently to 'e' and 'E'.

I then added a method to runebuf.go to provide the logic for that motion.
tested and working.
This commit is contained in:
aktungmak 2016-07-26 15:40:22 +02:00 committed by chzyer
parent cffdf641d1
commit 47d43db0fd
2 changed files with 25 additions and 1 deletions

View File

@ -259,6 +259,28 @@ func (r *RuneBuffer) MoveToNextWord() {
}) })
} }
func (r *RuneBuffer) MoveToEndWord() {
r.Refresh(func() {
// already at the end, so do nothing
if r.idx == len(r.buf) {
return
}
// if we are at the end of a word already, go to next
if !IsWordBreak(r.buf[r.idx]) && IsWordBreak(r.buf[r.idx+1]) {
r.idx++
}
// keep going until at the end of a word
for i := r.idx + 1; i < len(r.buf); i++ {
if IsWordBreak(r.buf[i]) && !IsWordBreak(r.buf[i-1]) {
r.idx = i - 1
return
}
}
r.idx = len(r.buf)
})
}
func (r *RuneBuffer) BackEscapeWord() { func (r *RuneBuffer) BackEscapeWord() {
r.Refresh(func() { r.Refresh(func() {
if r.idx == 0 { if r.idx == 0 {

4
vim.go
View File

@ -74,8 +74,10 @@ func (o *opVim) handleVimNormalMovement(r rune, readNext func() rune) (t rune, h
} }
case 'b', 'B': case 'b', 'B':
rb.MoveToPrevWord() rb.MoveToPrevWord()
case 'w', 'W', 'e', 'E': case 'w', 'W':
rb.MoveToNextWord() rb.MoveToNextWord()
case 'e', 'E':
rb.MoveToEndWord()
case 'f', 'F', 't', 'T': case 'f', 'F', 't', 'T':
next := readNext() next := readNext()
prevChar := r == 't' || r == 'T' prevChar := r == 't' || r == 'T'