~nerosnm/nixos

f482b6787aa67edecfeed12d19c104339302e3a5 — Søren Mortensen 4 months ago e7eccca
Update nvim config
1 files changed, 294 insertions(+), 122 deletions(-)

M program/editor/neovim/configs/init.vim
M program/editor/neovim/configs/init.vim => program/editor/neovim/configs/init.vim +294 -122
@@ 2,7 2,6 @@
" INITIAL SETUP
" =============

" Set the shell nvim uses to bash
set shell=/bin/bash

" Set the leader key to space


@@ 30,10 29,6 @@ Plug 'itchyny/lightline.vim'
Plug 'machakann/vim-highlightedyank'
" Only display relative numbers in places that make sense
Plug 'jeffkreeftmeijer/vim-numbertoggle'
" Display git status of lines
Plug 'airblade/vim-gitgutter'
" Show the git blame for the current line
Plug 'APZelos/blamer.nvim'
" Additional color schemes
Plug 'sonph/onehalf', {'rtp': 'vim/'}
" Coloriser for color codes and things


@@ 56,12 51,28 @@ Plug 'airblade/vim-rooter'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

" Git
" ---
" Display git status of lines
Plug 'airblade/vim-gitgutter'
" Show the git blame for the current line
Plug 'APZelos/blamer.nvim'
" Run Git commands and resolve conflicts inside Vim
Plug 'tpope/vim-fugitive'

" Semantic language support
" -------------------------
" Language server support
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
" Completion support
Plug 'lifepillar/vim-mucomplete'
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
" Extensions to built-in LSP, for example, providing type inlay hints
Plug 'nvim-lua/lsp_extensions.nvim'
" Autocompletion framework for built-in LSP
Plug 'nvim-lua/completion-nvim'
" Improvements to the built-in LSP UI
Plug 'RishabhRD/popfix'
Plug 'RishabhRD/nvim-lsputils'
" Statusline component for LSP information
Plug 'nerosnm/lsp-status.nvim', { 'branch': 'nerosnm/always-add-space' }

" Syntactic language support
" --------------------------


@@ 70,23 81,21 @@ Plug 'rust-lang/rust.vim'
Plug 'cespare/vim-toml'
Plug 'lervag/vimtex'
Plug 'dag/vim-fish'
Plug 'plasticboy/vim-markdown'
Plug 'LnL7/vim-nix'
Plug 'plasticboy/vim-markdown'
" Other languages
Plug 'keith/swift.vim'
Plug 'pangloss/vim-javascript'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'vmchale/ion-vim'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'uarun/vim-protobuf'
Plug 'jparise/vim-graphql'
Plug 'unisonweb/unison', { 'rtp': 'editor-support/vim' }
Plug 'keith/swift.vim'
Plug 'derekwyatt/vim-scala'
Plug 'neovimhaskell/haskell-vim'
Plug 'elmcast/elm-vim'
Plug 'gleam-lang/gleam.vim'
Plug 'tikhomirov/vim-glsl'
" Extra tools
Plug 'godlygeek/tabular'
Plug 'rhysd/vim-clang-format'
Plug 'google/vim-maktaba'
Plug 'mhartington/formatter.nvim'

" Utility
" -------


@@ 106,43 115,40 @@ call plug#end()
set noshowmode
" Set a colour scheme and add a custom filename pattern.
let g:lightline = {
    \   'colorscheme': 'onehalfdark',
    \   'component_function': {
    \       'filename': 'LightlineFilename',
    \   },
    \ 'colorscheme': 'onehalfdark',
    \ 'active': {
    \     'left': [
    \         [ 'mode', 'paste' ],
    \         [ 'readonly', 'filename' ],
    \         [ 'lspstatus' ],
    \         [ 'truncate' ],
    \     ],
    \     'right': [
    \         [ 'lineinfo' ],
    \         [ 'percent' ],
    \         [ 'fileformat', 'fileencoding', 'filetype', 'charvaluehex' ],
    \     ]
    \ },
    \ 'component': {
    \     'truncate': '%<'
    \ },
    \ 'component_visible_condition': {
    \     'truncate': 0,
    \ },
    \ 'component_type': {
    \     'truncate': 'raw',
    \ },
    \ 'component_function': {
    \     'filename': 'LightlineFilename',
    \     'lspstatus': 'LspStatus',
    \ },
\ }
function! LightlineFilename()
  return expand('%:t') !=# '' ? @% : '[No Name]'
