Skip to content
This repository has been archived by the owner on Apr 6, 2018. It is now read-only.

Commit

Permalink
Merge pull request #71 from jroes/move-to-beginning-of-line
Browse files Browse the repository at this point in the history
Move to beginning of line
  • Loading branch information
mcolyer committed Feb 28, 2014
2 parents 07146af + de8bc82 commit f764801
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/motions.md
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion keymaps/vim-mode.cson
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions lib/motions.coffee
Expand Up @@ -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, =>
Expand Down
15 changes: 14 additions & 1 deletion lib/vim-state.coffee
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
#
Expand Down
20 changes: 20 additions & 0 deletions spec/motions-spec.coffee
Expand Up @@ -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")
Expand Down

0 comments on commit f764801

Please sign in to comment.