Issue #284 resolved

gm move to middle of line command is not supported (it is in Vim)

Anonymous created an issue

Vim has the command 'gm' to move to the middle of the current visual line (middle of screen on the current line). Evil currently lacks this command.

Comments (5)

  1. Anonymous

    This code works exactly like Vim for lines of normal characters and tabs and performs acceptably for multi-byte characters:

    (evil-define-motion evil-middle-of-visual-line ()
     "Move the cursor to the middle of the current screen line."
      :type exclusive
      (move-to-column (/ (window-body-width) 2))
    )
    (define-key evil-normal-state-map "gm" 'evil-middle-of-visual-line)
    

    PS I'm an open source noob, should I be posting small contributions like this elsewhere?

  2. Michael Markert

    This doesn't do the same as Vim's "gm" and moves to the char at half the window width and not to char in the middle of the current visual line.

    The position calculation is more along the lines of

    (let ((v-end (save-excursion (end-of-visual-line) (point)))
          (v-begin (save-excursion (beginning-of-visual-line) (point))))
      (goto-char (+ v-begin (/ (- v-end v-begin) 2))))
    
  3. Frank Fischer repo owner
    • changed status to open

    But the second solution does not deal correctly with tabs, each of which counts for several columns.

    I submit another variant, hope it works as expected ;)

  4. Log in to comment