comparison dot_config/nvim/plugin/filetypo.lua @ 624:c0cef1aa4ccd

Replace didyoumean with lua implementation using vim.ui.select
author zegervdv <zegervdv@me.com>
date Mon, 01 Aug 2022 10:26:46 +0200
parents
children 1e6287df57f5
comparison
equal deleted inserted replaced
623:5cceedc51955 624:c0cef1aa4ccd
1 -- Inspired by https://github.com/EinfachToll/DidYouMean/blob/master/plugin/DidYouMean.vim
2
3 local filetypo = function()
4 if vim.fn.filereadable(vim.fn.expand '%') == 1 then return end
5
6 local filename = vim.fn.expand '%'
7 local matching_files = vim.fn.split(vim.fn.glob(filename .. '*', 0), '\n')
8 if matching_files == nil then matching_files = vim.fn.split(vim.fn.glob(filename .. '*', 1), '\n') end
9
10 local buf = vim.api.nvim_get_current_buf()
11 vim.schedule(function()
12 vim.ui.select(matching_files, { prompt = 'Select File:' }, function(choice)
13 vim.cmd.edit(vim.fn.fnameescape(choice))
14 vim.api.nvim_buf_delete(buf, { force = true })
15
16 vim.cmd.doautocmd { 'BufReadPre', mods = { silent = true } }
17 vim.cmd.doautocmd { 'BufRead', mods = { silent = true } }
18 vim.cmd.doautocmd { 'BufReadPost', mods = { silent = true } }
19 vim.cmd.doautocmd { 'TextChanged', mods = { silent = true } }
20 end)
21 end)
22 end
23
24 vim.api.nvim_create_autocmd('BufNewFile', { pattern = '*', callback = filetypo })