3 ms·
Renaming variables should be done using an LSP, not find/replace. I'd try to avoid using your mouse altogether; because it's faster and for me, avoids neck/sho
by MistaGobo 2y ago
Renaming variables should be done using an LSP, not find/replace.
I'd try to avoid using your mouse altogether; because it's faster and for me, avoids neck/shoulder strain.
Also, I'd recommend oil.nvim which is great for doing file exploration and manipulating. You can edit/move filenames naturally in a vim buffer, and then save to apply changes.
- shmerl 2y agoHow do you rename it with LSP? For now I got to setting up LSP configs and servers for a few languages but didn't get into using it yet besides getting extra syntax highlighting.
- PsyNyde 2y agouse `vim.lsp.buf.rename` to rename using lsp. for example i use `vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)` to rename.
- shmerl 2y agoThanks for the pointer!
- MistaGobo 2y agorequire('lspconfig')['tsserver'].setup{ on_attach = on_attach, ... } local on_attach = function(client, bufnr) vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts) end
- DiabloD3 2y agotry something like: vim.keymap.set('n', 'gr', function() local clients = vim.lsp.get_clients({ bufnr = 0 }) for _, client in ipairs(clients) do if client.server_capabilities.renameProvider then vim.lsp.buf.rename() return end end end)
- goosejuice 2y agoI agree, but not all LSPs support this for what it's worth. For local variables it's not really a big deal, for global references I just find all references and change in each buffer.