NOTE: Currently only works on MacOS & Linux
A Neovim wrapper of crazywall.
Note
crazywall itself is not a requirement, it comes bundled with the plugin.
- neovim 0.9+ (I think)
- A UNIX-based OS
You can install crazywall.nvim with the typical plugin managers.
{
"gitpulljoe/crazywall.nvim",
opts = {
--- add options here
}
}
use {
"gitpulljoe/crazywall.nvim",
config = function ()
require("crazywall").setup()
end
}
You can find example configs in the ./examples/ folder. Below is an example of how you could set up some keybinds for this plugin.
require("crazywall").setup({
configs = {
DEFAULT = { --- some config
}
}
})
vim.api.nvim_set_keymap(
"n",
"<leader>cq",
"<cmd>CrazywallQuick write<CR>",
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"n",
"<leader>cd",
"<cmd>CrazywallDry<CR>",
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"n",
"<leader>cw",
"<cmd>Crazywall<CR>",
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"n",
"<leader>cf",
"<cmd>CrazywallFollowRef<CR>",
{ noremap = true, silent = true }
)
require("crazywall").setup({
--- crazywall configs go here
configs = {
--- See https://github.com/gitpushjoe/crazywall.lua/blob/main/core/defaults/config.lua.
DEFAULT = {}
},
default_config_name = "DEFAULT",
--- See :CrazywallFollowRef
follow_ref = function(line, _column, _config, _config_name)
---@param path string
local file_exists_and_is_not_directory = function(path)
local stat = vim.loop.fs_stat(path)
return stat ~= nil and stat.type == "file"
end
--- Find text within [[]]s.
local match = string.match(line, "%[%[(.-)%]%]")
if not match then
return
end
local current_file_dir = vim.fn.expand("%:p:h")
local extension = '.' .. vim.fn.expand("%:e")
---@param path string
local expand_path = function(path)
return vim.fn.fnamemodify(current_file_dir .. "/" .. path, ":p")
end
---@param path string
local open_path = function(path)
vim.cmd("edit " .. vim.fn.fnameescape(path))
end
for _, path in ipairs({
expand_path(match .. extension),
expand_path(match),
expand_path(match .. "/_index" .. extension),
}) do
if file_exists_and_is_not_directory(path) then
open_path(path)
return
end
end
print(
"Default :CrazywallFollowRef failed. Read the docs to see how you can customize its behavior: https://github.com/gitpulljoe/crazywall.nvim"
)
end
})
Note
<>
-> means required
()
-> means optional
Applies crazywall to a file, with a confirmation window. Use :w
to confirm the action, and :q
to decline.
Equivalent of $ cw {src_path} --out {dest_path} --plan-stream
1
|0
--text-stream
1|0
.
-
output_style
"both"|"planonly"|"textonly"
- Default:
"both"
- Display just the plan information, or just the final text, or both.
-
on_unsaved
"warn"|"write"
- Default:
"warn"
- Emit a warning when the
src_path
is unsaved or automatically write the file, and then continue.
-
src_path
- Default:
vim.fn.expand("%")
(the current file)
- Default:
-
dest_path
- Default:
vim.fn.expand("%")
(the current file)
- Default:
Runs crazywall in dry-run mode on a file.
Equivalent to $ cw --dry-run {src_path} --out {dest_path} --plan-stream
1
|0
--text-stream
1|0
.
-
output_style
"both"|"planonly"|"textonly"
- Default:
"both"
- Display just the plan information, or just the final text, or both.
-
on_unsaved
"warn"|"write"
- Default:
"warn"
- Emit a warning when the
src_path
is unsaved or automatically write the file, and then continue.
-
src_path
- Default:
vim.fn.expand("%")
(the current file)
- Default:
-
dest_path
- Default:
vim.fn.expand("%")
(the current file)
- Default:
Applies crazywall to a file, skipping the confirmation window.
Equivalent to $ cw {src_path} --out {dest_path} --yes
.
-
on_unsaved
"warn"|"write"
- Default:
"warn"
- Emit a warning when the
src_path
is unsaved or automatically write the file, and then continue.
-
src_path
- Default:
vim.fn.expand("%")
(the current file)
- Default:
-
dest_path
- Default:
vim.fn.expand("%")
(the current file)
- Default:
Lists all configs, indicating which one is currently active.
Sets the currently active config to <config_name>
.
Runs follow_ref( line: string, column: integer, config: Config, current_config_name: string )
with the current line
, column
, config
, and current_config_name
. Can be used to navigate to different files from references.
Prints the current crazywall.nvim version and the version of crazywall.lua being used.
Registers a new config with the name name
. If there is already a config with name name
, then the previous one will be overwritten.
--- See https://github.com/gitpushjoe/crazywall.lua/blob/main/core/path.lua
local Path = require("crazywall").Path
--- See https://github.com/gitpushjoe/crazywall.lua/blob/main/core/utils.lua
local utils = require("crazywall").utils
--- See https://github.com/gitpushjoe/crazywall.lua/blob/main/core/context.lua
local Context = require("crazywall").Context
--- See https://github.com/gitpushjoe/crazywall.lua/blob/main/core/section.lua
local Section = require("crazywall").Section
--- See https://github.com/gitpushjoe/crazywall.lua/blob/main/core/config.lua
local Config = require("crazywall").Config
CrazywallPlanHeading
CrazywallTextHeading
CrazywallPlanCreate
CrazywallPlanOverwrite
CrazywallPlanMkdir
CrazywallPlanIgnore
CrazywallPlanRename
CrazywallPlanCreateAction
CrazywallPlanOverwriteAction
CrazywallPlanMkdirAction
CrazywallPlanIgnoreAction
CrazywallPlanRenameAction
CrazywallText
CrazywallError