From 781a076b6df4df7d57b39e6c9b417a4193da878d Mon Sep 17 00:00:00 2001 From: Daniel Lundin Date: Tue, 20 Apr 2021 18:10:56 +0200 Subject: [PATCH] nvim: bindings and indent! --- .config/nvim/init.vim | 1 + .config/nvim/lua/dln/lsp-config.lua | 162 +++++++++++++++------------- .config/nvim/lua/dln/treesitter.lua | 5 +- .config/nvim/lua/init.lua | 39 +++---- .config/nvim/lua/plugins.lua | 10 +- 5 files changed, 116 insertions(+), 101 deletions(-) diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 10b0ed6..13b408d 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -12,6 +12,7 @@ augroup recompile_plugins autocmd BufWritePost plugins.lua call recompile_plugins() augroup END +autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab "" Temporary hacks diff --git a/.config/nvim/lua/dln/lsp-config.lua b/.config/nvim/lua/dln/lsp-config.lua index 12dc184..8d0fa14 100644 --- a/.config/nvim/lua/dln/lsp-config.lua +++ b/.config/nvim/lua/dln/lsp-config.lua @@ -3,111 +3,119 @@ local lspconfig = require("lspconfig") local util = require("lspconfig.util") vim.lsp.handlers["textDocument/publishDiagnostics"] = - vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, - { - update_in_insert = false, - virtual_text = {prefix = "‹❮❰ " } - } +vim.lsp.with( +vim.lsp.diagnostic.on_publish_diagnostics, +{ + update_in_insert = false, + virtual_text = {prefix = "‹❮❰ " } +} ) vim.fn.sign_define( - "LspDiagnosticsSignError", - { - text = "🔥", - texthl = "LspDiagnosticsSignError" - } +"LspDiagnosticsSignError", +{ + text = "🔥", + texthl = "LspDiagnosticsSignError" +} ) vim.fn.sign_define( - "LspDiagnosticsSignWarning", - { - text = "⚠", - texthl = "LspDiagnosticsSignWarning" - } +"LspDiagnosticsSignWarning", +{ + text = "⚠", + texthl = "LspDiagnosticsSignWarning" +} ) vim.fn.sign_define( - "LspDiagnosticsSignInformation", - { - text = "💡", - texthl = "LspDiagnosticsSignInformation", - } +"LspDiagnosticsSignInformation", +{ + text = "💡", + texthl = "LspDiagnosticsSignInformation", +} ) vim.fn.sign_define( - "LspDiagnosticsSignHint", - { - text = "💡", - texthl = "LspDiagnosticsSignHint", - } +"LspDiagnosticsSignHint", +{ + text = "💡", + texthl = "LspDiagnosticsSignHint", +} ) local on_attach = function() - require("folding").on_attach() + require("folding").on_attach() end -- simple setups -- local servers = { - "bashls", - "cssls", - "dockerls", - "gopls", - "html", - "jsonls", - -- "sql", - "sumneko_lua", - "terraformls", + "bashls", + "cssls", + "dockerls", + "gopls", + "html", + "jsonls", + -- "sql", + "sumneko_lua", + "terraformls", "yamlls", } for _, lsp in ipairs(servers) do - lspconfig[lsp].setup {on_attach = on_attach} + lspconfig[lsp].setup {on_attach = on_attach} end local efm_prettier = { - formatCommand = "prettier --stdin-filepath ${INPUT}", - formatStdin = true + formatCommand = "prettier --stdin-filepath ${INPUT}", + formatStdin = true } lspconfig.sumneko_lua.setup { - cmd = {"lua-language-server", "-E", "/usr/share/lua-language-server/main.lua"}, - settings = { - Lua = { - completion = {kewordSnippet = "Disable"}, - diagnostics = { - enable = true, - globals = {"renoise", "use", "vim"} - }, - runtime = { - version = "LuaJIT", - path = {"?.lua", "?/init.lua", "?/?.lua"} - }, - workspace = { - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, - [vim.fn.stdpath("data") .. "/site/pack"] = true - }, - maxPreload = 2000, - preloadFileSize = 1000 - } - } - } + cmd = {"lua-language-server", "-E", "/usr/share/lua-language-server/main.lua"}, + settings = { + Lua = { + completion = {kewordSnippet = "Disable"}, + diagnostics = { + enable = true, + globals = {"renoise", "use", "vim"} + }, + runtime = { + version = "LuaJIT", + path = {"?.lua", "?/init.lua", "?/?.lua"} + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + [vim.fn.stdpath("data") .. "/site/pack"] = true + }, + maxPreload = 2000, + preloadFileSize = 1000 + } + } + } } +local yaml_is_k8s = function(bufnr) + local lines = vim.api.nvim_buf_get_lines(bufnr, 0, 50, false) -- Stop after the first 50 lines + for _, l in pairs(lines) do + if string.find(l, "apiVersion") ~= nil then return true end + end + return false +end + lspconfig.yamlls.setup { - on_attach = on_attach, - settings = { - yaml = { - format = {enable = true, singleQuote = true}, - schemaStore = {enable = true}, - schemas = { - ["https://json.schemastore.org/github-workflow"] = "*.github/workflows/*", - ["https://json.schemastore.org/kustomization.json"] = "kustomization.yaml", - ["https://json.schemastore.org/ansible-role-2.9.json"] = "*/tasks/*.y*ml", - ["kubernetes" ] = "*.yaml", - }, - validate = true - } - } + settings = { + yaml = { + format = {enable = true, singleQuote = true}, + schemaStore = {enable = true}, + schemas = { + -- ["https://json.schemastore.org/github-workflow"] = "*.github/workflows/*", + ["https://json.schemastore.org/kustomization.json"] = "kustomization.yaml", + -- ["https://json.schemastore.org/ansible-role-2.9.json"] = "*/tasks/*.y*ml", + -- kubernetes = "*.yaml", + }, + + validate = true + } + } } diff --git a/.config/nvim/lua/dln/treesitter.lua b/.config/nvim/lua/dln/treesitter.lua index 36fdc1e..382c669 100644 --- a/.config/nvim/lua/dln/treesitter.lua +++ b/.config/nvim/lua/dln/treesitter.lua @@ -3,8 +3,11 @@ require("nvim-treesitter.configs").setup { highlight = { enable = true, use_languagetree = true, -}, + }, + indent = { + enable = false + }, playground = { enable = true, diff --git a/.config/nvim/lua/init.lua b/.config/nvim/lua/init.lua index d9e4227..ab3ec22 100644 --- a/.config/nvim/lua/init.lua +++ b/.config/nvim/lua/init.lua @@ -1,6 +1,6 @@ -vim.bo.undofile = true -vim.cmd('set completeopt-=preview') -vim.cmd('set viewoptions-=options') +vim.cmd[[set undofile]] +vim.cmd[[set completeopt-=preview]] +vim.cmd[[set viewoptions-=options]] vim.g.mapleader = ',' vim.o.clipboard = 'unnamed' vim.o.hidden = true @@ -13,7 +13,10 @@ vim.o.updatetime = 100 vim.o.autochdir = true vim.o.backupdir = "/home/dln/.local/share/nvim/backup//" + --- Indent +vim.bo.autoindent = true +vim.o.breakindent = true vim.bo.expandtab = true vim.bo.smartindent = true vim.o.joinspaces = false @@ -21,9 +24,9 @@ vim.o.listchars = 'extends:›,precedes:‹,nbsp:·,tab:→ ,trail:·' vim.wo.foldlevel = 99 vim.wo.linebreak = true vim.wo.list = true -vim.o.shiftwidth = 2 -vim.o.tabstop = 2 -vim.o.softtabstop = 2 +vim.o.shiftwidth = 4 +vim.o.tabstop = 4 +vim.o.softtabstop = 4 --- Search vim.cmd('set path+=**') @@ -33,7 +36,7 @@ vim.o.smartcase = true vim.o.wildmode = 'longest:full,full' if vim.fn.executable('rg') then - vim.o.grepprg = 'rg --vimgrep --no-heading --smart-case' + vim.o.grepprg = 'rg --vimgrep --no-heading --smart-case' end --- Completion @@ -48,6 +51,7 @@ vim.o.sidescrolloff = 5 vim.o.termguicolors = true vim.wo.cursorline = true vim.wo.number = true +vim.wo.signcolumn = "yes" vim.o.laststatus = 0 --- Key mappings @@ -63,23 +67,22 @@ vim.g.netrw_dirhistmax = 0 require('plugins') --- local border = { '╭', '─' ,'╮', '│', '╯', '─', '╰', '│' } local border = { '🭽', '▔' ,'🭾', '▕', '🭿', '▂', '🭼', '▏' } vim.lsp.handlers["textDocument/hover"] = - vim.lsp.with( - vim.lsp.handlers.hover, - { - border = border - } +vim.lsp.with( +vim.lsp.handlers.hover, +{ + border = border +} ) vim.lsp.handlers["textDocument/signatureHelp"] = - vim.lsp.with( - vim.lsp.handlers.signature_help, - { - border = border - } +vim.lsp.with( +vim.lsp.handlers.signature_help, +{ + border = border +} ) -- vim.cmd [[nnoremap :lua vim.lsp.diagnostic.show_line_diagnostics({ border = border })]] diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 31cd533..adc7eb9 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -42,7 +42,7 @@ return require('packer').startup(function() end end - utils.mapx("is", "", "v:lua.complete('', '')") + utils.mapx("is", "", "v:lua.complete('', '')") utils.mapx("is", "", "v:lua.complete('', '')") utils.mapx("is", "", "v:lua.complete('', '')") utils.mapx("x", "", "compe:#confirm('lua vim.lsp.buf.rename()') map('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()') map('n', ']d', 'lua vim.lsp.diagnostic.goto_next()') - map('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()') - map('n', 'wr', 'lua vim.lsp.buf.add_workspace_folder()') - map('n', 'wl', 'lua vim.lsp.buf.add_workspace_folder()') + map('n', 'gwa', 'lua vim.lsp.buf.add_workspace_folder()') + map('n', 'gwr', 'lua vim.lsp.buf.add_workspace_folder()') + map('n', 'gwl', 'lua vim.lsp.buf.add_workspace_folder()') end }