A Vim/Neovim plugin to align texts by simple way.
- vim-simple-align provides only 1 command and a few its options
- no need to remember options because they can be completed
- delimiter used to split texts is always Vim's regular expression
vim-simple-align doesn't cover all alignment cases but aims to work nice in many common cases.
vim-simple-align-demo.mp4
vim-simple-align provides only 1 command: :SimpleAlign
.
Usage:
:{RANGE}SimpleAlign {DELIMITER}
Or
:{RANGE}SimpleAlign {DELIMITER} {OPTIONS}
Delimiter is Vim's regular expression. Some characters may need to be escaped.
cf. :h regular-expression
-count
option means how many times to split and align tokens. Available values are -1
and integers greater than 0. -1
means unlimited.
Default: -1
-lpadding
option means how many spaces to put left padding of each token. Available values are integers greater than or equal to 0.
Default: 1
-rpadding
option means how many spaces to put right padding of each token. Available values are integers greater than or equal to 0.
Default: 1
-justify
option means which side tokens should be on. Available values are left
and right
.
Default: left
a | bbb | ccccc
--- | --- | ---
012345 | 6 | 789
.. | .. | ..
| a | bbb | ccccc |
| --- | --- | --- |
| 012345 | 6 | 789 |
| .. | .. | .. |
:1,4SimpleAlign |
a | bbb | ccccc
--- | --- | ---
012345 | 6 | 789
.. | .. | ..
| a | bbb | ccccc |
| --- | --- | --- |
| 012345 | 6 | 789 |
| .. | .. | .. |
a | bbb | ccccc
--- | --- | ---
012345 | 6 | 789
.. | .. | ..
| a | bbb | ccccc |
| --- | --- | --- |
| 012345 | 6 | 789 |
| .. | .. | .. |
:1,4SimpleAlign | -justify right
a | bbb | ccccc
--- | --- | ---
012345 | 6 | 789
.. | .. | ..
| a | bbb | ccccc |
| --- | --- | --- |
| 012345 | 6 | 789 |
| .. | .. | .. |
JSON:
{
"a": "a",
"bbb": "bbb",
"ccccc": "ccccc"
}
JavaScript dictionary:
{
a: "a",
bbb: "bbb",
ccccc: "ccccc",
}
Ruby old Hash syntax:
{
"a" => "a",
"bbb" => "bbb",
"ccccc" => "ccccc",
}
For JSON:
:2,4SimpleAlign [^:\ ]\+:
For JavaScript dictionary:
:2,4SimpleAlign \w\+:
For Ruby old Hash syntax:
:2,4SimpleAlign =>
JSON:
{
"a": "a",
"bbb": "bbb",
"ccccc": "ccccc"
}
JavaScript dictionary:
{
a: "a",
bbb: "bbb",
ccccc: "ccccc",
}
Ruby old Hash syntax:
{
"a" => "a",
"bbb" => "bbb",
"ccccc" => "ccccc",
}
Basic case:
const a = "a";
const bbb = "bbb";
const ccccc = "ccccc";
Case when multiple =
s exist:
const a = "a";
const bbb = "bbb";
const ccccc = "ccccc";
const d = (a === bbb)
=
and +=
:
a = "a"
a += "a"
For basic case:
:1,3SimpleAlign =
For the case when multiple =
s exist:
:1,4SimpleAlign = -count 1
For =
and +=
:
:1,2SimpleAlign [+\ ]=
Basic case:
const a = "a";
const bbb = "bbb";
const ccccc = "ccccc";
Case when multiple =
s exist:
const a = "a";
const bbb = "bbb";
const ccccc = "ccccc";
const d = (a === bbb)
=
and +=
:
a = "a"
a += "a"
JavaScript:
a() //=> "a"
bbb() //=> "bbb"
ccccc() //=> "ccccc"
Ruby:
a #=> "a"
bbb #=> "bbb"
ccccc #=> "ccccc"
For JavaScript:
:1,3SimpleAlign //=> -lpadding 2
For Ruby:
:1,3SimpleAlign #=> -lpadding 2
JavaScript:
a() //=> "a"
bbb() //=> "bbb"
ccccc() //=> "ccccc"
Ruby:
a #=> "a"
bbb #=> "bbb"
ccccc #=> "ccccc"
t.belongs_to :user, null: false
t.string :name, null: false
t.boolean :active, null: false, default: true
t.boolean :foo, null: true, default: false
:1,4SimpleAlign \S\+ -lpadding 0
t.belongs_to :user, null: false
t.string :name, null: false
t.boolean :active, null: false, default: true
t.boolean :foo, null: true, default: false
vim-simple-align is inspired by h1mesuke/vim-alignta. It is a simple Vim plugin to align texts. It provides only 1 command :Alignta
and has a few options and command syntaxes. It is a very great plugin but doesn't work on current Vim. vim-simple-align inherits its philosophy and focuses its limited essential features.
Yes, vim-easy-align is a great Vim plugin. However, it is complicated and difficult for me. I can't remember its mappings, options, and syntaxes. It is a so cool product, but not for me.
If you use dein.vim:
call dein#add("kg8m/vim-simple-align")
Note: dein.vim's lazy loading feature with on_cmd
option is not recommended for vim-simple-align. You will see E471: Argument required: ...
if so. To tell the truth, lazy loading of vim-simple-align doesn't make Vim's startup faster. On the one hand, vim-simple-align just defines 1 command when added to runtimepath
. On the other hand, dein.vim's lazy loading with on_cmd
also defines a dummy command.
You can use Vim9 script version if you use Vim 8.2.4053+. Vim9 script version is 5-10 times faster than legacy Vim script version. Vim9 script version is available on vim9
branch.
call dein#add("kg8m/vim-simple-align", { "rev": "vim9" })
Vim 8.2+ or Neovim nightly