             keyChar = String.fromCharCode event.charCode
             @countPrefix =
               if keyChar?.length == 1 and "0" <= keyChar <= "9" and @countPrefix + keyChar != "0"
-                if @options.initialCount
-                  @countPrefix = ""
-                  delete @options.initialCount
                 @countPrefix + keyChar
               else
                 ""
 
-# Some symbolic names.
+  # This handles both "d3w" and "3dw". Also, "3d2w" deletes six words.
+  getCountPrefix: (prefix = @countPrefix) ->
+    prefix = prefix.toString() if typeof prefix == "number"
+    count = @countPrefixFactor * if 0 < prefix?.length then parseInt prefix else 1
+    @countPrefix = ""
+    @countPrefixFactor = 1
+    count
+
+# Some symbolic names for widely-used strings.
 forward = "forward"
 backward = "backward"
 character = "character"

      "P": -> @pasteClipboard backward
      "v": -> @launchSubMode VisualMode

      "Y": -> @enterVisualModeForMovement runMovement: "Y"
      "x": -> @enterVisualModeForMovement runMovement: "h", deleteFromDocument: true
      "y": -> @enterVisualModeForMovement yYanksLine: true
      "d": -> @enterVisualModeForMovement deleteFromDocument: true, dYanksLine: true
      "c": -> @enterVisualModeForMovement deleteFromDocument: true, onYank: => @enterInsertMode()

      "D": -> @enterVisualModeForMovement runMovement: "$", deleteFromDocument: true
      "C": -> @enterVisualModeForMovement runMovement: "$", deleteFromDocument: true, onYank: => @enterInsertMode()

      # Disabled as potentially confusing.
      # # If the input is empty, then enter insert mode immediately

  getDirection: ->
    # Try to move the selection forward or backward, check whether it got bigger or smaller (then restore it).
    for direction in [ forward, backward ]
      if change = @extendByOneCharacter direction
        @extendByOneCharacter @opposite[direction]
        return if 0 < change then direction else @opposite[direction]
    forward

  # An approximation of the vim "w" movement; only ever used in the forward direction.  The last two character
  # movements allow us to also get to the end of the very-last word.
  moveForwardWord: () ->
    # First, move to the end of the preceding word...
    if @runMovements "forward character", "backward word", "forward word"
      # And then to the start of the following word...
      @runMovements "forward word", "forward character", "backward character", "backward word"

  collapseSelectionToAnchor: ->
    if 0 < @selection.toString().length
      @selection[if @getDirection() == backward then "collapseToEnd" else "collapseToStart"]()

  collapseSelectionToFocus: ->
    if 0 < @selection.toString().length
      @selection[if @getDirection() == forward then "collapseToEnd" else "collapseToStart"]()

  movements:
    "l": "forward character"
