 # -------------------------
 class MoveToNextWholeWord extends MoveToNextWord
   @extend()
+  wordRegex: /^\s*$|\S+/g
+
+class MoveToPreviousWholeWord extends MoveToPreviousWord
+  @extend()
   wordRegex: /^\s*$|\S+/
 
-class MoveToPreviousWholeWord extends MoveToPreviousWord
-  @extend()
-  wordRegex: /^\s*$|\S+/
-
 class MoveToEndOfWholeWord extends MoveToEndOfWord
   @extend()
   wordRegex: /\S+/

class MoveToNextAlphanumericWord extends MoveToNextWord
  @extend()
  @description: "Move to next alphanumeric(`/\w+/`) word"
  wordRegex: /\w+/

class MoveToPreviousAlphanumericWord extends MoveToPreviousWord
  @extend()

  wordRegex: null

  getPoint: (cursor) ->
    cursorPoint = cursor.getBufferPosition()
    pattern = @wordRegex ? cursor.wordRegExp()
    point = null
    @scanWordRange cursorPoint, pattern, ({stop, range}) ->
      {start, end} = range
      if end.isGreaterThan(cursorPoint)
        point = end
        if start.isGreaterThan(cursorPoint)
          point = start
          stop()
    if point?
      Point.min(point, @vimEof)
    else
      cursorPoint

  scanWordRange: (from, pattern, fn) ->
    scanRange = [[from.row, 0], @editor.getEofBufferPosition()]
    @editor.scanInBufferRange pattern, scanRange, (event) ->
      fn(event)

  moveCursor: (cursor) ->
    return if cursorIsAtVimEndOfFile(cursor)
    # cache
    @vimEof = getVimEofBufferPosition(@editor)
    lastCount = @getCount()
    wasOnWhiteSpace = cursorIsOnWhiteSpace(cursor)
    @countTimes (num) =>
      isLastCount = (num is lastCount)
      # cursorPoint = cursor.getBufferPosition()
      cursorRow = cursor.getBufferRow()

      if cursorIsAtEmptyRow(cursor) and @isAsOperatorTarget()
        point = [cursorRow+1, 0]
      else
        point = @getPoint(cursor)
        if isLastCount and @isAsOperatorTarget()
          if @getOperator().getName() is 'Change' and (not wasOnWhiteSpace)
            point = cursor.getEndOfCurrentWordBufferPosition({@wordRegex})
          else if (point.row > cursorRow)
            point = [cursorRow, Infinity]
      cursor.setBufferPosition(point)

class MoveToPreviousWord extends Motion
  @extend()
