From e967bfcedbd78d770051a5ed72ecbdf0f40aa96e Mon Sep 17 00:00:00 2001 From: Cheney Date: Wed, 24 Feb 2016 22:35:22 +0800 Subject: [PATCH] #22 support more vim shortcut * c, d (change, delete) * x (delete character) * r (replace character) --- runebuf.go | 10 ++++++++++ vim.go | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/runebuf.go b/runebuf.go index e4bcc74..26773ae 100644 --- a/runebuf.go +++ b/runebuf.go @@ -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 diff --git a/vim.go b/vim.go index f587b6c..2203dec 100644 --- a/vim.go +++ b/vim.go @@ -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': @@ -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