nvim: bindings and indent!

This commit is contained in:
Daniel Lundin 2021-04-20 18:10:56 +02:00
parent 301dab336e
commit 781a076b6d
5 changed files with 116 additions and 101 deletions

View file

@ -12,6 +12,7 @@ augroup recompile_plugins
autocmd BufWritePost plugins.lua call <SID>recompile_plugins() autocmd BufWritePost plugins.lua call <SID>recompile_plugins()
augroup END augroup END
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
"" Temporary hacks "" Temporary hacks

View file

@ -3,111 +3,119 @@ local lspconfig = require("lspconfig")
local util = require("lspconfig.util") local util = require("lspconfig.util")
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.handlers["textDocument/publishDiagnostics"] =
vim.lsp.with( vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, vim.lsp.diagnostic.on_publish_diagnostics,
{ {
update_in_insert = false, update_in_insert = false,
virtual_text = {prefix = "‹❮❰ " } virtual_text = {prefix = "‹❮❰ " }
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"LspDiagnosticsSignError", "LspDiagnosticsSignError",
{ {
text = "🔥", text = "🔥",
texthl = "LspDiagnosticsSignError" texthl = "LspDiagnosticsSignError"
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"LspDiagnosticsSignWarning", "LspDiagnosticsSignWarning",
{ {
text = "", text = "",
texthl = "LspDiagnosticsSignWarning" texthl = "LspDiagnosticsSignWarning"
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"LspDiagnosticsSignInformation", "LspDiagnosticsSignInformation",
{ {
text = "💡", text = "💡",
texthl = "LspDiagnosticsSignInformation", texthl = "LspDiagnosticsSignInformation",
} }
) )
vim.fn.sign_define( vim.fn.sign_define(
"LspDiagnosticsSignHint", "LspDiagnosticsSignHint",
{ {
text = "💡", text = "💡",
texthl = "LspDiagnosticsSignHint", texthl = "LspDiagnosticsSignHint",
} }
) )
local on_attach = function() local on_attach = function()
require("folding").on_attach() require("folding").on_attach()
end end
-- simple setups -- -- simple setups --
local servers = { local servers = {
"bashls", "bashls",
"cssls", "cssls",
"dockerls", "dockerls",
"gopls", "gopls",
"html", "html",
"jsonls", "jsonls",
-- "sql", -- "sql",
"sumneko_lua", "sumneko_lua",
"terraformls", "terraformls",
"yamlls", "yamlls",
} }
for _, lsp in ipairs(servers) do for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {on_attach = on_attach} lspconfig[lsp].setup {on_attach = on_attach}
end end
local efm_prettier = { local efm_prettier = {
formatCommand = "prettier --stdin-filepath ${INPUT}", formatCommand = "prettier --stdin-filepath ${INPUT}",
formatStdin = true formatStdin = true
} }
lspconfig.sumneko_lua.setup { lspconfig.sumneko_lua.setup {
cmd = {"lua-language-server", "-E", "/usr/share/lua-language-server/main.lua"}, cmd = {"lua-language-server", "-E", "/usr/share/lua-language-server/main.lua"},
settings = { settings = {
Lua = { Lua = {
completion = {kewordSnippet = "Disable"}, completion = {kewordSnippet = "Disable"},
diagnostics = { diagnostics = {
enable = true, enable = true,
globals = {"renoise", "use", "vim"} globals = {"renoise", "use", "vim"}
}, },
runtime = { runtime = {
version = "LuaJIT", version = "LuaJIT",
path = {"?.lua", "?/init.lua", "?/?.lua"} path = {"?.lua", "?/init.lua", "?/?.lua"}
}, },
workspace = { workspace = {
library = { library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true, [vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true, [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true, [vim.fn.stdpath("config") .. "/lua"] = true,
[vim.fn.stdpath("data") .. "/site/pack"] = true [vim.fn.stdpath("data") .. "/site/pack"] = true
}, },
maxPreload = 2000, maxPreload = 2000,
preloadFileSize = 1000 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 { lspconfig.yamlls.setup {
on_attach = on_attach, settings = {
settings = { yaml = {
yaml = { format = {enable = true, singleQuote = true},
format = {enable = true, singleQuote = true}, schemaStore = {enable = true},
schemaStore = {enable = true}, schemas = {
schemas = { -- ["https://json.schemastore.org/github-workflow"] = "*.github/workflows/*",
["https://json.schemastore.org/github-workflow"] = "*.github/workflows/*", ["https://json.schemastore.org/kustomization.json"] = "kustomization.yaml",
["https://json.schemastore.org/kustomization.json"] = "kustomization.yaml", -- ["https://json.schemastore.org/ansible-role-2.9.json"] = "*/tasks/*.y*ml",
["https://json.schemastore.org/ansible-role-2.9.json"] = "*/tasks/*.y*ml", -- kubernetes = "*.yaml",
["kubernetes" ] = "*.yaml", },
},
validate = true validate = true
} }
} }
} }

View file

@ -3,8 +3,11 @@ require("nvim-treesitter.configs").setup {
highlight = { highlight = {
enable = true, enable = true,
use_languagetree = true, use_languagetree = true,
}, },
indent = {
enable = false
},
playground = { playground = {
enable = true, enable = true,

View file

@ -1,6 +1,6 @@
vim.bo.undofile = true vim.cmd[[set undofile]]
vim.cmd('set completeopt-=preview') vim.cmd[[set completeopt-=preview]]
vim.cmd('set viewoptions-=options') vim.cmd[[set viewoptions-=options]]
vim.g.mapleader = ',' vim.g.mapleader = ','
vim.o.clipboard = 'unnamed' vim.o.clipboard = 'unnamed'
vim.o.hidden = true vim.o.hidden = true
@ -13,7 +13,10 @@ vim.o.updatetime = 100
vim.o.autochdir = true vim.o.autochdir = true
vim.o.backupdir = "/home/dln/.local/share/nvim/backup//" vim.o.backupdir = "/home/dln/.local/share/nvim/backup//"
--- Indent --- Indent
vim.bo.autoindent = true
vim.o.breakindent = true
vim.bo.expandtab = true vim.bo.expandtab = true
vim.bo.smartindent = true vim.bo.smartindent = true
vim.o.joinspaces = false vim.o.joinspaces = false
@ -21,9 +24,9 @@ vim.o.listchars = 'extends:,precedes:,nbsp:·,tab:→ ,trail:·'
vim.wo.foldlevel = 99 vim.wo.foldlevel = 99
vim.wo.linebreak = true vim.wo.linebreak = true
vim.wo.list = true vim.wo.list = true
vim.o.shiftwidth = 2 vim.o.shiftwidth = 4
vim.o.tabstop = 2 vim.o.tabstop = 4
vim.o.softtabstop = 2 vim.o.softtabstop = 4
--- Search --- Search
vim.cmd('set path+=**') vim.cmd('set path+=**')
@ -33,7 +36,7 @@ vim.o.smartcase = true
vim.o.wildmode = 'longest:full,full' vim.o.wildmode = 'longest:full,full'
if vim.fn.executable('rg') then 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 end
--- Completion --- Completion
@ -48,6 +51,7 @@ vim.o.sidescrolloff = 5
vim.o.termguicolors = true vim.o.termguicolors = true
vim.wo.cursorline = true vim.wo.cursorline = true
vim.wo.number = true vim.wo.number = true
vim.wo.signcolumn = "yes"
vim.o.laststatus = 0 vim.o.laststatus = 0
--- Key mappings --- Key mappings
@ -63,23 +67,22 @@ vim.g.netrw_dirhistmax = 0
require('plugins') require('plugins')
-- local border = { '╭', '─' ,'╮', '│', '╯', '─', '╰', '│' }
local border = { '🭽', '' ,'🭾', '', '🭿', '', '🭼', '' } local border = { '🭽', '' ,'🭾', '', '🭿', '', '🭼', '' }
vim.lsp.handlers["textDocument/hover"] = vim.lsp.handlers["textDocument/hover"] =
vim.lsp.with( vim.lsp.with(
vim.lsp.handlers.hover, vim.lsp.handlers.hover,
{ {
border = border border = border
} }
) )
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.handlers["textDocument/signatureHelp"] =
vim.lsp.with( vim.lsp.with(
vim.lsp.handlers.signature_help, vim.lsp.handlers.signature_help,
{ {
border = border border = border
} }
) )
-- vim.cmd [[nnoremap <buffer><silent> <C-space> :lua vim.lsp.diagnostic.show_line_diagnostics({ border = border })<CR>]] -- vim.cmd [[nnoremap <buffer><silent> <C-space> :lua vim.lsp.diagnostic.show_line_diagnostics({ border = border })<CR>]]

View file

@ -42,7 +42,7 @@ return require('packer').startup(function()
end end
end end
utils.mapx("is", "<C-space>", "v:lua.complete('<C-n>', '<Tab>')") utils.mapx("is", "<C-Space>", "v:lua.complete('<C-n>', '<Tab>')")
utils.mapx("is", "<Tab>", "v:lua.complete('<C-n>', '<Tab>')") utils.mapx("is", "<Tab>", "v:lua.complete('<C-n>', '<Tab>')")
utils.mapx("is", "<S-Tab>", "v:lua.complete('<C-p>', '<C-h>')") utils.mapx("is", "<S-Tab>", "v:lua.complete('<C-p>', '<C-h>')")
utils.mapx("x", "<CR>", "compe:#confirm('<CR')") utils.mapx("x", "<CR>", "compe:#confirm('<CR')")
@ -83,7 +83,7 @@ return require('packer').startup(function()
-- vim.g.indent_blankline_show_end_of_line = true -- vim.g.indent_blankline_show_end_of_line = true
vim.g.indent_blankline_show_first_indent_level = true vim.g.indent_blankline_show_first_indent_level = true
vim.g.indent_blankline_show_trailing_blankline_indent = true vim.g.indent_blankline_show_trailing_blankline_indent = true
vim.g.indent_blankline_char_highlight_list = { 'Indent1', 'Indent2', 'Indent3', 'Indent4'} vim.g.indent_blankline_char_highlight_list = { 'Indent1', 'Indent2', 'Indent3', 'Indent4', 'Indent5', 'Indent6'}
end end
} }
@ -99,9 +99,9 @@ return require('packer').startup(function()
map('n', 'rn', '<Cmd>lua vim.lsp.buf.rename()<CR>') map('n', 'rn', '<Cmd>lua vim.lsp.buf.rename()<CR>')
map('n', '[d', '<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>') map('n', '[d', '<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>')
map('n', ']d', '<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>') map('n', ']d', '<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>')
map('n', 'wa', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>') map('n', 'gwa', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
map('n', 'wr', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>') map('n', 'gwr', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
map('n', 'wl', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>') map('n', 'gwl', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
end end
} }