Jochen Sprickerhof
Last changed: 2022-07-02

Software

Vim Config

require("gitsigns").setup {}
require("lsp_signature").setup {}
require("spellsitter").setup {}
local cmp = require("cmp")
cmp.setup {
  mapping = cmp.mapping.preset.insert({["<CR>"] = cmp.mapping.confirm()}),
  sources = {
    {name = "nvim_lsp"},
    {name = "buffer", options = {keyword_pattern = [[\k\+]]}},
    {name = "path"},
    {name = "latex_symbols"},
    {name = "emoji"}
  }
}

local lspconfig = require("lspconfig")
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
capabilities.textDocument.completion.completionItem.snippetSupport = false
lspconfig.clangd.setup {capabilities = capabilities}
lspconfig.pylsp.setup {
  capabilities = capabilities,
  settings = {pylsp = {plugins = {
    pyflakes = {enabled = false},
    mccabe = {enabled = false},
    pycodestyle = {enabled = false},
    flake8 = {enabled = true, ignore = {"E501", "W503"}},
    pylint = {enabled = true, executable = "pylint", args = {"-d C0114,C0115,C0116"}},
  }}}
}
lspconfig.efm.setup {filetypes = {"cmake", "json", "markdown", "rst", "sh", "tex", "yaml"}}
local function goto_definition()
  return function(_, result, ctx)
    if result == nil or vim.tbl_isempty(result) then
      return
    end
    vim.cmd("vsplit")
    vim.cmd("wincmd p")
    if vim.tbl_islist(result) then
      vim.lsp.util.jump_to_location(result[1])
      if #result > 1 then
        vim.lsp.util.set_qflist(vim.lsp.util.locations_to_items(result))
        vim.cmd("copen")
        vim.cmd("wincmd p")
      end
    else
      vim.lsp.util.jump_to_location(result)
    end
  end
end
vim.lsp.handlers["textDocument/definition"] = goto_definition()
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {virtual_text = false})

vim.o.autoread = false
vim.o.autowrite = true
vim.o.colorcolumn = "101"
vim.o.completeopt = "menuone,noselect"
vim.o.foldenable = false
vim.o.ignorecase = true
vim.o.inccommand = "nosplit"
vim.o.linebreak = true
vim.o.number = true
vim.o.omnifunc = "v:lua.vim.lsp.omnifunc"
vim.o.pastetoggle = "<F11>"
vim.o.path = vim.o.path .. "**"
vim.o.scrolloff = 3
vim.o.shell = "sh"
vim.o.showmatch = true
vim.o.sidescrolloff = 10
vim.o.smartcase = true
vim.o.spell = not vim.o.diff
vim.o.termguicolors = true
vim.o.timeoutlen = 500
vim.o.title = true
vim.o.ttimeoutlen = 0
vim.o.updatetime = 250
vim.o.wildmode = "list:longest,full"

vim.g.do_filetype_lua = 1
vim.g.netrw_chgwin = 2
vim.g.vimtex_view_method = "zathura"
vim.g.symbols_outline = {
  symbols = {
    File = {icon = "F", hl = "TSURI"},
    Module = {icon = "M", hl = "TSNamespace"},
    Namespace = {icon = "ℕ", hl = "TSNamespace"},
    Package = {icon = "📦", hl = "TSNamespace"},
    Property = {icon = "P", hl = "TSMethod"},
    Field = {icon = "f", hl = "TSField"},
    Constructor = {icon = "", hl = "TSConstructor"},
    Interface = {icon = "I", hl = "TSType"},
    Variable = {icon = "V", hl = "TSConstant"},
    Constant = {icon = "C", hl = "TSConstant"},
    Array = {icon = "A", hl = "TSConstant"}
  }
}

vim.filetype.add({extension = {launch = "xml", test = "xml", install = "text"}})

vim.api.nvim_create_autocmd("BufRead", {pattern = "/tmp/mutt*", callback = function(args) vim.cmd("normal :g/^> -- $/,/^$/-1d^M/^$^M^L") end})
vim.api.nvim_create_autocmd("CursorHold,CursorHoldI", {pattern = "*", callback = function(args) vim.diagnostic.open_float(nil, {focus = false, scope = "cursor"}) end})
vim.api.nvim_create_autocmd("DiagnosticChanged", {pattern = "*", callback = function(args) vim.diagnostic.setqflist({open = false}) end})
vim.api.nvim_create_autocmd("FileType", {pattern = "qf,git,gitAnnotate,Outline,diff,help", callback = function(args) vim.opt_local.spell = false end})
vim.api.nvim_create_autocmd("FileType", {pattern = "remind", callback = function(args) vim.opt_local.spelllang = "de" end})
vim.api.nvim_create_autocmd("FileType", {
  pattern = "mail",
  callback = function(args)
    vim.opt_local.expandtab = true
    vim.opt_local.tabstop = 2
    vim.opt_local.shiftwidth = 2
    vim.opt_local.colorcolumn = "80"
  end
})

