Compare commits

...

2 Commits

Author SHA1 Message Date
4240a67dff sync 2024-02-07 16:00:31 +01:00
b876d10530 merge 2024-02-02 10:47:49 +01:00
2 changed files with 196 additions and 187 deletions

View File

@ -1,35 +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,
"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,12 +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'
call plug#end() call plug#end()
" GENERAL VIM SETUP
" SETTINGS
" set leader to space " set leader to space
let mapleader= "\<SPACE>" let mapleader= "\<SPACE>"
@ -117,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
@ -131,18 +133,6 @@ 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("$") |
@ -151,27 +141,6 @@ 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-]>
@ -182,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))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
-- Set up nvim-cmp.
local cmp = require'cmp'
local lspkind = require'lspkind'
cmp.setup({
snippet = {
-- 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 else
call feedkeys('K', 'in') cmp.select_next_item()
endif end
endfunction 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" }),
" Highlight the symbol and its references when holding the cursor ["<S-Tab>"] = cmp.mapping(function()
autocmd CursorHold * silent call CocActionAsync('highlight') if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
" Symbol renaming }),
nmap <leader>rn <Plug>(coc-rename) sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
" Formatting selected code -- Set configuration for specific filetype.
xmap <leader>f <Plug>(coc-format-selected) cmp.setup.filetype('gitcommit', {
nmap <leader>f <Plug>(coc-format-selected) sources = cmp.config.sources({
{ name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
}, {
{ name = 'buffer' },
})
})
augroup mygroup -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
autocmd! cmp.setup.cmdline({ '/', '?' }, {
" Setup formatexpr specified filetype(s) mapping = cmp.mapping.preset.cmdline(),
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') sources = {
" Update signature help on jump placeholder { name = 'buffer' }
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') }
augroup end })
" Applying code actions to the selected code block -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
" Example: `<leader>aap` for current paragraph cmp.setup.cmdline(':', {
xmap <leader>a <Plug>(coc-codeaction-selected) mapping = cmp.mapping.preset.cmdline(),
nmap <leader>a <Plug>(coc-codeaction-selected) sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
" Remap keys for applying code actions at the cursor position -- Set up lspconfig.
nmap <leader>ac <Plug>(coc-codeaction-cursor) local capabilities = require('cmp_nvim_lsp').default_capabilities()
" Remap keys for apply code actions affect whole buffer
nmap <leader>as <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>qf <Plug>(coc-fix-current)
" Remap keys for applying refactor code actions local on_attach = function(client, bufnr)
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected) local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
" Run the Code Lens action on the current line buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
nmap <leader>cl <Plug>(coc-codelens-action) end
" Map function and class text objects require("lspconfig").gopls.setup {
" NOTE: Requires 'textDocument.documentSymbol' support from the language server cmd = {'gopls'},
xmap if <Plug>(coc-funcobj-i) -- on_attach = on_attach,
omap if <Plug>(coc-funcobj-i) capabilities = capabilities,
xmap af <Plug>(coc-funcobj-a) settings = {
omap af <Plug>(coc-funcobj-a) gopls = {
xmap ic <Plug>(coc-classobj-i) experimentalPostfixCompletions = true,
omap ic <Plug>(coc-classobj-i) analyses = {
xmap ac <Plug>(coc-classobj-a) unusedparams = true,
omap ac <Plug>(coc-classobj-a) 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 {}
" Remap <C-f> and <C-b> to scroll float windows/popups function swallow_output(callback, ...)
if has('nvim-0.4.0') || has('patch-8.2.0750') local old_print = print
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>" print = function(...) 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 pcall(callback, arg)
" Requires 'textDocument/selectionRange' support of language server
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer print = old_print
command! -nargs=0 Format :call CocActionAsync('format') end
" Add `:Fold` command to fold current buffer -- See `:help vim.diagnostic.*` for documentation on any of the below functions
command! -nargs=? Fold :call CocAction('fold', <f-args>) vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
" Add `:OR` command for organize imports of the current buffer -- Use LspAttach autocommand to only map the following keys
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport') -- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
" Add (Neo)Vim's native statusline support -- Buffer local mappings.
" NOTE: Please see `:h coc-status` for integrations with external plugins that -- See `:help vim.lsp.*` for documentation on any of the below functions
" provide custom statusline: lightline.vim, vim-airline local opts = { buffer = ev.buf }
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
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
" Mappings for CoCList "" KEY-BINDINGS
" Show all diagnostics
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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