This package provides gl
and gL
align operators: gl MOTION CHAR
and right-align gL MOTION CHAR
.
Use CHAR /
to enter regular expression if a single character wouldn't suffice.
Use CHAR RET
to align with align.el's default rules for the active major mode.
Port of vim-lion
with use-package
(use-package evil-lion
:ensure t
:config
(evil-lion-mode))
without use-package
M-x package-install RET evil-lion RET
, then add in init.el
:
(evil-lion-mode)
Align with gl MOTION CHAR
or right-align with gL MOTION CHAR
.
If the align separator is /
you will be prompted for a regular expression instead of a plain character.
If the align separator is RET
alignment will be performed with align.el's rules specific for the major mode.
You can pass count 1
to align on the first occurrence of CHAR
. To pass count, use: COUNT gl MOTION CHAR
.
After pressing glip=
(gl
is the operator, ip
text object paragraph, =
separator)
one = 1
three = 3
fifteen = 15
will become:
one = 1
three = 3
fifteen = 15
After pressing gLip,
one, two, three,
fifteen, sixteen, seventeen
will become:
one, two, three,
fifteen, sixteen, seventeen
In perl-mode, after pressing glib RET
(RET
is return key, not individal keys):
my %hash = (
a => 1,
bbb => 2,
cccc => 3,
a => 1,
bbb => 2,
cccccc => 3
);
will become:
my $hash = (
a => 1,
bbb => 2,
cccc => 3,
a => 1,
bbb => 2,
cccccc => 3
););
After pressing 1glip"
(red "red"
(teal-green "#6fb593")
(wheat "#b9c791")
(blue "blue")
(cyan "#54b6b6")
will become:
(red "red"
(teal-green "#6fb593")
(wheat "#b9c791")
(blue "blue")
(cyan "#54b6b6")
By default, evil-lion will remove unnecessary spaces if there are any. To disable this behaviour:
(setq evil-lion-squeeze-spaces nil) ;; default t
;; use `g a` (mnemonic `align`)
;; these variables should be changed before (evil-lion-mode) is called
(setq evil-lion-left-align-key (kbd "g a"))
(setq evil-lion-right-align-key (kbd "g A"))
(evil-lion-mode)
Or withuse-package
and bind-key
:
(use-package evil-lion
:ensure t
:bind (:map evil-normal-state-map
("g l " . evil-lion-left)
("g L " . evil-lion-right)
:map evil-visual-state-map
("g l " . evil-lion-left)
("g L " . evil-lion-right)))
Bind evil-lion-left
and evil-lion-right
to your liking.
The evil-lion-mode
is just a convenience mode and should not be enabled with this setup.
(evil-define-key 'normal prog-mode-map
(kbd "g l") 'evil-lion-left
(kbd "g L") 'evil-lion-right)
(evil-define-key 'visual prog-mode-map
(kbd "g l") 'evil-lion-left
(kbd "g L") 'evil-lion-right)