-- commands.lua vim.cmd 'autocmd BufRead,BufNewFile *.wiki,*.md,*.tex set wrap' vim.cmd 'au BufRead,BufNewFile *.kdl set filetype=kdl' vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.format()]] -- I don't know why but whenever I accidentally type :W instead of :w, I slows down the ide and reverts all changes -- It doesn't even save files with sudo... -- vim.cmd 'command W :execute \':silent w !sudo tee % > /dev/null\' | :edit!' -- Array of file names indicating root directory. Modify to your liking. local root_names = { '.git', 'Makefile', 'justfile', 'CMakeLists.txt', 'maskfile.md' } -- Cache to use for speed up (at cost of possibly outdated results) local root_cache = {} local set_root = function() -- Get directory path to start search from local path = vim.api.nvim_buf_get_name(0) if path == '' then return end path = vim.fs.dirname(path) -- Try cache and resort to searching upward for root directory local root = root_cache[path] if root == nil then local root_file = vim.fs.find(root_names, { path = path, upward = true })[1] if root_file == nil then return end root = vim.fs.dirname(root_file) root_cache[path] = root end -- Set current directory vim.fn.chdir(root) end local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {}) vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root }) local function set_makeprg() local cwd = vim.fn.getcwd() if vim.fn.filereadable(cwd .. '/justfile') == 1 then vim.o.makeprg = 'just' elseif vim.fn.filereadable(cwd .. '/Makefile') == 1 then vim.o.makeprg = 'make' elseif vim.fn.filereadable(cwd .. '/maskfile.md') == 1 then vim.o.makeprg = 'mask' end end local makeprg_augroup = vim.api.nvim_create_augroup('MyMakeprg', {}) vim.api.nvim_create_autocmd('BufEnter', { pattern = '*', group = makeprg_augroup, callback = set_makeprg, }) vim.api.nvim_create_autocmd("BufRead", { pattern = "*.ui", callback = function(args) local designer_path = "/home/schmidtf/Qt/6.10.0/gcc_64/bin/designer" local filename = vim.fn.expand(":p") -- Check if Qt Designer is available if vim.fn.executable(designer_path) == 0 then vim.notify("Qt Designer not found in PATH", vim.log.levels.WARN) return end -- Open in Qt Designer and close the buffer vim.fn.jobstart({ designer_path, filename }, { detach = true, on_exit = function() vim.schedule(function() vim.cmd("bd!") end) end }) vim.notify("Opening " .. filename .. " in Qt Designer") end })