Mercurial > dotfiles
view dot_config/nvim/plugin/filetypo.lua @ 876:8589883596fd
fix: remove pathdirs option to avoid slow path completions
see: https://stackoverflow.com/questions/76746392/why-is-my-zsh-tab-completion-slow-on-commands-but-not-directories
> Perform a path search even on command names with slashes in them.
> Thus if ?/usr/local/bin? is in the user?s path, and he or she types ?X11/xinit?, the command ?/usr/local/bin/X11/xinit? will be executed (assuming it exists).
> Commands explicitly beginning with ?/?, ?./? or ?../? are not subject to the path search. This also applies to the ?.? and source builtins.
author | Zeger Van de Vannet <zeger@vandevan.net> |
---|---|
date | Thu, 25 Apr 2024 10:05:40 +0200 |
parents | 1e6287df57f5 |
children |
line wrap: on
line source
-- Inspired by https://github.com/EinfachToll/DidYouMean/blob/master/plugin/DidYouMean.vim local filetypo = function() if vim.fn.filereadable(vim.fn.expand '%') == 1 then return end local filename = vim.fn.expand '%' local matching_files = vim.fn.split(vim.fn.glob(filename .. '*', 0), '\n') if matching_files == nil or vim.tbl_isempty(matching_files) then matching_files = vim.fn.split(vim.fn.glob(filename .. '*', 1), '\n') end if matching_files == nil or vim.tbl_isempty(matching_files) then return end local buf = vim.api.nvim_get_current_buf() vim.schedule(function() vim.ui.select(matching_files, { prompt = 'Select File:' }, function(choice) vim.cmd.edit(vim.fn.fnameescape(choice)) vim.api.nvim_buf_delete(buf, { force = true }) vim.cmd.doautocmd { 'BufReadPre', mods = { silent = true } } vim.cmd.doautocmd { 'BufRead', mods = { silent = true } } vim.cmd.doautocmd { 'BufReadPost', mods = { silent = true } } vim.cmd.doautocmd { 'TextChanged', mods = { silent = true } } end) end) end vim.api.nvim_create_autocmd('BufNewFile', { pattern = '*', callback = filetypo })