     helpers.keydown(key, options)
 
   describe "the x keybinding", ->
-    it "deletes a character", ->
-      editor.setText("012345")
-      editor.setCursorScreenPosition([0, 4])
-
-      keydown('x')
-      expect(editor.getText()).toBe '01235'
-      expect(editor.getCursorScreenPosition()).toEqual [0, 4]
-      expect(vimState.getRegister('"').text).toBe '4'
-
-      keydown('x')
-      expect(editor.getText()).toBe '0123'
-      expect(editor.getCursorScreenPosition()).toEqual [0, 3]
-      expect(vimState.getRegister('"').text).toBe '5'
-
-      keydown('x')
-      expect(editor.getText()).toBe '012'
-      expect(editor.getCursorScreenPosition()).toEqual [0, 2]
-      expect(vimState.getRegister('"').text).toBe '3'
-
-    it "deletes nothing when cursor is on empty line", ->
-      editor.getBuffer().setText "012345\n\nabcdef"
-      editor.setCursorScreenPosition [1, 0]
-
-      keydown('x')
-      expect(editor.getText()).toBe "012345\n\nabcdef"
+    describe "on a line with content", ->
+      beforeEach ->
+        editor.setText("012345")
+        editor.setCursorScreenPosition([0, 4])
+
+      it "deletes a character", ->
+        keydown('x')
+        expect(editor.getText()).toBe '01235'
+        expect(editor.getCursorScreenPosition()).toEqual [0, 4]
+        expect(vimState.getRegister('"').text).toBe '4'
+
+        keydown('x')
+        expect(editor.getText()).toBe '0123'
+        expect(editor.getCursorScreenPosition()).toEqual [0, 3]
+        expect(vimState.getRegister('"').text).toBe '5'
+
+        keydown('x')
+        expect(editor.getText()).toBe '012'
+        expect(editor.getCursorScreenPosition()).toEqual [0, 2]
+        expect(vimState.getRegister('"').text).toBe '3'
+
+    describe "on an empty line", ->
+      beforeEach ->
+        editor.setText("012345\n\nabcdef")
+        editor.setCursorScreenPosition([1, 0])
+        keydown('x')
+
+      it "deletes nothing when cursor is on empty line", ->
+        expect(editor.getText()).toBe "012345\n\nabcdef"
 
   describe "the s keybinding", ->
     beforeEach ->
       editor.setText('012345')
       editor.setCursorScreenPosition([0, 1])
+      keydown('s')
 
     it "deletes the character to the right and enters insert mode", ->
-      keydown('s')
-
       expect(editor).toHaveClass 'insert-mode'
       expect(editor.getText()).toBe '02345'
       expect(editor.getCursorScreenPosition()).toEqual [0, 1]
       expect(vimState.getRegister('"').text).toBe '1'
 
-    it "deletes count characters to the right and enters insert mode", ->
-      keydown('3')
-      keydown('s')
-
-      expect(editor).toHaveClass 'insert-mode'
-      expect(editor.getText()).toBe '045'
-      expect(editor.getCursorScreenPosition()).toEqual [0, 1]
-      expect(vimState.getRegister('"').text).toBe '123'
-
   describe "the S keybinding", ->
-    it "deletes the entire line and enters insert mode", ->
+    beforeEach ->
       editor.setText("12345\nabcde\nABCDE")
       editor.setCursorScreenPosition([1, 3])
-
       keydown('S', shift: true)
+
+    it "deletes the entire line and enters insert mode", ->
       expect(editor).toHaveClass 'insert-mode'
       expect(editor.getText()).toBe "12345\n\nABCDE"
       expect(editor.getCursorScreenPosition()).toEqual [1, 0]

    beforeEach ->
      editor.getBuffer().setText("012\n")

    it "switches to insert mode and shifts to the right", ->
      editor.setCursorScreenPosition([0, 0])

      keydown('a')

      expect(editor.getCursorScreenPosition()).toEqual [0, 1]
      expect(editor).toHaveClass 'insert-mode'

    it "doesn't linewrap", ->
      editor.setCursorScreenPosition([0, 3])

      keydown('a')

      expect(editor.getCursorScreenPosition()).toEqual [0, 3]

  describe "the J keybinding", ->
    beforeEach ->
      editor.getBuffer().setText("012\n    456\n")
      editor.setCursorScreenPosition([0, 1])

    it "deletes the contents until the end of the line", ->
      keydown('J', shift: true)

      expect(editor.getText()).toBe "012 456\n"

    describe "undo behavior", ->
      it "handles repeats", ->
        editor.setText("12345\nabcde\nABCDE\nQWERT")
        editor.setCursorScreenPosition([1, 1])

        keydown('2')
        keydown('J', shift: true)

        keydown('u')

        expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"

  describe "the > keybinding", ->
    describe "when followed by a >", ->
      it "indents the current line", ->
        editor.setText("12345\nabcde\nABCDE")
        editor.setCursorScreenPosition([1, 1])

        keydown('>')
        keydown('>')

        expect(editor.getText()).toBe "12345\n  abcde\nABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [1, 2]

      it "indents multiple lines at once", ->
        editor.setText("12345\nabcde\nABCDE")
        editor.setCursorScreenPosition([0, 0])

        keydown('3')
        keydown('>')
        keydown('>')

        expect(editor.getText()).toBe "  12345\n  abcde\n  ABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [0, 2]

        keydown('u')
        expect(editor.getText()).toBe "12345\nabcde\nABCDE"

  describe "the < keybinding", ->
    describe "when followed by a <", ->
      it "indents the current line", ->
        expect(editor.setText("12345\n  abcde\nABCDE"))
        editor.setCursorScreenPosition([1, 2])

        keydown('<')
        keydown('<')
        expect(editor.getText()).toBe "12345\nabcde\nABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [1, 0]

      it "indents multiple lines at once", ->
        editor.setText("  12345\n  abcde\n  ABCDE")
        editor.setCursorScreenPosition([0, 0])

        keydown('3')
        keydown('<')
        keydown('<')
        expect(editor.getText()).toBe "12345\nabcde\nABCDE"
        expect(editor.getCursorScreenPosition()).toEqual [0, 0]

        keydown('u')
        expect(editor.getText()).toBe "  12345\n  abcde\n  ABCDE"

      editor.getBuffer().setText("012 345\nabc\n")
      editor.setCursorScreenPosition([0, 4])

    describe "when followed by a second y ", ->
      beforeEach ->
        keydown('y')
        keydown('y')

      it "saves the line to the default register", ->
        expect(vimState.getRegister('"').text).toBe "012 345\n"
        expect(editor.getCursorScreenPosition()).toEqual [0, 4]

    describe "when followed with a repeated y", ->
      beforeEach ->
        keydown('y')
        keydown('2')
        keydown('y')

      it "copies n lines, starting from the current", ->
        expect(vimState.getRegister('"').text).toBe "012 345\nabc\n"

    describe "with a register", ->
      beforeEach ->
        keydown('"')
        keydown('a')
        keydown('y')
        keydown('y')

      it "saves the line to the a register", ->
        expect(vimState.getRegister('a').text).toBe "012 345\n"

    describe "with a motion", ->
      beforeEach ->
        keydown('y')
        keydown('w')

      it "saves the first word to the default register", ->
        expect(vimState.getRegister('"').text).toBe '345'

  describe "the Y keybinding", ->
    beforeEach ->
      editor.getBuffer().setText "012 345\nabc\n"
      editor.setCursorScreenPosition [0, 4]

    it "saves the line to the default register", ->
      keydown('Y', shift: true)

      expect(vimState.getRegister('"').text).toBe "012 345\n"
      expect(editor.getCursorScreenPosition()).toEqual [0, 4]

  describe "the p keybinding", ->
    describe "with character contents", ->
      beforeEach ->
        editor.getBuffer().setText "012\n"
        editor.setCursorScreenPosition [0, 0]
        vimState.setRegister('"', text: '345')
        vimState.setRegister('a', text: 'a')

      describe "from the default register", ->
        beforeEach -> keydown('p')

        it "inserts the contents", ->
          expect(editor.getText()).toBe "034512\n"
          expect(editor.getCursorScreenPosition()).toEqual [0, 4]

      describe "from a specified register", ->
        beforeEach ->
          keydown('"')
          keydown('a')
          keydown('p')

        it "inserts the contents of the 'a' register", ->
          expect(editor.getText()).toBe "0a12\n"
          expect(editor.getCursorScreenPosition()).toEqual [0, 2]

    describe "with linewise contents", ->
      beforeEach ->
        editor.getBuffer().setText("012\n")
        editor.setCursorScreenPosition([0, 1])
        vimState.setRegister('"', text: " 345\n", type: 'linewise')
        keydown('p')

      it "inserts the contents of the default register", ->
        expect(editor.getText()).toBe "012\n 345\n"
        expect(editor.getCursorScreenPosition()).toEqual [1, 1]

    describe "undo behavior", ->
      beforeEach ->
        editor.setText("12345\nabcde\nABCDE\nQWERT")
        editor.setCursorScreenPosition([1, 1])
        vimState.setRegister('"', text: '123')
        keydown('2')
        keydown('p')
        keydown('u')

      it "handles repeats", ->
        expect(editor.getText()).toBe "12345\nabcde\nABCDE\nQWERT"

  describe "the P keybinding", ->
    describe "with character contents", ->
      beforeEach ->
        editor.getBuffer().setText("012\n")
        editor.setCursorScreenPosition([0, 0])
        vimState.setRegister('"', text: '345')
        vimState.setRegister('a', text: 'a')
        keydown('P', shift: true)

      it "inserts the contents of the default register above", ->
        expect(editor.getText()).toBe "345012\n"
        expect(editor.getCursorScreenPosition()).toEqual [0, 3]

  describe "the O keybinding", ->
    beforeEach ->
