robin/artio.nvim

minimal ui2 fuzzy finder for Neovim

git clone https://git.robinwobin.dev/robin/artio.nvim

robinfeat!: collapse qflist actions into one8fb9b8a

main
10.7 KiB349 linesraw
1*artio.txt*	a minimal, nature-infused file picker for neovim using ui2
2
3==============================================================================
4
5FEATURES                                                      *artio-features*
6
7Requires Neovim `>= 0.12`
8
9- Lightweight picker window built on Neovim's ui2
10- Prompt + list UI components - minimal and focused
11- Fuzzy filtering using matchfuzzy (built-in)
12- Optional icon support for common filetypes through mini.icons
13  (https://github.com/echasnovski/mini.nvim)
14- No heavy dependencies - pure Lua
15
16UI2
17
18artio requires ui2 to be enabled.
19
20an example of how to set this up is:
21
22>lua
23  require("vim._core.ui2").enable({ enable = true, msg = {
24    target = "msg",
25  } })
26<
27
28INSTALLATION
29
30`vim.pack`
31
32>lua
33  vim.pack.add({{ src = "https://github.com/comfysage/artio.nvim" }})
34<
35
36`lazy.nvim`
37
38>lua
39  {
40    "comfysage/artio.nvim", lazy = false,
41  }
42<
43
44==============================================================================
45
46CONFIGURATION                                                   *artio-config*
47
48Options ~
49
50options that change default behavior of the picker.
51
52>lua
53  {
54    opts = {
55      preselect = true, -- whether to preselect the first match
56      bottom = true, -- whether to draw the prompt at the bottom
57      shrink = true, -- whether the window should shrink to fit the matches
58      promptprefix = "", -- prefix for the prompt
59      prompt_title = true, -- whether to draw the prompt title
60      pointer = "", -- pointer for the selected match
61      marker = "│", -- prefix for marked items
62      infolist = { "list" }, -- index: [1] list: (4/5)
63      use_icons = true, -- requires mini.icons
64    },
65  }
66<
67
68Window Options ~
69
70some less used options for the picker window and its render logic.
71
72>lua
73  {
74    win = {
75      height = 12,
76      hidestatusline = false, -- works best with laststatus=3
77    },
78  }
79<
80
81Mappings ~
82
83these override the default mappings for any picker.
84these map keys to actions. its allowed to use multiple keys for the same
85action.
86
87NOTE: if you override the mappings, make sure to provide keys for all actions
88
89>lua
90  {
91    mappings = {
92      ["<down>"] = "down",
93      ["<up>"] = "up",
94      ["<cr>"] = "accept",
95      ["<esc>"] = "cancel",
96      ["<tab>"] = "mark",
97      ["<c-l>"] = "togglepreview",
98      ["<c-q>"] = "setqflist",
99    },
100  }
101<
102
103Setup ~
104
105after setting up artio with your options there are some additional things to
106setup.
107
108Keymaps for artio are set using the |<Plug>| interface. These bindings are set
109by the api and can be rebound by the user to specific keybindings.
110
111By default there are <Plug> bindings for all builtins. |artio-builtins|
112
113Example ~
114
115>lua
116  require('artio').setup({})
117
118  -- override built-in ui select with artio
119  vim.ui.select = require("artio").select
120
121  vim.keymap.set("n", "<leader><leader>", "<Plug>(artio-files)")
122  vim.keymap.set("n", "<leader>fg", "<Plug>(artio-grep)")
123
124  -- smart file picker
125  vim.keymap.set("n", "<leader>ff", "<Plug>(artio-smart)")
126
127  -- general built-in pickers
128  vim.keymap.set("n", "<leader>fh", "<Plug>(artio-helptags)")
129  vim.keymap.set("n", "<leader>fb", "<Plug>(artio-buffers)")
130  vim.keymap.set("n", "<leader>f/", "<Plug>(artio-buffergrep)")
131  vim.keymap.set("n", "<leader>fo", "<Plug>(artio-oldfiles)")
132<
133
134==============================================================================
135
136API                                                                *artio-api*
137
138artio.pick({opts})                                              *artio.pick()*
139
140  create a new picker |artio.Picker| and start it.
141
142  >lua
143    artio.pick({
144      items = { 'a', 'b', 'c' },
145      fn = artio.sorter,
146    })
147  <
148
149artio.generic({items}, {props})                              *artio.generic()*
150
151  creates a generic picker from the given items and props.
152  uses the default |artio.sorter| function.
153
154                                                              *artio.select()*
155artio.select({items}, {opts}, {on_choice}, {start_opts?})
156
157  the |vim.ui.select| interface implemented for artio.
158  adds an optional `{start_opts?}` argument that accepts artio specific
159  options.
160
161artio.resume()                                                *artio.resume()*
162
163  resume the last closed picker. does not work across neovim
164  restarts/sessions.
165
166  Plug: `<Plug>(artio-resume)`.
167
168API-PICKER                                                  *artio-api-picker*
169
170*artio.Picker*
171  a picker is a special table that holds the state of the picker.
172  the current active picker is stored in
173  `require('artio.picker').active_picker`.
174
175  Fields: ~
176    - {items}           (`artio.Picker.item[]|string[]`)
177                        array of |artio.Picker.item| or strings. an array of
178                        strings will be converted to items.
179    - {fn}              (`artio.Picker.sorter`)
180                        an instance of |artio.Picker.sorter|.
181    - {on_close}        (`fun(text: string, idx: integer)`)
182                        callback function for when the picker closes (after
183                        accepting a match). gets the `item.text` field as the
184                        first argument and the item id as the second.
185    - {get_items}?      (`fun(input: string): artio.Picker.item[]`)
186    - {format_item}?    (`fun(item: any): string`)
187    - {preview_item}?   (`fun(item: any): {buf?:integer, pos?:[integer,integer], pos_end?:[integer,integer]}`)
188    - {get_icon}?       (`fun(item: artio.Picker.item): string, string`)
189    - {hl_item}?        (`fun(item: artio.Picker.item): artio.Picker.hl[]`)
190    - {on_quit}?        (`fun()`)
191                        callback function for when the picker closes before
192                        choosing a match.
193    - {prompt}?         (`string`)
194                        text before prompt prefix. can be disabled with
195                        `config.opts.prompt_title = false`.
196    - {defaulttext}?    (`string`)
197                        start input for picker.
198    - {prompttext}?     (`string`)
199                        defaults to prompt title combined with prompt prefix.
200    - {opts}?           (`artio.config.opts`)
201                        picker options combined with the user config.
202    - {win}?            (`artio.config.win`)
203                        picker window options combined with the user config.
204    - {actions}?        (`table<string, artio.Picker.action>`)
205                        picker specific actions.
206    - {mappings}?       (`table<string, string>`)
207                        mappings from the user config.
208
209API-SORTER                                                  *artio-api-sorter*
210
211*artio.Picker.sorter*
212   a function that takes an array of |artio.Picker.item| and an input string
213   and returns a table of matches |artio.Picker.matches|.
214
215*artio.Picker.matches*
216  a table where each key is the id of the item and each value is of
217  |artio.Picker.match|.
218
219*artio.Picker.match*
220
221  Fields: ~
222    - {1}       (`integer`)
223                id of the item
224    - {2}       (`any`)
225                array of ' matching ' hls. these correspond to chars of the
226                `item.text` field. this is based on the output of
227                |matchfuzzypos|.
228    - {3}       (`integer`)
229                the score of the match.
230
231*artio.Picker.item*
232
233  Fields: ~
234    - {id}      (`integer`)
235    - {v}       (`any`)
236    - {text}    (`string`)
237
238artio.sorter({items}, {input})                                *artio.sorter()*
239
240  the default sorter provides support for pattern matching. a `/.../` match at
241  the start of the input will limit the fuzzy sorter to items matching the
242  pattern. if you want to use `/.../` in your fuzzy matches, make sure to
243  escape it by starting the input with an empty space (` /.../`). fuzzy
244  sorting will be done on the input with the pattern removed.
245
246API-BUILTINS
247
248artio builtins are for general editor use. they are accessible through
249`require('artio.builtins')`.
250
251builtins.builtins()                                           *artio-builtins*
252
253  list of all builtins.
254
255  Plug: `<Plug>(artio-builtins)`.
256
257builtins.files()                                                 *artio-files*
258
259  list all files within the current directory.
260
261  Plug: `<Plug>(artio-files)`.
262
263builtins.grep()                                                   *artio-grep*
264
265  grep in the current directory.
266  runs `rg` if available; uses `grep` as a fallback.
267
268  Plug: `<Plug>(artio-grep)`.
269
270builtins.oldfiles()                                           *artio-oldfiles*
271
272  list all files in |v:oldfiles|; recently accessed files in neovim. these are
273  stored in |shada| memory.
274
275  Plug: `<Plug>(artio-oldfiles)`.
276
277builtins.buffergrep()                                       *artio-buffergrep*
278
279  grep in the current buffer. uses the default sorter to match lines.
280
281  Plug: `<Plug>(artio-buffergrep)`.
282
283builtins.helptags()                                           *artio-helptags*
284
285  list all help tags. behaves like |:help|.
286
287  Plug: `<Plug>(artio-helptags)`.
288
289builtins.buffers()                                             *artio-buffers*
290
291  list all open buffers. behaves like |:buffers|.
292
293  Plug: `<Plug>(artio-buffers)`.
294
295builtins.smart()                                                 *artio-smart*
296
297  uses the regular files picker as a base
298  - boosts items in the bufferlist
299  - proportionally boosts items that match closely to the current file in
300    proximity within the filesystem
301
302  Plug: `<Plug>(artio-smart)`.
303
304builtins.colorschemes()                                   *artio-colorschemes*
305
306  list all colorschemes by finding all `colors/*.{vim,lua}` files in the
307  runtime.
308
309  Plug: `<Plug>(artio-colorschemes)`.
310
311builtins.highlights()                                       *artio-highlights*
312
313  list all highlights. behaves like |:highlight|.
314
315  Plug: `<Plug>(artio-highlights)`.
316
317builtins.diagnostics({buffer})                             *artio-diagnostics*
318
319  list all diagnostics. uses diagnostics from |vim.diagnostic.get()|.
320  uses all diagnostics in the workspace if no buffer is specified.
321
322  Plug: `<Plug>(artio-diagnostics)`.
323
324builtins.diagnostics_buffer({buffer})               *artio-diagnostics-buffer*
325
326  list all diagnostics for the given buffer. uses diagnostics from
327  |vim.diagnostic.get()|. uses the current buffer if no buffer is specified.
328
329  Plug: `<Plug>(artio-diagnostics-buffer)`.
330
331builtins.keymaps()                                             *artio-keymaps*
332
333  list all keymaps. uses formatted data from |nvim_get_keymap()|.
334
335  Plug: `<Plug>(artio-keymaps)`.
336
337builtins.commands()                                           *artio-commands*
338
339  list all user commands. uses formatted data from |nvim_get_commands()|.
340
341  Plug: `<Plug>(artio-commands)`.
342
343builtins.quickfix()                                           *artio-quickfix*
344
345  show current quickfix list. allows previewing items and updating the list.
346
347  Plug: `<Plug>(artio-quickfix)`.
348
349 vim:tw=78:ts=8:noet:ft=help:norl: