diff --git a/spec/atom/vim-mode-spec.coffee b/spec/atom/vim-mode-spec.coffee index 7a62d07a4..e47eed8ea 100644 --- a/spec/atom/vim-mode-spec.coffee +++ b/spec/atom/vim-mode-spec.coffee @@ -78,13 +78,27 @@ describe "VimMode", -> expect(editor.getCursor()).toEqual(column: 1, row: 0) describe "the w keybinding", -> - it "moves the cursor to the beginning of the next word", -> - editor.buffer.setText("ab cde 123+- \n xyz") + fit "moves the cursor to the beginning of the next word", -> + editor.buffer.setText("ab cde1+- \n xyz\n\nzip") editor.setCursor(column: 0, row: 0) editor.trigger keydownEvent('w') expect(editor.getCursor()).toEqual(column: 3, row: 0) + editor.trigger keydownEvent('w') + expect(editor.getCursor()).toEqual(column: 7, row: 0) + + editor.trigger keydownEvent('w') + expect(editor.getCursor()).toEqual(column: 1, row: 1) + + editor.trigger keydownEvent('w') + expect(editor.getCursor()).toEqual(column: 0, row: 2) + + editor.trigger keydownEvent('w') + expect(editor.getCursor()).toEqual(column: 0, row: 3) + + editor.trigger keydownEvent('w') + expect(editor.getCursor()).toEqual(column: 3, row: 3) describe "numeric prefix bindings", -> it "repeats the following operation N times", -> diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index 27bc6b772..049c0162a 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -61,8 +61,8 @@ class Editor extends Template getCursor: -> @getAceSession().getSelection().getCursor() - getLineText: -> - @buffer.getLine(@getRow()) + getLineText: (row) -> + @buffer.getLine(row) getRow: -> { row } = @getCursor() diff --git a/src/atom/vim-mode-operators.coffee b/src/atom/vim-mode-operators.coffee index cb8c5b5c1..26f0f3e4e 100644 --- a/src/atom/vim-mode-operators.coffee +++ b/src/atom/vim-mode-operators.coffee @@ -54,12 +54,17 @@ module.exports = execute: (editor) -> regex = getWordRegex() { row, column } = editor.getCursor() - rightOfCursor = editor.getLineText().substring(column) + rightOfCursor = editor.getLineText(row).substring(column) match = regex.exec(rightOfCursor) # If we're on top of part of a word, match the next one. match = regex.exec(rightOfCursor) if match?.index is 0 - column += match.index + + if match + column += match.index + else + nextLineMatch = regex.exec(editor.getLineText(++row)) + column = nextLineMatch?.index or 0 editor.setCursor { row, column }