Skip to content

Commit

Permalink
tabs: Go to nth tab when tab-next is prefixed.
Browse files Browse the repository at this point in the history
This emulates the behavior of vim, where {N}gt goes to the Nth tab, but {N}gT
goes back N tabs.
  • Loading branch information
anpandey committed Aug 13, 2023
1 parent f3f5f65 commit 868b162
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -4710,6 +4710,19 @@ and redisplay the current buffer there."
:repeat nil
(evil-move-window 'below))

;;; Tab commands

(evil-define-command evil-tab-next (arg)
"Switch to the next tab.
If ARG is non-nil, parse ARG as an index and go to the tab at
that index."
:repeat nil
(interactive "<N>")
(if arg
(tab-bar-select-tab
(prefix-numeric-value arg))
(tab-bar-switch-to-next-tab)))

;;; Mouse handling

;; Large parts of this code are taken from mouse.el which is
Expand Down
6 changes: 3 additions & 3 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@
(define-key evil-window-map [C-right] 'evil-window-right)

(when (featurep 'tab-bar)
(define-key evil-motion-state-map "gt" 'tab-bar-switch-to-next-tab)
(define-key evil-window-map "gt" 'tab-bar-switch-to-next-tab)
(define-key evil-motion-state-map "gt" 'evil-tab-next)
(define-key evil-window-map "gt" 'evil-tab-next)
(define-key evil-motion-state-map "gT" 'tab-bar-switch-to-prev-tab)
(define-key evil-window-map "gT" 'tab-bar-switch-to-prev-tab))

Expand Down Expand Up @@ -582,7 +582,7 @@ included in `evil-insert-state-bindings' by default."
(evil-ex-define-cmd "tabnew" 'tab-bar-new-tab)
(evil-ex-define-cmd "tabc[lose]" 'tab-bar-close-tab)
(evil-ex-define-cmd "tabo[nly]" 'tab-bar-close-other-tabs)
(evil-ex-define-cmd "tabn[ext]" 'tab-bar-switch-to-next-tab)
(evil-ex-define-cmd "tabn[ext]" 'evil-tab-next)
(evil-ex-define-cmd "tabp[revious]" 'tab-bar-switch-to-prev-tab))

;; search command line
Expand Down

0 comments on commit 868b162

Please sign in to comment.