Argonaut is a Neovim extension for manipulating function arguments, lists, and dictionaries. It is the successor to ArgWrap, a much more basic extension I created for Vim many years ago. Argonaut has more features, handles edge cases better, and is much easier to work on compared to its predecessor.
Features include:
- Wrapping and unwrapping of argument lists.
- Reformatting argument lists for consistency.
- Navigating forwards and backwards in argument lists.
- Declaring text objects for individual arguments.
The plugin is configured via the setup function. Options may be provided to change the default settings shown below.
require('argonaut').setup({
brace_last_indent = false,
brace_last_wrap = true,
brace_pad = false,
comma_last = false,
comma_prefix = false,
comma_prefix_indent = false,
limit_cols = 512,
limit_rows = 64,
by_filetype = {
go = {comma_last = true},
},
})Global options can be overridden for specific file types by inserting a configuration in the by_filetype table. In the sample configuration shown above, we force all wrapped brace ranges in Go to end with a comma.
Per-brace configuration is possible by assigning tables instead of raw values. The following configuration only pads curly braces:
brace_pad = {['{'] = true},The table should be keyed on the type of brace you wish to specialize, where * matches everything.
Specifies if the closing brace should be indented to argument depth.
-- brace_last_indent = true
Foo(
wibble,
wobble,
wubble
)-- brace_last_indent = false
Foo(
wibble,
wobble,
wubble
)Specifies if the closing brace should be wrapped to a new line.
-- brace_last_wrap = true
Foo(
wibble,
wobble,
wubble
)-- brace_last_wrap = false
Foo(
wibble,
wobble,
wubble)Specifies which brace types should be padded on the inside with spaces.
-- brace_pad = true
[ 1, 2, 3 ]-- brace_pad = false
[1, 2, 3]Specifies which closing brace should be preceded with a comma when wrapping lines.
-- comma_last = true
[
1,
2,
3,
]
-- comma_last = false
[
1,
2,
3
]Specifies if the argument comma delimiter should be placed before arguments.
-- comma_prefix = true
Foo(
wibble
, wobble
, wubble
)-- comma_prefix = false
Foo(
wibble,
wobble,
wubble
)Specifies if the first argument should be indented when used in conjunction with comma_prefix.
-- comma_prefix_indent = true
Foo(
wibble
, wobble
, wubble
)-- comma_prefix_indent = false
Foo(
wibble
, wobble
, wubble
)Limits the maximum number of columns to consider on each line of an argument range.
Limits the maximum number of rows to search and parse around the cursor.
Commands are not mapped by default; an example set of bindings is shown below:
vim.keymap.set('n', '<leader>a', ':<c-u>ArgonautToggle<cr>', {noremap = true, silent = true})
vim.keymap.set({'x', 'o'}, 'ia', ':<c-u>ArgonautObject inner<cr>', {noremap = true, silent = true})
vim.keymap.set({'x', 'o'}, 'aa', ':<c-u>ArgonautObject outer<cr>', {noremap = true, silent = true})
vim.keymap.set({'x', 'o', 'n'}, '<leader>n', ':<c-u>ArgonautObject next<cr>', {noremap = true, silent = true})
vim.keymap.set({'x', 'o', 'n'}, '<leader>p', ':<c-u>ArgonautObject previous<cr>', {noremap = true, silent = true})Wraps or unwraps the brace range containing the cursor.
Reformats a brace range according to the active configuration.
Several text objects are supported; an object mode must be passed to this command as an argument.
inner: selects argument text not including the comma and any paddingouter: selects argument text including the comma and any paddingprevious: moves cursor to the previous argumentnext: moves cursor to the next argumentbeginning: moves cursor to the beginning of the argumentend: moves cursor to the end of the argument
Inspect the parsing and picking state for a brace range (development feature).
String and comment detection uses Vim syntax highlighting. Enable syntax highlighting and set the buffer's file type so delimiters inside strings are recognized correctly. Ranges containing comments, malformed nested braces, empty arguments (except a trailing comma), or arguments spanning lines outside nested ranges are left unchanged. Reflow preserves the wrapping of nested ranges.
Run the regression suite from the repository root with Neovim:
./test.sh