Merge pull request #33 from chzyer/feature/support_more_vim_feature

Support more vim shortcut
This commit is contained in:
Chzyer 2016-02-27 10:07:23 +08:00
commit 44ccc71d92
2 changed files with 33 additions and 0 deletions

View File

@ -137,6 +137,16 @@ func (r *RuneBuffer) MoveForward() {
}) })
} }
func (r *RuneBuffer) IsCursorInEnd() bool {
return r.idx == len(r.buf)
}
func (r *RuneBuffer) Replace(ch rune) {
r.Refresh(func() {
r.buf[r.idx] = ch
})
}
func (r *RuneBuffer) Erase() { func (r *RuneBuffer) Erase() {
r.Refresh(func() { r.Refresh(func() {
r.idx = 0 r.idx = 0

23
vim.go
View File

@ -53,6 +53,25 @@ func (o *opVim) handleVimNormalMovement(r rune, readNext func() rune) (t rune, h
rb.MoveToLineStart() rb.MoveToLineStart()
case '$': case '$':
rb.MoveToLineEnd() rb.MoveToLineEnd()
case 'x':
rb.Delete()
if rb.IsCursorInEnd() {
rb.MoveBackward()
}
case 'r':
rb.Replace(readNext())
case 'd':
next := readNext()
switch next {
case 'd':
rb.Erase()
case 'w':
rb.DeleteWord()
case 'h':
rb.Backspace()
case 'l':
rb.Delete()
}
case 'b', 'B': case 'b', 'B':
rb.MoveToPrevWord() rb.MoveToPrevWord()
case 'w', 'W', 'e', 'E': case 'w', 'W', 'e', 'E':
@ -94,6 +113,10 @@ func (o *opVim) handleVimNormalEnterInsert(r rune, readNext func() rune) (t rune
rb.Erase() rb.Erase()
case 'w': case 'w':
rb.DeleteWord() rb.DeleteWord()
case 'h':
rb.Backspace()
case 'l':
rb.Delete()
} }
default: default:
return r, false return r, false