diff --git a/README.md b/README.md index 683ca61b..764aebcc 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ them useful as no one person uses all of vim's functionality. * Support for marks (including \`.) * Support for `q` and `.` * There is now partial support for `.`, full support is pending atom/atom#962 -* Differentiate between 0 for repetition and 0 for motion. +* ~~Differentiate between 0 for repetition and 0 for motion.~~ * Block backspace in command mode. * Block `ctrl-d` in insert mode. * More advanced keymap to support `iw` motion. diff --git a/docs/motions.md b/docs/motions.md index e93208da..610ba7ea 100644 --- a/docs/motions.md +++ b/docs/motions.md @@ -10,6 +10,6 @@ * [}](http://vimhelp.appspot.com/motion.txt.html#%7D) * [^](http://vimhelp.appspot.com/motion.txt.html#%5E) * [$](http://vimhelp.appspot.com/motion.txt.html#%24) -* [0](http://vimhelp.appspot.com/motion.txt.html#0) (currently disabled) +* [0](http://vimhelp.appspot.com/motion.txt.html#0) * [gg](http://vimhelp.appspot.com/motion.txt.html#gg) * [G](http://vimhelp.appspot.com/motion.txt.html#G) diff --git a/keymaps/vim-mode.cson b/keymaps/vim-mode.cson index 45643f11..128519fd 100644 --- a/keymaps/vim-mode.cson +++ b/keymaps/vim-mode.cson @@ -77,7 +77,7 @@ '^': 'vim-mode:move-to-first-character-of-line' '$': 'vim-mode:move-to-last-character-of-line' '.': 'vim-mode:repeat' - # '0': 'vim-mode:move-to-beginning-of-line' + '0': 'vim-mode:move-to-beginning-of-line' 'g g': 'vim-mode:move-to-start-of-file' 'enter': 'vim-mode:move-down' 'G': 'vim-mode:move-to-line' diff --git a/lib/motions.coffee b/lib/motions.coffee index 66f28137..782604aa 100644 --- a/lib/motions.coffee +++ b/lib/motions.coffee @@ -222,8 +222,7 @@ class MoveToLine extends Motion class MoveToBeginningOfLine extends Motion execute: (count=1) -> - _.times count, => - @editor.moveCursorToBeginningOfLine() + @editor.moveCursorToBeginningOfLine() select: (count=1) -> _.times count, => diff --git a/lib/vim-state.coffee b/lib/vim-state.coffee index b6497e87..05893994 100644 --- a/lib/vim-state.coffee +++ b/lib/vim-state.coffee @@ -104,7 +104,7 @@ class VimState 'move-to-next-paragraph': => new motions.MoveToNextParagraph(@editor) 'move-to-first-character-of-line': => new motions.MoveToFirstCharacterOfLine(@editor) 'move-to-last-character-of-line': => new motions.MoveToLastCharacterOfLine(@editor) - 'move-to-beginning-of-line': => new motions.MoveToBeginningOfLine(@editor) + 'move-to-beginning-of-line': (e) => @moveOrRepeat(e) 'move-to-start-of-file': => new motions.MoveToStartOfFile(@editor) 'move-to-line': => new motions.MoveToLine(@editor) 'register-prefix': (e) => @registerPrefix(e) @@ -283,6 +283,19 @@ class VimState else @pushOperator(new prefixes.Repeat(num)) + # Private: Figure out whether or not we are in a repeat sequence or we just + # want to move to the beginning of the line. If we are within a repeat + # sequence, we pass control over to @repeatPrefix. + # + # e - The triggered event. + # + # Returns nothing. + moveOrRepeat: (e) -> + if @topOperator() instanceof prefixes.Repeat + @repeatPrefix(e) + else + new motions.MoveToBeginningOfLine(@editor) + # Private: A generic way to handle operators that can be repeated for # their linewise form. # diff --git a/spec/motions-spec.coffee b/spec/motions-spec.coffee index 530e64b5..54d4be56 100644 --- a/spec/motions-spec.coffee +++ b/spec/motions-spec.coffee @@ -272,6 +272,26 @@ describe "Motions", -> expect(editor.getText()).toBe ' cde' expect(editor.getCursorScreenPosition()).toEqual [0, 2] + describe "the 0 keybinding", -> + beforeEach -> + editor.setText(" abcde") + editor.setCursorScreenPosition([0, 4]) + + describe "as a motion", -> + beforeEach -> keydown('0') + + it "moves the cursor to the first column", -> + expect(editor.getCursorScreenPosition()).toEqual [0, 0] + + describe "as a selection", -> + beforeEach -> + keydown('d') + keydown('0') + + it 'selects to the first column of the line', -> + expect(editor.getText()).toBe 'cde' + expect(editor.getCursorScreenPosition()).toEqual [0, 0] + describe "the $ keybinding", -> beforeEach -> editor.setText(" abcde\n")