endfunction

" vim-gitgutter
" ------------
" Don't map any keys by default
let g:gitgutter_map_keys = 0
" Set all these signs to a bar so that just colour is used to distinguish
let g:gitgutter_sign_added = '▏'
let g:gitgutter_sign_modified = '▏'
let g:gitgutter_sign_removed = '▏'
let g:gitgutter_sign_removed_first_line = '▏'
let g:gitgutter_sign_modified_removed = '▏'
" Don't highlight line numbers
let g:gitgutter_highlight_linenrs = 0
highlight! link SignColumn LineNr

" blamer.nvim
" -----------
" Disabled by default; run :BlamerToggle to enable
let g:blamer_enabled = 0
" Shorten the delay before updates to blame information
let g:blamer_delay = 300
" Don't put a prefix at the beginning of the blame info
let g:blamer_prefix = ''
" Include short commit hash in addition to default blame info
let g:blamer_template = '<committer>, <committer-time> (<commit-short>) • <summary>'
" Only show the date, not time, in the blame info
let g:blamer_date_format = '%Y-%m-%d'
" Use relative date for recent dates
let g:blamer_relative_time = 1
function! LspStatus() abort
  return luaeval("require('lsp-status').status()")
endfunction

" nvim-colorizer.lua
" ------------------


@@ 170,7 176,7 @@ nmap <Leader>j <Plug>(easymotion-overwin-w)
" vim-rooter
" ----------
" Set file and directory patterns for detection of project root
let g:rooter_patterns = ['.git', '.git/', 'Cargo.lock']
let g:rooter_patterns = ['.git', '.git/', 'Cargo.lock', 'package-lock.json']

" fzf.vim
" -------


@@ 189,79 195,186 @@ command! -bang -nargs=* Rg
  \           : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)

" vim-gitgutter
" ------------
" Don't map any keys by default
let g:gitgutter_map_keys = 0
" Set all these signs to a bar so that just colour is used to distinguish
let g:gitgutter_sign_added = '▏'
let g:gitgutter_sign_modified = '▏'
let g:gitgutter_sign_removed = '▏'
let g:gitgutter_sign_removed_first_line = '▏'
let g:gitgutter_sign_modified_removed = '▏'
" Don't highlight line numbers
let g:gitgutter_highlight_linenrs = 0
highlight! link SignColumn LineNr

" coc.nvim
" --------
" List of language server extensions to install if they aren't already
let g:coc_global_extensions = [
    \ "coc-clangd",
    \ "coc-html",
    \ "coc-json",
    \ "coc-markdownlint",
    \ "coc-omnisharp",
    \ "coc-rust-analyzer",
    \ "coc-sourcekit",
    \ "coc-yaml",
    \ ]
" Shorten the update time of nvim to help with delays
" blamer.nvim
" -----------
" Disabled by default; run :BlamerToggle to enable
let g:blamer_enabled = 0
" Shorten the delay before updates to blame information
let g:blamer_delay = 300
" Don't put a prefix at the beginning of the blame info
let g:blamer_prefix = ''
" Include short commit hash in addition to default blame info
let g:blamer_template = '<committer>, <committer-time> (<commit-short>) • <summary>'
" Only show the date, not time, in the blame info
let g:blamer_date_format = '%Y-%m-%d'
" Use relative date for recent dates
let g:blamer_relative_time = 1

" nvim-lspconfig, nvim-lsputils, lsp-status.nvim
" ----------------------------------------------
" Set up language server(s)
lua <<EOF
local config = require'lspconfig'
local completion = require'completion'
local status = require'lsp-status'

local on_attach = function(client)
    completion.on_attach(client)
    status.on_attach(client, bufnr)
end

config.rust_analyzer.setup({
    on_attach = on_attach,
    on_init = function(client)
        client.config.flags = {
            allow_incremental_sync = false;
        }
    end,
    capabilities = status.capabilities,
    settings = {
        ["rust-analyzer"] = {
            diagnostics = {
                disabled = {
                    "unresolved-proc-macro"
                }
            }
        },
    },
    flags = {
        debounce_did_change_notify = 50,
    },
})

config.hls.setup({
    on_attach = on_attach,
    capabilities = status.capabilities,
})

config.tsserver.setup({
    on_attach = on_attach,
    capabilities = status.capabilities,
})

config.metals.setup({
    on_attach = on_attach,
    capabilities = status.capabilities,
})

vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
    vim.lsp.diagnostic.on_publish_diagnostics, {
        virtual_text = {
            prefix = '⋈',
        },
        signs = true,
        update_in_insert = false,
    }
)

vim.lsp.handlers['textDocument/codeAction'] = require'lsputil.codeAction'.code_action_handler
vim.lsp.handlers['textDocument/references'] = require'lsputil.locations'.references_handler
vim.lsp.handlers['textDocument/definition'] = require'lsputil.locations'.definition_handler
vim.lsp.handlers['textDocument/declaration'] = require'lsputil.locations'.declaration_handler
vim.lsp.handlers['textDocument/typeDefinition'] = require'lsputil.locations'.typeDefinition_handler
vim.lsp.handlers['textDocument/implementation'] = require'lsputil.locations'.implementation_handler
vim.lsp.handlers['textDocument/documentSymbol'] = require'lsputil.symbols'.document_handler
vim.lsp.handlers['workspace/symbol'] = require'lsputil.symbols'.workspace_handler

status.register_progress()
status.config({
    status_symbol = 'λ',
    current_function = false,
    indicator_errors = '●',
    indicator_warnings = '◉',
    indicator_info = '◎',
    indicator_hint = '○',
    indicator_ok = '◌',
    spinner_frames = { '◜', '◝', '◞', '◟' },
    -- spinner_frames = { '○', '◔', '◑', '◕', '●' },
})
EOF

" Code navigation shortcuts
nnoremap <silent> gd    <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K     <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gi    <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> gD    <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gu    <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0    <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW    <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> ga    <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <silent> gr    <cmd>lua vim.lsp.buf.rename()<CR>

" Set updatetime for CursorHold
" 100ms of no cursor movement to trigger CursorHold
set updatetime=100
" Rename the symbol under the cursor with <leader>rn
nmap <silent> gr <Plug>(coc-rename)
" Jump to the definition with gd
nmap <silent> gd <Plug>(coc-definition)
" Jump to implementations with gi
nmap <silent> gi <Plug>(coc-implementation)
" Jump to usages with gu
nmap <silent> gu <Plug>(coc-references)
" Show documentation in the preview window for the symbol under the cursor when pressing K
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  elseif (coc#rpc#ready())
    call CocActionAsync('doHover')
  else
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction
augroup coc | au!
    " Customise some of the colours used in the Coc Pmenu
    au ColorScheme * hi! CocFloating guibg=#40464F
    " Always show the signcolumn, and give it a transparent background
    au ColorScheme * hi! SignColumn guibg=none
    " Make hint text grey
    au ColorScheme * hi! CocHintSign guifg=#6F6F6F
    " Darken special (doc) comments a bit
    au ColorScheme * hi! SpecialComment guifg=#BFBFBF
    " Make comments italic
    au ColorScheme * hi! Comment gui=italic
    au ColorScheme * hi! SpecialComment gui=italic
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()

" Goto previous/next diagnostic warning/error
nnoremap <silent> g< <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> g> <cmd>lua vim.lsp.diagnostic.goto_next()<CR>

" Enable type inlay hints
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = '▷ ', highlight = "InlayHint", enabled = { "TypeHint", "ChainingHint", "ParameterHint" } }

augroup lspcolors | au!
    " Customise some of the colours used for LSP things
    au ColorScheme * hi! NormalFloat guibg=#3c4048
    au ColorScheme * hi! LspDiagnosticsDefaultHint guifg=#5c6370
    au ColorScheme * hi! LspDiagnosticsDefaultInformation guifg=#5c6370
    au ColorScheme * hi! LspDiagnosticsDefaultWarning guifg=#e5c07b
    au ColorScheme * hi! LspDiagnosticsDefaultError guifg=#e06c75
    " Customise some of the symbols used
    sign define LspDiagnosticsSignError text=●
    sign define LspDiagnosticsSignWarning text=◉
    sign define LspDiagnosticsSignInformation text=◎
    sign define LspDiagnosticsSignHint text=○
    " Add a highlight group for inlay hints
    au ColorScheme * hi! InlayHint guifg=#848b98
augroup END