vim.api.nvim_set_hl(0, "ColorColumn", {bg = "Gray20"})
vim.api.nvim_set_hl(0, "GitSignsAdd", {bg = "Green"})
vim.api.nvim_set_hl(0, "GitSignsDelete", {bg = "Red"})
vim.api.nvim_set_hl(0, "SignColumn", {})
vim.api.nvim_set_hl(0, "SpellBad", {fg = "Red", underline = true})
vim.api.nvim_set_hl(0, "Pmenu", {bg = "Gray20"})

vim.cmd[[command DiffOrig vert new | set buftype=nofile | read ++edit # | 0d_ | diffthis | wincmd p | diffthis]]

-- https://wiki.ubuntuusers.de/VIM/Tipps
-- https://ftp.nluug.nl/pub/vim/runtime/spell/{de,en}.utf-8.{spl,sug}
-- :mkspell! ~/.local/share/nvim/site/spell/en.utf-8.add
local togglespell = function()
  if vim.o.spell then
    if vim.o.spelllang == "de" then
      vim.o.spelllang = "en"
      print("toggle spell " .. vim.o.spelllang)
    else
      vim.o.spell = false
      print("toggle spell off")
    end
  else
    vim.o.spell = true
    vim.o.spelllang = "de"
    print("toggle spell " .. vim.o.spelllang)
  end
end

vim.keymap.set("", "<F1>", togglespell)
vim.keymap.set("i", "<F1>", togglespell)
vim.keymap.set("", "gd", vim.lsp.buf.definition)
vim.keymap.set("", "<Space>f", vim.lsp.buf.formatting)
vim.keymap.set("", "<Space>F", vim.lsp.buf.range_formatting)
vim.api.nvim_set_keymap("", "<space>o", "<Cmd>SymbolsOutline<CR>", {silent = true})
vim.keymap.set("", "<Space>r", vim.lsp.buf.rename)
vim.api.nvim_set_keymap("", "<space>t", "<Cmd>UndotreeToggle<CR>", {silent = true})
vim.keymap.set("", "<Space>l", function() vim.lsp.stop_client(vim.lsp.get_active_clients()) end)
vim.keymap.set("", "<Space>q", vim.lsp.buf.code_action)
vim.keymap.set("", "<Space>Q", vim.lsp.buf.range_code_action)
vim.keymap.del("", "Y")

efm-langserver Config

languages:
  cmake:
    - format-command: 'cmake-format -'
      format-stdin: true
    - lint-command: 'cmake-lint'
      lint-formats:
        - '%f:%l,%c: %m'
  json:
    - format-command: 'python3 -m json.tool'
      format-stdin: true
    - lint-command: 'python3 -m json.tool'
      lint-stdin: true
      lint-formats:
        - '%m: line %l column %c (char %r)'
  markdown:
    - format-command: 'pandoc -f markdown -t gfm -sp --tab-stop=2'
      format-stdin: true
  rst:
    - format-command: 'pandoc -f rst -t rst -s --columns=79'
      format-stdin: true
    - lint-command: 'rstcheck -'
      lint-stdin: true
      lint-formats:
        - '%f:%l: (%tNFO/1) %m'
        - '%f:%l: (%tARNING/2) %m'
        - '%f:%l: (%tRROR/3) %m'
        - '%f:%l: (%tEVERE/4) %m'
  sh:
    - format-command: 'shfmt'
      format-stdin: true
    - lint-command: 'shellcheck -f gcc -x -'
      lint-stdin: true
      lint-formats:
        - '%f:%l:%c: %trror: %m'
        - '%f:%l:%c: %tarning: %m'
        - '%f:%l:%c: %tote: %m'
  tex:
    - lint-command: 'chktex -v0 -q'
      lint-stdin: true
      lint-formats:
        - '%f:%l:%c:%m'
  yaml:
    - lint-command: 'yamllint -f parsable -'
      lint-stdin: true