Skip to content

Commit

Permalink
Merge pull request #33 from chzyer/feature/support_more_vim_feature
Browse files Browse the repository at this point in the history
Support more vim shortcut
  • Loading branch information
chzyer committed Feb 27, 2016
2 parents f1ecca3 + e967bfc commit 44ccc71
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions runebuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
r.Refresh(func() {
r.idx = 0
Expand Down
23 changes: 23 additions & 0 deletions vim.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ func (o *opVim) handleVimNormalMovement(r rune, readNext func() rune) (t rune, h
rb.MoveToLineStart()
case '$':
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':
rb.MoveToPrevWord()
case 'w', 'W', 'e', 'E':
Expand Down Expand Up @@ -94,6 +113,10 @@ func (o *opVim) handleVimNormalEnterInsert(r rune, readNext func() rune) (t rune
rb.Erase()
case 'w':
rb.DeleteWord()
case 'h':
rb.Backspace()
case 'l':
rb.Delete()
}
default:
return r, false
Expand Down

0 comments on commit 44ccc71

Please sign in to comment.