" vim-mucomplete
" --------------
" mucomplete says this option is required
set completeopt=menu
set completeopt+=menuone
set completeopt+=noinsert
" Turn off completion messages
" completion-nvim
" ---------------
" Set completeopt to have a better completion experience
" - menuone: popup even when there's only one match
" - noinsert: Do not insert text until a selection is made
" - noselect: Do not select, force user to select one from the menu
set completeopt=menuone,noinsert,noselect
" Turn off extra completion messages
set shortmess+=c
" Turn off auto-completion at startup
let g:mucomplete#enable_auto_at_startup = 0
" Set up completion chains
let g:mucomplete#chains = {
\   'default': ['tags', 'nsnp'],
\   'rust': {
\     'default': ['omni', 'nsnp'],
\     'rustString.*': [],
\     'rustComment.*': ['spel'],
\   },
\   'vim' : {
\     'default': ['cmd', 'nsnp', 'keyn'],
\     'vimComment.*': [],
\     'vimString.*': ['spel']
\   },
\ }

" Don't automatically pop up completion unless Tab has been pressed
let g:completion_enable_auto_popup = 0

" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

" use <Tab> as trigger keys
imap <Tab> <Plug>(completion_smart_tab)
imap <S-Tab> <Plug>(completion_smart_s_tab)

" Set matching strategy for completions
let g:completion_matching_strategy_list = ['exact', 'substring', 'fuzzy', 'all']

" Complete parentheses for functions
let g:completion_enable_auto_paren = 1

" rust.vim
" --------


@@ 281,10 394,45 @@ let g:vimtex_imaps_leader = ';'
" Disable automatic folding of sections in Markdown files
let g:vim_markdown_folding_disabled = 1

" Disable markdown conceal feature
let g:vim_markdown_conceal = 0

" Disable TeX conceal feature
let g:tex_conceal = ""
let g:vim_markdown_math = 1

" Turn on support for frontmatter in Markdown files
let g:vim_markdown_frontmatter = 1 " YAML
let g:vim_markdown_toml_frontmatter = 1
let g:vim_markdown_json_frontmatter = 1

" vim-clang-format
" ----------------
let g:clang_format#code_style = 'llvm'

" formatter.nvim
" --------------
lua <<EOF
require('formatter').setup({
    logging = false,
    filetype = {
        haskell = {
            function()
                return {
                    exe = "stylish-haskell",
                    args = {},
                    stdin = true
                }
            end
        }
    }
})
EOF

augroup Formatter | au!
    au BufWritePost *.hs :FormatWrite
augroup END

" =================
" LANGUAGE SETTINGS
" =================


@@ 371,18 519,38 @@ augroup gemini | au!
    au BufRead,BufNewFile *.gmi setlocal wrap linebreak textwidth=0 wrapmargin=0
augroup END

" Haskell
" ----
augroup hs | au!

    " Set the indentation width to 2 spaces for Haskell
    au Filetype haskell setlocal shiftwidth=2 softtabstop=2
augroup END

" ===============
" EDITOR SETTINGS
" ===============

" Appearance
" ----------
" Set a color scheme
colorscheme onehalfdark
augroup appearance | au!
    " Give the sign column a transparent background
    au ColorScheme * hi! SignColumn guibg=none
    " Darken special (doc) comments a bit
    au ColorScheme * hi! SpecialComment guifg=#c0c7d4
    " Make comments italic
    au ColorScheme * hi! Comment gui=italic
    au ColorScheme * hi! SpecialComment gui=italic
    " Use undercurl for misspelled words
    au ColorScheme * hi! SpellBad guisp=Red gui=undercurl
    au ColorScheme * hi! SpellCap guisp=Yellow gui=undercurl
augroup END
" Display a background on the line with the cursor on it
set cursorline
" Always show the signcolumn
set signcolumn=yes
" Set the color scheme
colorscheme onehalfdark

" Text Editing
" ------------


@@ 410,6 578,8 @@ set fo+=j " Auto-remove comment characters when joining lines
inoremap <M-o> ø
" Enable mouse usage (all modes) in terminals
set mouse=a
" Enable spell check
" set spell spelllang=en_gb

" Text Display
" ------------


@@ 507,9 677,10 @@ nnoremap <leader><leader> <c-^>

" Open a new file adjacent to current file
nnoremap <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
nnoremap <leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>

" Toggle search highlighting
nmap <silent> <leader>/ :set hlsearch!<cr>
nmap <silent> <leader>/ :noh<cr>

" Create splits with <leader>s and a direction
nmap <silent> <leader>sh :leftabove vnew<cr>


@@ 527,3 698,4 @@ nnoremap <C-H> <C-W><C-H>
noremap M :make<cr>
" Run make from the directory containing the current file
noremap MM :!cd "%:p:h" \| make<cr>