Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Created February 19, 2011 09:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sroccaserra/834957 to your computer and use it in GitHub Desktop.
Save sroccaserra/834957 to your computer and use it in GitHub Desktop.
Vim's "insert character above / below cursor"
(defun vim-get-line-forward (n)
"Returns the Nth line forward, or nil when reaching buffer end. N can be negative."
(save-excursion
(let ((row (line-number-at-pos)))
(beginning-of-line)
(forward-line n)
(unless (not (= n (- (line-number-at-pos) row)))
(buffer-substring-no-properties (line-beginning-position) (line-end-position))))))
(defun vim-insert-char-from-other-line (n)
"Acts like Vim's i_CTRL-E and i_CTRL-Y. Works with universal argument."
(interactive "p")
(let ((col (current-column))
(other-line (vim-get-line-forward n)))
(when (and other-line
(< col (length other-line)))
(insert (elt other-line col)))))
(defun vim-i-ctrl-e (n)
"Acts line Vim's i_CTRL_E."
(interactive "p")
(vim-insert-char-from-other-line n))
(defun vim-i-ctrl-y (n)
"Acts line Vim's i_CTRL_Y."
(interactive "p")
(vim-insert-char-from-other-line (- n)))
(vimpulse-imap "\C-e" 'vim-i-ctrl-e)
(vimpulse-imap "\C-y" 'vim-i-ctrl-y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment