 
   #### visual mode switches
 
+  # switch to characterwise visual mode
   map 'v', class extends ModeSwitch
     isRepeatable: no
     beforeSwitch: (jim) -> jim.adaptor.setSelectionAnchor()
     switchToMode: 'visual:characterwise'
 
+  # switch to linewise visual mode
   map 'V', class extends ModeSwitch
     isRepeatable: no
     beforeSwitch: (jim) -> jim.adaptor.setLinewiseSelectionAnchor()


  #### insert mode switches

  map 'i', class Insert extends ModeSwitch
    switchToMode: 'insert'
    exec: (jim) ->
      @beforeSwitch? jim
      if @repeatableInsert
        jim.adaptor.insert @repeatableInsert.string
      else
        jim.afterInsertSwitch = true
        jim.setMode @switchToMode

  map 'a', class InsertAfter extends Insert
    beforeSwitch: (jim) -> jim.adaptor.moveRight true

  map 'A', class InsertAtEndOfLine extends Insert
    beforeSwitch: (jim) ->
      new MoveToEndOfLine().exec jim
      jim.adaptor.moveRight true

  map 'C', class ChangeToEndOfLine extends Insert
    beforeSwitch: (jim) ->
      new DeleteToEndOfLine(@count).exec jim

  map 'I', class InsertBeforeFirstNonBlank extends Insert
    beforeSwitch: (jim) -> new MoveToFirstNonBlank().exec jim

  map 'o', class OpenLine extends Insert
    beforeSwitch: (jim) ->
      row = jim.adaptor.row() + (if @above then 0 else 1)
      jim.adaptor.insertNewLine row
      jim.adaptor.moveTo row, 0

  map 'O', class OpenLineAbove extends OpenLine
    above: yes

  map 's', class ChangeChar extends Insert
    beforeSwitch: (jim) -> new DeleteChar(@count).exec jim


# All the default commands (other than operations and motions) for normal mode.  All commands
# can be prefixed with a {count} which multiplies their action in some way.
#
# Commands that also work in visual mode define a `::visualExec` here.

define (require, exports, module) ->
  {Command, repeatCountTimes} = require 'jim/helpers'
  {Change, Delete} = require 'jim/operators'
  {GoToLine, MoveDown, MoveLeft, MoveRight, MoveToEndOfLine, MoveToFirstNonBlank} = require 'jim/motions'

  # The default key mappings are specified alongside the definitions of each command.
  # Accumulate the mappings so they can be exported.
  defaultMappings = {}
  map = (keys, commandClass) -> defaultMappings[keys] = commandClass

  # convenience class for commands that switch to another mode
  class ModeSwitch extends Command
    exec: (jim) ->
      @beforeSwitch? jim
