. . .
at main 82 lines 2.1 kB view raw
1 2local function find_and_replace() 3 vim.ui.input({ prompt = 'Find: ' }, function(find) 4 if not find then return end 5 vim.ui.input({ prompt = 'Replace: ' }, function(replace) 6 if not replace then return end 7 vim.cmd(string.format('%%s/%s/%s/g', 8 vim.fn.escape(find, '/\\'), 9 vim.fn.escape(replace, '/\\'))) 10 end) 11 end) 12end 13 14vim.keymap.set("n", "far", find_and_replace) 15 16vim.defer_fn(function() 17 local pid = vim.fn.getpid() 18 local socket = '/tmp/nvim-' .. pid .. '.socket' 19 vim.fn.serverstart(socket) 20end, 0) 21 22local function fix_menu() 23 local choices = {"spaces", "quotes", "tabs", "all"} 24 vim.ui.select(choices, {prompt = "fix"}, function(choice) 25 if not choice then return end 26 if choice == "spaces" or choice == "all" then 27 vim.cmd("call CleanupWhitespace()") 28 end 29 if choice == "quotes" or choice == "all" then 30 vim.cmd([[:%s/'\([^']*\)'/"\1"/g]]) 31 end 32 if choice == "tabs" or choice == "all" then 33 vim.cmd("set ts=2 sts=2 noet | retab! | set ts=4 sts=4 et | retab") 34 end 35 end) 36end 37 38vim.keymap.set("n", "fix", fix_menu) 39 40--[[ 41 42TODO keybindings for 43 44vim.lsp.buf 45.definition() 46.declaration() 47.implementation() 48.type_definition() 49.references() 50.signature_help() 51.rename() 52.code_action() 53 54vim.diagnostic 55.open_float() 56.goto_prev(), _next() 57 58<C-x><C-o> for completion 59 60 61vim.api.nvim_create_autocmd({"BufEnter"}, 62 { 63 pattern = {"*.rs"}, 64 callback = function(ev) 65 print(vim.fs.dirname(vim.fs.find({'Cargo.toml'}, {upward = true})[1])) 66 vim.lsp.start({ 67 name = 'rust-analyzer', 68 cmd = {'rust-analyzer'}, 69 root_dir = vim.fs.dirname(vim.fs.find({'Cargo.toml'}, {upward = true})[1]), 70 }) 71 72 vim.keymap.set('n', '<leader><leader>', '<cmd>lua vim.lsp.buf.hover()<return>') 73 end 74 }) 75 76require('lsp_lines').setup() 77 78vim.diagnostic.config({ 79 virtual_text = false, 80}) 81]]-- 82