Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
165 lines (155 loc) · 8.31 KB
/
Copy pathinit.lua
File metadata and controls
165 lines (155 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
-- ┌──────────────────────────┐
-- │ Welcome to this Neovim │
-- │ config (born of MiniMax) │
-- └──────────────────────────┘
--
-- This is a config designed to mostly use MINI. It provides out of the box
-- a stable, polished, and feature rich Neovim experience. Its structure:
--
-- ├ init.lua Initial (this) file executed during startup
-- ├ plugin/ Files automatically sourced during startup
-- ├── 10_options.lua Built-in Neovim behavior
-- ├── 20_keymaps.lua Custom mappings
-- ├── 30_mini.lua MINI configuration
-- ├── 40_plugins.lua Plugins outside of MINI
-- ├ snippets/ User defined snippets (has demo file)
-- ├ after/ Files to override behavior added by plugins
-- ├── ftplugin/ Files for filetype behavior (has demo file)
-- ├── lsp/ Language server configurations (has demo file)
-- ├── snippets/ Higher priority snippet files (has demo file)
--
-- Config files are meant to be read, preferably inside a Neovim instance running
-- this config and opened at its root. This will help you better understand your
-- setup. Start with this file. Any order is possible, prefer the one listed above.
-- Ways of navigating your config:
-- - `<Space>` + `e` + (one of) `iokmp` - edit 'init.lua' or 'plugin/' files.
-- - Inside config directory: `<Space>ff` (picker) or `<Space>ed` (explorer)
-- - Navigate existing buffers with `[b`, `]b`, or `<Space>fb`.
--
-- Config files are also meant to be customized. Initially it is a baseline of
-- a working config based on MINI. Modify it to make it yours. Some approaches:
-- - Modify already existing files in a way that keeps them consistent.
-- - Add new files in a way that keeps config consistent.
-- Usually inside 'plugin/' or 'after/'.
--
-- Documentation comments like this can be found throughout the config.
-- Common conventions:
--
-- - See `:h key-notation` for key notation used.
-- - `:h xxx` means "documentation of helptag xxx". Either type text directly
-- followed by Enter or type `<Space>fh` to open a helptag fuzzy picker.
-- - "Type `<Space>fh`" means "press <Space>, followed by f, followed by h".
-- Unless said otherwise, it assumes that Normal mode is current.
-- - "See 'path/to/file'" means see open file at described path and read it.
-- - `:SomeCommand ...` or `:lua ...` means execute mentioned command.
-- ┌────────────────┐
-- │ Plugin manager │
-- └────────────────┘
--
-- This config uses `vim.pack` - built-in plugin manager. Its main entry
-- point is a `vim.pack.add()` function, which acts like a "smarter `:packadd`":
-- load plugin after making sure it is installed from source. The state of
-- installed plugins is recorded in the lockfile named 'nvim-pack-lock.json'.
-- Example usage:
-- - `vim.pack.add({ ... })` - use inside config to add one or more plugins.
-- - `:lua vim.pack.update()` - update all plugins; execute `:write` to confirm.
-- - `:lua vim.pack.del({ ... })` - delete specific plugins.
--
-- See also:
-- - `:h vim.pack-examples` - how to use it
-- - `:h vim.pack-lockfile` - lockfile info
-- - `:h vim.pack-events` - available events and plugin hooks examples
-- - `:h vim.pack.update()` - more details about confirmation step
-- Define config table to be able to pass data between scripts
-- It is a global variable which can be use both as `_G.Config` and `Config`
_G.Config = {}
-- Define custom autocommand group and helper to create an autocommand.
-- Autocommands are Neovim's way to define actions that are executed on events
-- (like creating a buffer, setting an option, etc.).
--
-- See also:
-- - `:h autocommand`
-- - `:h nvim_create_augroup()`
-- - `:h nvim_create_autocmd()`
local gr = vim.api.nvim_create_augroup('custom-config', { clear = true })
Config.new_autocmd = function(event, pattern, callback, desc)
local opts = { group = gr, pattern = pattern, callback = callback, desc = desc }
vim.api.nvim_create_autocmd(event, opts)
end
-- Define custom `vim.pack.add()` hook helper. Plugin data is passed as
-- argument to the callback. See `:h vim.pack-events`.
-- Example usage: see 'plugin/40_plugins.lua'.
-- If any plugin requires installation hooks, add them after this function
-- and before the first `vim.pack.add()` call.
Config.on_packchanged = function(plugin_name, kinds, callback, desc)
local f = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
if not (name == plugin_name and vim.tbl_contains(kinds, kind)) then return end
if not ev.data.active then vim.cmd.packadd(plugin_name) end
callback(ev.data)
end
Config.new_autocmd('PackChanged', '*', f, desc)
end
-- 'mini.nvim' - all-in-one plugin powering most of this config's features.
-- See 'plugin/30_mini.lua' for how it is used.
-- Load now to have 'mini.misc' available for custom loading helpers.
vim.pack.add({ 'https://github.com/nvim-mini/mini.nvim' })
-- Loading helpers used to organize config into fail-safe parts. Example usage:
-- - `now` - execute immediately. Use for what must be executed during startup.
-- Like colorscheme, statusline, tabline, dashboard, etc.
-- - `later` - execute a bit later. Use for things not needed during startup.
-- - `now_if_args` - use only if needed during startup when Neovim is started
-- like `nvim -- path/to/file`, but otherwise delaying is fine.
-- - Others are better used only if the above is not enough for good performance.
-- Use only if you are comfortable with adding complexity to your config:
-- - `on_event` - execute once on a first matched event. Like "delay until
-- first Insert mode enter": `on_event('InsertEnter', function() ... end)`.
-- - `on_filetype` - execute once on a first matched filetype. Like "delay
-- until first Lua file": `on_filetype('lua', function() ... end)`.
--
-- See also:
-- - `:h MiniMisc.safely()`
-- - 'plugin/30_mini.lua' and 'plugin/40_plugins.lua'
local misc = require('mini.misc')
Config.now = function(f) misc.safely('now', f) end
Config.later = function(f) misc.safely('later', f) end
Config.now_if_args = vim.fn.argc(-1) > 0 and Config.now or Config.later
Config.on_event = function(ev, f) misc.safely('event:' .. ev, f) end
Config.on_filetype = function(ft, f) misc.safely('filetype:' .. ft, f) end
-- HACK: a snapshot of the global default of `'path'`, taken before any
-- buffer can write it. `plugin/41_git.lua` and `after/ftplugin/c.lua` both
-- prepend project directories to it, and both need the value that was there
-- BEFORE - but the FIRST write to a never-locally-set global-local string
-- option like `'path'`, from ANY scope (`vim.bo`, `vim.opt_local`, even
-- `:setlocal`), overwrites Neovim's own compiled-in GLOBAL default too
-- (measured: `vim.o.path` reads the written value afterwards, in a buffer
-- that never touched it). Reading `vim.o.path` a second time then reads
-- back what the first write already corrupted it to, so the entries grow
-- without bound across repeated `:setf`/buffer opens. Present in Neovim
-- 0.12.5; remove if a future release stops promoting a local write into the
-- global slot.
Config.pristine_path = vim.o.path
-- Ask a yes/no question and run `on_yes` only on a clear 'y'. Used by any
-- part of the config that needs permission before acting, so the prompt shape
-- and the predicate live in one place.
Config.confirm = function(prompt, on_yes)
vim.ui.input({ prompt = prompt .. ' (y/n) ' }, function(answer)
if (answer or ''):lower() == 'y' then on_yes() end
end)
end
-- Report how many items of a batch operation succeeded and how many failed,
-- picking the notification level from the failure count. Used by review close,
-- review open and any future bulk operation that needs a single summary.
-- The two labels are required, not defaulted: what is 1 item of the batch is a
-- file when opening a review and a buffer when closing one, so a generic
-- default would read as a wrong count rather than as a missing argument.
Config.report = function(message, done, failed, done_label, failed_label)
local msg = message .. ': ' .. done .. ' ' .. done_label
local level = vim.log.levels.INFO
if failed > 0 then
msg = msg .. ', ' .. failed .. ' ' .. failed_label
level = vim.log.levels.WARN
end
vim.notify(msg, level)
end
vim.o.exrc = true