diff --git a/extensions/vi-mode/binds.lisp b/extensions/vi-mode/binds.lisp index e42ea2c0f..1954f9eaf 100644 --- a/extensions/vi-mode/binds.lisp +++ b/extensions/vi-mode/binds.lisp @@ -81,19 +81,32 @@ (define-key *normal-keymap* "z ^" 'vi-scroll-top-line-to-bottom) (define-key *normal-keymap* "Z Z" 'vi-write-quit) (define-key *normal-keymap* "Z Q" 'vi-quit) -(define-key *motion-keymap* "C-w s" 'split-active-window-vertically) -(define-key *motion-keymap* "C-w C-s" 'split-active-window-vertically) + +;; Window Management +(define-key *motion-keymap* "C-w h" 'vi-window-move-left) +(define-key *motion-keymap* "C-w C-h" 'vi-window-move-left) +(define-key *motion-keymap* "C-w j" 'vi-window-move-down) +(define-key *motion-keymap* "C-w C-j" 'vi-window-move-down) +(define-key *motion-keymap* "C-w k" 'vi-window-move-up) +(define-key *motion-keymap* "C-w C-k" 'vi-window-move-up) +(define-key *motion-keymap* "C-w l" 'vi-window-move-right) +(define-key *motion-keymap* "C-w C-l" 'vi-window-move-right) +(define-key *motion-keymap* "C-w s" 'vi-window-split-vertically) +(define-key *motion-keymap* "C-w S" 'vi-window-split-vertically) +(define-key *motion-keymap* "C-w C-s" 'vi-window-split-vertically) +(define-key *motion-keymap* "C-w v" 'vi-window-split-horizontally) +(define-key *motion-keymap* "C-w C-v" 'vi-window-split-horizontally) +(define-key *motion-keymap* "C-w n" 'vi-window-split-vertically-new) +(define-key *motion-keymap* "C-w C-n" 'vi-window-split-vertically-new) (define-key *motion-keymap* "C-w w" 'next-window) (define-key *motion-keymap* "C-w C-w" 'next-window) +(define-key *motion-keymap* "C-w p" 'previous-window) +(define-key *motion-keymap* "C-w C-p" 'previous-window) (define-key *motion-keymap* "C-w q" 'vi-quit) -(define-key *motion-keymap* "C-w h" 'window-move-left) -(define-key *motion-keymap* "C-w C-h" 'undefined-key) -(define-key *motion-keymap* "C-w l" 'window-move-right) -(define-key *motion-keymap* "C-w C-l" 'undefined-key) -(define-key *motion-keymap* "C-w k" 'window-move-up) -(define-key *motion-keymap* "C-w C-k" 'undefined-key) -(define-key *motion-keymap* "C-w j" 'window-move-down) -(define-key *motion-keymap* "C-w C-j" 'undefined-key) +(define-key *motion-keymap* "C-w c" 'vi-close) +(define-key *motion-keymap* "C-w o" 'delete-other-windows) +(define-key *motion-keymap* "C-w C-o" 'delete-other-windows) + (define-key *motion-keymap* "C-o" 'vi-jump-back) (define-key *motion-keymap* "C-i" 'vi-jump-next) (define-key *motion-keymap* "' '" 'vi-jump-previous) diff --git a/extensions/vi-mode/commands.lisp b/extensions/vi-mode/commands.lisp index 81aa461d3..4bef86c5a 100644 --- a/extensions/vi-mode/commands.lisp +++ b/extensions/vi-mode/commands.lisp @@ -138,7 +138,18 @@ :vi-inner-paren :vi-repeat :vi-normal - :vi-keyboard-quit)) + :vi-keyboard-quit + :vi-close + :vi-window-move-left + :vi-window-move-down + :vi-window-move-up + :vi-window-move-right + :vi-window-split-horizontally + :vi-window-split-vertically + :vi-window-split-new-buffer + :vi-window-split-horizontally-new + :vi-window-split-vertically-new + :vi-switch-to-buffer)) (in-package :lem-vi-mode/commands) (defun extract-count-keys (keys) @@ -979,6 +990,12 @@ on the same line or at eol if there are none." (vi-write) (vi-quit nil)) +(define-command vi-close (&optional (n 1)) (:universal) + (dotimes (i n) + (if (one-window-p) + (lem:message "Cannot close last window") + (delete-active-window)))) + (define-command vi-end-insert () () (change-state 'normal) (vi-backward-char 1)) @@ -1092,3 +1109,49 @@ on the same line or at eol if there are none." (error 'editor-abort)) (vi-visual-end) (keyboard-quit)) + +(define-command vi-window-move-left (&optional (n 1)) (:universal) + "Go to the window on the left N times." + (dotimes (i n) (window-move-left))) + +(define-command vi-window-move-down (&optional (n 1)) (:universal) + "Go to the window on the down N times." + (dotimes (i n) (window-move-down))) + +(define-command vi-window-move-up (&optional (n 1)) (:universal) + "Go to the window on the up N times." + (dotimes (i n) (window-move-up))) + +(define-command vi-window-move-right (&optional (n 1)) (:universal) + "Go to the window on the right N times." + (dotimes (i n) (window-move-right))) + +(define-command vi-window-split-horizontally (&optional (n 1)) (:universal) + "Split the window horizontally and moves N times." + (dotimes (i n) + (split-active-window-horizontally) + (window-move-right))) + +(define-command vi-window-split-vertically (&optional (n 1)) (:universal) + "Split the window vertically and moves N times." + (dotimes (i n) + (split-active-window-vertically) + (window-move-down))) + +(define-command vi-switch-to-buffer (&optional (filename nil)) (:universal-nil) + "Opens the specified file name or creates a blank buffer." + (switch-to-buffer (if (or (null filename) (string= filename "")) + (make-buffer nil :temporary t) + (execute-find-file *find-file-executor* (get-file-mode filename) filename)))) + +(define-command vi-window-split-horizontally-new (&optional (n 1) (filename nil)) (:universal) + "Creates an empty buffer in a new window N times." + (dotimes (i (or n 1)) + (vi-window-split-horizontally) + (vi-switch-to-buffer filename))) + +(define-command vi-window-split-vertically-new (&optional (n 1) (filename nil)) (:universal) + "Creates an empty buffer in a new window N times." + (dotimes (i n) + (vi-window-split-vertically) + (vi-switch-to-buffer filename))) diff --git a/extensions/vi-mode/ex-command.lisp b/extensions/vi-mode/ex-command.lisp index a93deb6cb..52fab719c 100644 --- a/extensions/vi-mode/ex-command.lisp +++ b/extensions/vi-mode/ex-command.lisp @@ -54,14 +54,26 @@ (define-ex-command "^(w|write)$" (range filename) (ex-write range filename t)) -(define-ex-command "^wa(?:ll)$" (range argument) +(define-ex-command "^wa(?:ll)?$" (range argument) (declare (ignore range argument)) (ex-write-all nil)) -(define-ex-command "^wa(?:ll)!$" (range argument) +(define-ex-command "^wa(?:ll)?!$" (range argument) (declare (ignore range argument)) (ex-write-all t)) +(define-ex-command "^new$" (range filename) + (declare (ignore range)) + (lem-vi-mode/commands:vi-window-split-vertically-new 1 filename)) + +(define-ex-command "^vne(?:w)?$" (range filename) + (declare (ignore range filename)) + (lem-vi-mode/commands:vi-window-split-horizontally-new 1 filename)) + +(define-ex-command "^ene(?:w)?$" (range filename) + (declare (ignore range)) + (lem-vi-mode/commands:vi-switch-to-buffer filename)) + (define-ex-command "^update$" (range filename) (when (lem:buffer-modified-p (lem:current-buffer)) (ex-write range filename t))) @@ -106,12 +118,20 @@ (ex-write-all t) (lem:exit-lem nil)) +(define-ex-command "^clo(?:se)?$" (range filename) + (declare (ignore range filename)) + (lem-vi-mode/commands:vi-close 1)) + (define-ex-command "^(x|xit)$" (range filename) (ex-write-quit range filename nil nil)) (define-ex-command "^(x|xit)!$" (range filename) (ex-write-quit range filename t nil)) +(define-ex-command "^on(?:ly)?$" (range filename) + (declare (ignore range filename)) + (lem:delete-other-windows)) + (defun copy-current-jumplist-to-next-window () (let* ((window-list (lem:compute-window-list (lem:current-window)))