Created
February 19, 2011 09:20
-
-
Save sroccaserra/834957 to your computer and use it in GitHub Desktop.
Vim's "insert character above / below cursor"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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