 # Jump motions
 # ------------
 
-# go to `{count}` line number or the first line
+# Go to `{count}` line number or the first line.
 map 'gg', class GoToLine extends Motion
   linewise: yes
   exec: (jim) ->

    jim.adaptor.moveTo rowNumber, 0
    new MoveToFirstNonBlank().exec jim

# go to `{count}` line number or the last line
map 'G', class GoToLineOrEnd extends GoToLine
  constructor: (@count) ->
  exec: (jim) ->
    @count or= jim.adaptor.lastRow() + 1
    super

# go to the first line that's visible in the viewport
map 'H', class GoToFirstVisibleLine extends Motion
  linewise: yes
  exec: (jim) ->
    line = jim.adaptor.firstFullyVisibleRow() + @count
    new GoToLineOrEnd(line).exec jim

# go to the middle line of the lines that exist and are visible in the viewport
map 'M', class GoToMiddleLine extends Motion
  linewise: yes
  exec: (jim) ->

    match = regex.exec leftOfCursor
    if match
      column = match.index

    # If there are no matches left of the cursor, go to the last word on the
    # previous line.  Vim skips lines that are have only whitespace on them, but
    # not completely empty lines.
    else
      row--
      row-- while /^\s+$/.test(line = jim.adaptor.lineText row)
      match = regex.exec line
      column = match?.index or 0
