From 991f7aee59db9b173e63bd74a6d4c2698a0b2e4b Mon Sep 17 00:00:00 2001 From: Rostyslav Hnatyshyn Date: Tue, 15 Nov 2022 10:51:28 -0700 Subject: [PATCH] fixed formatting in vim --- nvim/cheatsheet.txt | 23 ++++++++++++++++ nvim/init.lua | 66 ++++++++++++++++++++++++++------------------- zshrc | 2 +- 3 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 nvim/cheatsheet.txt diff --git a/nvim/cheatsheet.txt b/nvim/cheatsheet.txt new file mode 100644 index 0000000..af442c3 --- /dev/null +++ b/nvim/cheatsheet.txt @@ -0,0 +1,23 @@ +## LSP +Get type definition | D +Rename symbol | rn +Code action | ca +Find references | gr +Format file | f +Goto declaration | gD +Goto definition | gd +Toggle hover over symbol | K +Goto implementation | gi +Get signature | +Add folder to workspace | wa +Remove folder from workspace | wr +List workspace folders | wl + +## Diagnostics +Open diagnostics as floating window | e +Goto next diagnostic | [d +Goto previous diagnostic | ]d +Show diagnostics | q + +## Misc +Find in project | f diff --git a/nvim/init.lua b/nvim/init.lua index 7f4d71e..d83471b 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -59,7 +59,7 @@ nmap("b", "BufferLineCyclePrev") nmap("n", "BufferLineCycleNext") nmap("gb", "BufferLinePick") nmap("w", "bdelete!") - +nmap("f", "Telescope live_grep") -- toggle terminal in both modes nmap("t", "FloatermToggle") map("t", "t", "FloatermToggle") @@ -88,44 +88,28 @@ local on_attach = function(client, bufnr) vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', 'f', vim.lsp.buf.formatting, bufopts) + -- won't need format on save if it always works + -- vim.keymap.set('n', 'f', vim.lsp.buf.formatting, bufopts) require "coq".lsp_ensure_capabilities {} require 'illuminate'.on_attach(client) -- format on save if client.supports_method("textDocument/formatting") then - - -- get filetype - local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") - -- get null-ls supported sources - local available = require "null-ls.sources".get_available(filetype, require("null-ls").methods.FORMATTING) - - local enable = false - if #available > 0 then - enable = client.name == "null-ls" - else - enable = not (client.name == "null-ls") - end - - client.resolved_capabilities.document_formatting = enable - client.resolved_capabilities.document_range_formatting = enable - - if client.resolved_capabilities.document_formatting then - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.formatting_sync() - end - }) - end + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end + }) end end -- lsp config setup local lsp = require "lspconfig" lsp.hls.setup { on_attach = on_attach } -- haskell language server +lsp.ccls.setup { on_attach = on_attach } lsp.pyright.setup { on_attach = on_attach } lsp.tsserver.setup { on_attach = on_attach } lsp.rust_analyzer.setup { on_attach = on_attach } @@ -187,11 +171,29 @@ return require('packer').startup(function(use) use { 'jose-elias-alvarez/null-ls.nvim', config = function() require('null-ls').setup({ + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + -- overwrites format on save if null-ls is loaded + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr, filter = function(client) + return client.name == "null-ls" + end + }) + end + }) + end + end, sources = { require('null-ls').builtins.formatting.eslint_d, require('null-ls').builtins.diagnostics.eslint_d, require("null-ls").builtins.code_actions.eslint_d, - require("null-ls").builtins.formatting.black + require("null-ls").builtins.diagnostics.flake8, + require("null-ls").builtins.formatting.black, + require("null-ls").builtins.code_actions.gitsigns } }) end, @@ -266,6 +268,14 @@ return require('packer').startup(function(use) require('gitsigns').setup() end } + use { + 'sudormrfbin/cheatsheet.nvim', + requires = { + { 'nvim-telescope/telescope.nvim' }, + { 'nvim-lua/popup.nvim' }, + { 'nvim-lua/plenary.nvim' }, + } + } if packer_bootstrap then require('packer').sync() end diff --git a/zshrc b/zshrc index e23c29b..8d63a34 100644 --- a/zshrc +++ b/zshrc @@ -34,7 +34,7 @@ alias ucpserver='/home/frosty/Programs/Rust/UnifiedCopyPaste/target/debug/server alias fixWifi='sudo rmmod iwlmvm; sudo rmmod iwlwifi; sudo modprobe iwlmvm; sudo modprobe iwlwifi' alias weather='curl wttr.in' alias sshLANL='ssh -t -l rhnatyshyn wtrw.lanl.gov ssh ch-fe.lanl.gov' - +alias vim='nvim' function tunnelLANL() { if [ -n "$1" ] then