This commit is contained in:
Nicole Dresselhaus 2024-02-07 16:00:31 +01:00
parent b876d10530
commit 4240a67dff
2 changed files with 196 additions and 190 deletions

View File

@ -1,36 +0,0 @@
{
"languageserver": {
"haskell": {
"command": "haskell-language-server-wrapper",
"args": ["--lsp"],
"rootPatterns": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml"],
"filetypes": ["haskell", "lhaskell"]
}
},
"coc.source.iced.enable": true,
"coc.preferences.formatOnSaveFiletypes": ["css","markdown"],
"diagnostic-languageserver.filetypes": {
"vim": "vint",
"email": "languagetool",
"markdown": [ "write-good", "markdownlint" ],
"sh": "shellcheck",
"bash": "shellcheck",
"elixir": ["mix_credo", "mix_credo_compile"],
"eelixir": ["mix_credo", "mix_credo_compile"],
"php": ["phpstan", "psalm"],
"yaml": [ "yamllint" ],
"cmake": [ "cmake-lint", "cmakelint" ],
"systemd": "systemd-analyze"
},
"diagnostic-languageserver.formatFiletypes": {
"dart": "dartfmt",
"elixir": "mix_format",
"eelixir": "mix_format",
"python": ["black", "isort"],
"lua": "lua-format",
"sh": "shfmt",
"bash": "shfmt",
"blade": "blade-formatter",
"cmake": "cmake-format"
}
}

View File

@ -60,13 +60,6 @@ Plug 'mhinz/vim-sayonara'
" Session-Management " Session-Management
Plug 'xolox/vim-session' | Plug 'xolox/vim-misc' Plug 'xolox/vim-session' | Plug 'xolox/vim-misc'
" CoC
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Clojure
Plug 'guns/vim-sexp', {'for': 'clojure'}
Plug 'liquidz/vim-iced', {'for': 'clojure'}
Plug 'liquidz/vim-iced-coc-source', {'for': 'clojure'}
" todo.txt " todo.txt
Plug 'freitass/todo.txt-vim' Plug 'freitass/todo.txt-vim'
@ -74,14 +67,21 @@ Plug 'freitass/todo.txt-vim'
" LSP " LSP
Plug 'williamboman/mason.nvim' Plug 'williamboman/mason.nvim'
Plug 'williamboman/mason-lspconfig.nvim' Plug 'williamboman/mason-lspconfig.nvim'
Plug 'neovim/nvim-lspconfig', {'branch': 'v0.1.6'} Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'onsails/lspkind.nvim'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" Go
Plug 'fatih/vim-go', {'do':':GoUpdateBinaries'}
call plug#end() call plug#end()
" GENERAL VIM SETUP
" SETTINGS
" set leader to space " set leader to space
let mapleader= "\<SPACE>" let mapleader= "\<SPACE>"
@ -119,7 +119,7 @@ set smartcase " ... unless the query has capital letters.
set incsearch " Incremental search. set incsearch " Incremental search.
set gdefault " Use 'g' flag by default with :s/foo/bar/. set gdefault " Use 'g' flag by default with :s/foo/bar/.
set magic " Use 'magic' patterns (extended regular expressions). set magic " Use 'magic' patterns (extended regular expressions).
"set inccommand=nosplit " Use live-preview of search/replace etc. set inccommand=nosplit " Use live-preview of search/replace etc.
set conceallevel=2 " Allow things to be visually opressed (i.e. *foo* be italic) set conceallevel=2 " Allow things to be visually opressed (i.e. *foo* be italic)
set mouse=a " enable mouse set mouse=a " enable mouse
set foldenable " enable folding set foldenable " enable folding
@ -133,46 +133,13 @@ set hidden
let g:loaded_perl_provider = 0 let g:loaded_perl_provider = 0
" LSP Config
lua << EOF
require("mason").setup()
require("mason-lspconfig").setup()
EOF
" Use <C-L> to clear the highlighting of :set hlsearch.
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
endif
" Remember cursor position between vim sessions " Remember cursor position between vim sessions
autocmd BufReadPost * autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") | \ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" | \ exe "normal! g'\"" |
\ endif \ endif
" center buffer around cursor when opening files " center buffer around cursor when opening files
autocmd BufRead * normal zz autocmd BufRead * normal zz
"" KEY-BINDINGS
" use <TAB> to fold/unfold
nnoremap <TAB> za
" <Tab>: completion
function! CheckBackSpace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-N>" :
\ CheckBackSpace() ? "\<Tab>" :
\ coc#refresh()
" <S-Tab>: completion back
inoremap <silent><expr> <S-Tab> pumvisible() ? "\<C-P>" : "\<C-H>"
" <CR>: confirm completion, or insert <CR>
inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"
" use <C-J> to Jump to definition instead of <C-]> (default) " use <C-J> to Jump to definition instead of <C-]> (default)
nmap <C-J> <C-]> nmap <C-J> <C-]>
@ -184,129 +151,204 @@ inoremap <C-D> <esc>ddi
tnoremap <C-t><C-t> <C-\><C-n> tnoremap <C-t><C-t> <C-\><C-n>
""""""""""""""""""""""""""""""""""""""""""""" Coc Keys " FANCY NEOVIM-MAGIC
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation " setup mason, language-server & nvim-cmp for completion
nmap <silent> gd <Plug>(coc-definition) lua <<EOF
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window require("mason").setup()
nnoremap <silent> K :call ShowDocumentation()<CR> require("mason-lspconfig").setup()
function! ShowDocumentation() local has_words_before = function()
if CocAction('hasProvider', 'hover') unpack = unpack or table.unpack
call CocActionAsync('doHover') local line, col = unpack(vim.api.nvim_win_get_cursor(0))
else return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
call feedkeys('K', 'in') end
endif
endfunction
" Highlight the symbol and its references when holding the cursor local feedkey = function(key, mode)
autocmd CursorHold * silent call CocActionAsync('highlight') vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
" Symbol renaming -- Set up nvim-cmp.
nmap <leader>rn <Plug>(coc-rename) local cmp = require'cmp'
local lspkind = require'lspkind'
" Formatting selected code cmp.setup({
xmap <leader>f <Plug>(coc-format-selected) snippet = {
nmap <leader>f <Plug>(coc-format-selected) -- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
formatting = {
format = lspkind.cmp_format(),
},
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
if #cmp.get_entries() == 1 then
cmp.confirm({ select = true })
else
cmp.select_next_item()
end
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
if #cmp.get_entries() == 1 then
cmp.confirm({ select = true })
end
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
augroup mygroup ["<S-Tab>"] = cmp.mapping(function()
autocmd! if cmp.visible() then
" Setup formatexpr specified filetype(s) cmp.select_prev_item()
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') elseif vim.fn["vsnip#jumpable"](-1) == 1 then
" Update signature help on jump placeholder feedkey("<Plug>(vsnip-jump-prev)", "")
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') end
augroup end end, { "i", "s" }),
" Applying code actions to the selected code block }),
" Example: `<leader>aap` for current paragraph sources = cmp.config.sources({
xmap <leader>a <Plug>(coc-codeaction-selected) { name = 'nvim_lsp' },
nmap <leader>a <Plug>(coc-codeaction-selected) { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
" Remap keys for applying code actions at the cursor position -- Set configuration for specific filetype.
nmap <leader>ac <Plug>(coc-codeaction-cursor) cmp.setup.filetype('gitcommit', {
" Remap keys for apply code actions affect whole buffer sources = cmp.config.sources({
nmap <leader>as <Plug>(coc-codeaction-source) { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
" Apply the most preferred quickfix action to fix diagnostic on the current line }, {
nmap <leader>qf <Plug>(coc-fix-current) { name = 'buffer' },
})
})
" Remap keys for applying refactor code actions -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor) cmp.setup.cmdline({ '/', '?' }, {
xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) mapping = cmp.mapping.preset.cmdline(),
nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) sources = {
{ name = 'buffer' }
}
})
" Run the Code Lens action on the current line -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
nmap <leader>cl <Plug>(coc-codelens-action) cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
" Map function and class text objects -- Set up lspconfig.
" NOTE: Requires 'textDocument.documentSymbol' support from the language server local capabilities = require('cmp_nvim_lsp').default_capabilities()
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> to scroll float windows/popups local on_attach = function(client, bufnr)
if has('nvim-0.4.0') || has('patch-8.2.0750') local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
" Requires 'textDocument/selectionRange' support of language server end
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer require("lspconfig").gopls.setup {
command! -nargs=0 Format :call CocActionAsync('format') cmd = {'gopls'},
-- on_attach = on_attach,
capabilities = capabilities,
settings = {
gopls = {
experimentalPostfixCompletions = true,
analyses = {
unusedparams = true,
shadow = true,
},
staticcheck = true,
},
},
init_options = {
usePlaceholders = true,
}
}
require("lspconfig").eslint.setup {}
require("lspconfig").jsonls.setup {}
require("lspconfig").tsserver.setup {}
require("lspconfig").ast_grep.setup {}
require("lspconfig").golangci_lint_ls.setup {}
" Add `:Fold` command to fold current buffer function swallow_output(callback, ...)
command! -nargs=? Fold :call CocAction('fold', <f-args>) local old_print = print
print = function(...) end
" Add `:OR` command for organize imports of the current buffer pcall(callback, arg)
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support print = old_print
" NOTE: Please see `:h coc-status` for integrations with external plugins that end
" provide custom statusline: lightline.vim, vim-airline
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList -- See `:help vim.diagnostic.*` for documentation on any of the below functions
" Show all diagnostics vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr> vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
" Manage extensions vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr> vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
" Show commands
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr> -- Use LspAttach autocommand to only map the following keys
" Find symbol of current document -- after the language server attaches to the current buffer
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr> vim.api.nvim_create_autocmd('LspAttach', {
" Search workspace symbols group = vim.api.nvim_create_augroup('UserLspConfig', {}),
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr> callback = function(ev)
" Do default action for next item
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR> -- Buffer local mappings.
" Do default action for previous item -- See `:help vim.lsp.*` for documentation on any of the below functions
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR> local opts = { buffer = ev.buf }
" Resume latest coc list vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR> vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('v', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
vim.api.nvim_create_autocmd('BufWrite', {
callback = function(ev)
vim.lsp.buf.format { async = false }
end
})
end,
})
EOF
"" KEY-BINDINGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" autoformat code if possible (read docs on vim-autoformat!)
"noremap <leader>f :Autoformat<CR>
noremap <leader>TM :TableModeToggle<CR> noremap <leader>TM :TableModeToggle<CR>
" multi-cursor " multi-cursor