fixed formatting in vim

master
Rostyslav Hnatyshyn 2 years ago
parent af1a0beed2
commit 991f7aee59
  1. 23
      nvim/cheatsheet.txt
  2. 54
      nvim/init.lua
  3. 2
      zshrc

@ -0,0 +1,23 @@
## LSP
Get type definition | <space>D
Rename symbol | <space>rn
Code action | <space>ca
Find references | gr
Format file | <space>f
Goto declaration | gD
Goto definition | gd
Toggle hover over symbol | K
Goto implementation | gi
Get signature | <C-k>
Add folder to workspace | <space>wa
Remove folder from workspace | <space>wr
List workspace folders | <space>wl
## Diagnostics
Open diagnostics as floating window | <space>e
Goto next diagnostic | [d
Goto previous diagnostic | ]d
Show diagnostics | <space>q
## Misc
Find in project | <leader>f

@ -59,7 +59,7 @@ nmap("<leader>b", "<cmd>BufferLineCyclePrev<cr>")
nmap("<leader>n", "<cmd>BufferLineCycleNext<cr>")
nmap("<leader>gb", "<cmd>BufferLinePick<cr>")
nmap("<leader>w", "<cmd>bdelete!<cr>")
nmap("<leader>f", "<cmd>Telescope live_grep<cr>")
-- toggle terminal in both modes
nmap("<leader>t", "<cmd>FloatermToggle<cr>")
map("t", "<leader>t", "<cmd>FloatermToggle<cr>")
@ -88,44 +88,28 @@ local on_attach = function(client, bufnr)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
-- won't need format on save if it always works
-- vim.keymap.set('n', '<space>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()
vim.lsp.buf.format({ bufnr = bufnr })
end
})
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

@ -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

Loading…
Cancel
Save