~kaction/config

34c7ba361469468091b4530b3e13722b36d17b86 — Dmitry Bogatov 4 months ago 685a2e7
Switch from vim to neovim

Neovim seems to be mostly compatible with vim, but has lua api. It
is not as good as emacs lisp, but much better than vim in which all
interactions between normal languages and vimscript are done via eval.
M flake.nix => flake.nix +1 -0
@@ 68,6 68,7 @@
          attach-shell = call ./universe/attach-shell;
          blurdate = callPackage ./universe/blurdate { };
          dbxcli = callPackage ./universe/dbxcli { };
          neovim = callPackage ./universe/neovim { };
          dvtm =
            import ./universe/dvtm { inherit (pkgs.pkgsStatic) dvtm-unstable; };
          fasm-arch = call ./universe/fasm-arch;

M universe/default.nix => universe/default.nix +1 -1
@@ 67,7 67,7 @@ in with pkgs; buildEnv {
      trezord
      uenv
      urlview # open links in email
      vim
      neovim
      w3m # Web-browser that supports tables
      haskell.compiler.ghc884
      haskell.packages.ghc884.haskell-language-server

A universe/neovim/boot/after/ftplugin/c.vim => universe/neovim/boot/after/ftplugin/c.vim +2 -0
@@ 0,0 1,2 @@
vnoremap  <buffer> -- :!boxes -m -d c<CR>
setlocal equalprg=indent\ -linux\ -psl

A universe/neovim/boot/after/ftplugin/debchangelog.vim => universe/neovim/boot/after/ftplugin/debchangelog.vim +1 -0
@@ 0,0 1,1 @@
setlocal sw=2

A universe/neovim/boot/after/ftplugin/dhall.vim => universe/neovim/boot/after/ftplugin/dhall.vim +2 -0
@@ 0,0 1,2 @@
set expandtab
set shiftwidth=2

A universe/neovim/boot/after/ftplugin/execline.vim => universe/neovim/boot/after/ftplugin/execline.vim +4 -0
@@ 0,0 1,4 @@
setlocal shiftwidth=2
setlocal tabstop=2
setlocal expandtab
let b:undo_ftplugin = ""

A universe/neovim/boot/after/ftplugin/gitcommit.vim => universe/neovim/boot/after/ftplugin/gitcommit.vim +1 -0
@@ 0,0 1,1 @@
set textwidth=0 " conflicts with language server

A universe/neovim/boot/after/ftplugin/gmi.vim => universe/neovim/boot/after/ftplugin/gmi.vim +5 -0
@@ 0,0 1,5 @@
set colorcolumn=0
set textwidth=0
set wrap
set wrapmargin=0
set linebreak

A universe/neovim/boot/after/ftplugin/haskell.vim => universe/neovim/boot/after/ftplugin/haskell.vim +15 -0
@@ 0,0 1,15 @@

setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal textwidth=79
setlocal equalprg=brittany

nnoremap <buffer> <leader>= m'ggVG=''

command! -bang -nargs=1 -complete=tag HSymbol call hsymbol#main(<f-args>, "<bang>")
command! -bang HSymbolWord call hsymbol#main(expand("<cword>"), "<bang>")
nnoremap <buffer> <leader>i :HSymbolWord<CR>
nnoremap <buffer> <leader>I :HSymbolWord!<CR>

au BufWrite *.hs :silent !vtags --silent 2>/dev/null &

A universe/neovim/boot/after/ftplugin/html.vim => universe/neovim/boot/after/ftplugin/html.vim +3 -0
@@ 0,0 1,3 @@
setlocal shiftwidth=2
setlocal expandtab
setlocal softtabstop=2

A universe/neovim/boot/after/ftplugin/lua.vim => universe/neovim/boot/after/ftplugin/lua.vim +3 -0
@@ 0,0 1,3 @@
setlocal shiftwidth=2
setlocal expandtab
setlocal softtabstop=2

A universe/neovim/boot/after/ftplugin/purescript.vim => universe/neovim/boot/after/ftplugin/purescript.vim +3 -0
@@ 0,0 1,3 @@
set shiftwidth=2
set tabstop=2
set expandtab

A universe/neovim/boot/after/ftplugin/python.vim => universe/neovim/boot/after/ftplugin/python.vim +1 -0
@@ 0,0 1,1 @@
set equalprg=pyfmt

A universe/neovim/boot/after/ftplugin/sh.vim => universe/neovim/boot/after/ftplugin/sh.vim +7 -0
@@ 0,0 1,7 @@
setlocal tabstop=4
setlocal shiftwidth=4

if expand("%:t") ==# '.posixrc'
  let &path = printf("%s/prefix/config/posix", expand("%:h"))
  setlocal suffixesadd+=.sh
endif

A universe/neovim/boot/after/ftplugin/vim.vim => universe/neovim/boot/after/ftplugin/vim.vim +1 -0
@@ 0,0 1,1 @@
setlocal shiftwidth=2

A universe/neovim/boot/after/ftplugin/yaml.vim => universe/neovim/boot/after/ftplugin/yaml.vim +2 -0
@@ 0,0 1,2 @@
set expandtab
set shiftwidth=2

A universe/neovim/boot/after/syntax/execline.vim => universe/neovim/boot/after/syntax/execline.vim +49 -0
@@ 0,0 1,49 @@
if exists("b:current_syntax") | finish | endif
syntax keyword Special background
syntax keyword Special backtick
syntax keyword Special cd
syntax keyword Special define
syntax keyword Special dollarat
syntax keyword Special elgetopt
syntax keyword Special elgetpositionals
syntax keyword Special elglob
syntax keyword Special emptyenv
syntax keyword Special exec
syntax keyword Special exitcodes
syntax keyword Special exit
syntax keyword Special export
syntax keyword Special fdblock
syntax keyword Special fdclose
syntax keyword Special fdmove
syntax keyword Special fdreserve
syntax keyword Special fdswap
syntax keyword Special forbacktickx
syntax keyword Special foreground
syntax keyword Special forstdin
syntax keyword Special forx
syntax keyword Special getcwd
syntax keyword Special getpid
syntax keyword Special heredoc
syntax keyword Special homeof
syntax keyword Special ifelse
syntax keyword Special if
syntax keyword Special ifte
syntax keyword Special ifthenelse
syntax keyword Special importas
syntax keyword Special loopwhilex
syntax keyword Special multidefine
syntax keyword Special multisubstitute
syntax keyword Special pipeline
syntax keyword Special piperw
syntax keyword Special redirfd
syntax keyword Special runblock
syntax keyword Special shift
syntax keyword Special trap
syntax keyword Special tryexec
syntax keyword Special umask
syntax keyword Special unexport
syntax keyword Special upgrade
syntax keyword Special wait
syntax keyword Special withstdinas
syntax match Function /\(^\| \):[a-z-]\+\($\| \)/
syntax match Comment /^#.*/

A universe/neovim/boot/after/syntax/gitcommit.vim => universe/neovim/boot/after/syntax/gitcommit.vim +29 -0
@@ 0,0 1,29 @@
" Minor amendments to gitcommit.vim syntax file to encourage formatting
" commit messages more verbosely and informative. Following is added:
"
" * Highlight `m4-style' quotation. Personally, I often mix this style
"   with `markdown` one. With highlighting it is easier to be
"   consistent.
"
" * Highlight GNU-style changelog entries, like following:
"
"     * src/foo.c: reworked i/o subsistem.
"     * src/bar.c(output_object): rewrite function to avoid use of
"       stdio.
"
" * Make mode suitable for editing src(1) commit messages too.

syn region gitcommitEntry start="^ \* " end=":" transparent
  \ contains=gitcommitFilePath,gitcommitAffected
syn match gitcommitBullet "^ \*" contained
syn match gitcommitFilePath "\v^ \* [a-zA-Z0-9./_-]+" contained contains=gitcommitBullet
syn match gitcommitAffected "\v\(\zs[a-zA-Z0-9_-]+\ze\)" contained
syn match gitcommitQuote "\v`\zs[a-zA-Z/.-]+\ze'"
syn region gitcommitComment start="^\.\.\." end="^Changes to be committed:"
syn region gitcommitDiff start=/^--- / end=/______/ contains=@gitcommitDiff

hi! def link gitcommitBullet gitcommitComment
hi! def link gitcommitFilePath Type
hi! def link gitcommitBullet Title
hi! def link gitcommitAffected Identifier
hi! def link gitcommitQuote Constant

A universe/neovim/boot/after/syntax/sh.vim => universe/neovim/boot/after/syntax/sh.vim +4 -0
@@ 0,0 1,4 @@
syntax match shSpecial "^\s*include "
syntax match shSpecial "^\s*once "
syntax match shSpecial "^\s*have "
syntax match shSpecial "^\s*optional "

A universe/neovim/boot/after/syntax/sql.vim => universe/neovim/boot/after/syntax/sql.vim +3 -0
@@ 0,0 1,3 @@
set shiftwidth=2
set tabstop=2
set expandtab

A universe/neovim/boot/lua/boot.lua => universe/neovim/boot/lua/boot.lua +67 -0
@@ 0,0 1,67 @@
local M = {}

local lspconfig = require 'lspconfig'

-- Copied almost verbatim from official repositoriy of nvim-lspconfig:
-- https://github.com/neovim/nvim-lspconfig#keybindings-and-completion
local lsp_on_attach = function(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  local opts = { noremap=true, silent=true }
  buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
  buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
  buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
  buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)

  -- Set some keybinds conditional on server capabilities
  if client.resolved_capabilities.document_formatting then
    buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
  elseif client.resolved_capabilities.document_range_formatting then
    buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
  end

  -- Set autocommands conditional on server_capabilities
  if client.resolved_capabilities.document_highlight then
    vim.api.nvim_exec([[
      hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
      hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
      hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]], false)
  end
end

function M.main()
  opts = { on_attach = lsp_on_attach }

  lspconfig.ccls.setup(opts)
  lspconfig.dhall_lsp_server.setup(opts)
  lspconfig.texlab.setup(opts)
  lspconfig.pyls.setup(opts)
  lspconfig.gopls.setup(opts)
  lspconfig.rnix.setup(opts)
  lspconfig.hls.setup(opts)

  vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
    vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = false })
end

return M

A universe/neovim/default.nix => universe/neovim/default.nix +55 -0
@@ 0,0 1,55 @@
{ fetchgit, tree-sitter, neovim-unwrapped, wrapNeovim, vimUtils, vimPlugins }:
let
  file-json = path: builtins.fromJSON (builtins.readFile path);
  source = path:
    let info = file-json path;
    in (fetchgit { inherit (info) url rev sha256; }) // info;

  plugin = path:
    vimUtils.buildVimPluginFrom2Nix rec {
      pname = builtins.baseNameOf src.url;
      version = src.rev;
      src = source path;
    };
  boot-plugin = vimUtils.buildVimPluginFrom2Nix rec {
    pname = "boot";
    version = "1.0";
    src = ./boot;
  };

  nightly = neovim-unwrapped.overrideAttrs (old: {
    name = "neovim-0.4.4+nightly";
    src = source ./src/neovim.json;
    buildInputs = old.buildInputs ++ [ tree-sitter ];
  });
in wrapNeovim nightly {
  configure = {
    packages.boot = with vimPlugins; {
      start = [
        vim-nix
        dhall-vim
        last256
        vim-snipmate
        vim-snippets
        nvim-lspconfig
        purescript-vim
        vim-addon-mw-utils # hidden dependency of vim-snipmate
        tlib
        vim-colorschemes
        boot-plugin
        (plugin ./src/vim-bookmarks.json)
        (plugin ./src/vim-nnn.json)
        (plugin ./src/vim-nginx.json)
        (plugin ./src/vim-pgsql.json)
        (plugin ./src/vim-gemini.json)
        (plugin ./src/vim-vidir.json)
      ];
    };
    customRC = ''
      set rtp+=${./boot}
      set rtp+=${./boot}/after
      lua require('boot').main()
      ${builtins.readFile ./init.vim}
    '';
  };
}

A universe/neovim/init.vim => universe/neovim/init.vim +93 -0
@@ 0,0 1,93 @@
set nocompatible
syntax enable
filetype plugin indent on

set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0

set autoindent
set cmdwinheight=4
" This teaches vim to find files references by Python's pkgutil.get_data
set path+=.;.git
set cindent
set complete+=t "tag completion
set copyindent
set exrc
set foldclose=all
set foldlevel=0
set foldmethod=marker
set incsearch
set list
set listchars=trail:-,tab:>.
" panic action to prevent cve-2019-12735
set nomodeline
set magic
set nohlsearch
set ruler
set secure
set showmatch
set showcmd
set smartcase
set wildmenu
set wildmode=list:longest,list:longest
set infercase
set colorcolumn=80
set laststatus=0
set number

" There is no reason for .viminfo file to survive reboot. This way it
" does not clutter ~/.
let &viminfofile = "/dev/shm/" . getenv("USER") . "/.neovim.info"
let g:netrw_home = "/dev/shm/" . getenv("USER")

let g:sql_type_default = 'pgsql'
let g:pgsql_pl = ['python']

" Vim thinks, that /bin/sh scripts must use backticks for command
" substitution. Make it believe that shell is actually bash.
let g:is_bash=1
let g:sh_fold_enabled=7

map Q gq
noremap j gj
noremap k gk
set tags+=../tags,../../tags,../../../tags,../../../../tags

au BufNewFile,BufRead *.asy setf asy
au BufNewFile,BufRead manifest setf sh

" These are huge files (~150k lines) in nixpkgs, and they hang syntax
" highlight.
au BufNewFile,BufRead all-packages.nix set syntax=off
au BufNewFile,BufRead hackage-packages.nix set syntax=off

au BufNewFile,BufRead */.mail/*/[0123456789]* setf mail
au BufNewFile,BufRead /tmp/src* setf gitcommit
au BufNewFile,BufRead *.asy setfiletype asy
au BufNewFile,BufRead manifest setfiletype sh
au BufNewFile,BufRead *.ex set filetype=execline
au BufNewFile,BufRead *.exec set filetype=execline
" Used by redo(1) build system.
au BufNewFile,BufRead *.do set filetype=sh
au BufNewFile,BufRead *.fasm setfiletype fasm
au BufNewFile,BufRead,BufWritePost *.gmi set columns=80
au BufNewFile,BufRead */mail/*/[0123456789]* setfiletype mail
au BufNewFile,BufRead syntax sync minlines=200 "slower but more correct highlighting
au BufWritePre * :silent !mkdir -p %:p:h

imap <Tab> <Plug>snipMateNextOrTrigger
smap <Tab> <Plug>snipMateNextOrTrigger
vmap <Tab> <Plug>snipMateVisual

imap <S-Tab> <Plug>snipMateBack
smap <S-Tab> <Plug>snipMateBack

imap <C-s> <Plug>snipMateShow
let g:snipMate = { 'snippet_version': 1 }
let g:nnn#action = {
      \ '<c-t>': 'tab split',
      \ '<c-x>': 'split',
      \ '<c-v>': 'vsplit' }
let g:nnn#replace_netrw = 1
colorscheme wombat256

A universe/neovim/src/neovim.json => universe/neovim/src/neovim.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://github.com/neovim/neovim",
  "rev": "b79596eb5e942a299aa021a0f9a3f2db909294da",
  "date": "2021-03-27T19:02:48-07:00",
  "path": "/nix/store/lxmbhs4bcwzh3nck24i43v3h5r5szlg9-neovim",
  "sha256": "1frf4wphhm8ilbgizaj61zhs6srqj6akmc90xahvdqii5rkvhcwp",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

A universe/neovim/src/vim-bookmarks.json => universe/neovim/src/vim-bookmarks.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://github.com/MattesGroeger/vim-bookmarks",
  "rev": "3adeae10639edcba29ea80dafa1c58cf545cb80e",
  "date": "2017-12-16T17:08:10+01:00",
  "path": "/nix/store/mx8i92h88faqlb9kz8f6b1hjjvlhs6bl-vim-bookmarks",
  "sha256": "1ikgs5cnqs9bhr8fqan8hg14px1j331l0b51yhnx00rmj4lr44bm",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

A universe/neovim/src/vim-gemini.json => universe/neovim/src/vim-gemini.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://tildegit.org/sloum/gemini-vim-syntax",
  "rev": "596d1f36b386e5b2cc1af4f2f8285134626878d1",
  "date": "2021-02-14T05:22:28+00:00",
  "path": "/nix/store/rli90bds43z25y72a7jbzxbfdmbp0h0y-gemini-vim-syntax",
  "sha256": "1h5cq9fbv53nsjj66xrqmdiv0i1gqcvd0mfks3sdlnj0lzhbpip0",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

A universe/neovim/src/vim-nginx.json => universe/neovim/src/vim-nginx.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://github.com/chr4/nginx.vim",
  "rev": "7b8e3ef48d8e60fe64bb1a85be52e66dd412c84d",
  "date": "2021-02-25T21:15:08+00:00",
  "path": "/nix/store/camcbv45i4pkcgwb96yl5yl5yq2066ag-nginx.vim",
  "sha256": "00n3kx4gczryx968n0l7hqdxg6i4vfi3n3m4bdl5d3rwpbwdy6zy",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

A universe/neovim/src/vim-nnn.json => universe/neovim/src/vim-nnn.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://github.com/mcchrish/nnn.vim",
  "rev": "6408b859f9fac3880d82109d25874fb6656026d9",
  "date": "2021-03-22T08:03:54+08:00",
  "path": "/nix/store/w70d0d9p5bwsqa9qmjd3jlvgkdfafa9p-nnn.vim",
  "sha256": "0r5s89882hj54qyi5rcwmf8g54jkjmap5c2rd2mhfjs3j4dfny72",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

A universe/neovim/src/vim-pgsql.json => universe/neovim/src/vim-pgsql.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://github.com/lifepillar/pgsql.vim",
  "rev": "51521a89018efb58aa6c530b8426936e6e2a85a9",
  "date": "2021-02-07T11:15:35+01:00",
  "path": "/nix/store/17n6jdfvm9z70cfir19c0f09pxndz5ng-pgsql.vim",
  "sha256": "1m7n2c0jaczw5ii4cbq7xdv5aa3gddw0dhxa2j2cnwiyhc5kdlp4",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

A universe/neovim/src/vim-vidir.json => universe/neovim/src/vim-vidir.json +10 -0
@@ 0,0 1,10 @@
{
  "url": "https://github.com/trapd00r/vim-syntax-vidir-ls",
  "rev": "2b64ff03eb1a523fe0528e69804c5d19d8a809d7",
  "date": "2019-04-02T06:51:16+02:00",
  "path": "/nix/store/b57fqb0vk640q4hrah0pjkjsv6m8b2mg-vim-syntax-vidir-ls",
  "sha256": "14k1ka3x4sl86hb31b5ylhq41a2pd2szh09bldh1sqdnqqvlx3ii",
  "fetchSubmodules": false,
  "deepClone": false,
  "leaveDotGit": false
}

M universe/uenv/env.conf => universe/uenv/env.conf +1 -1
@@ 1,4 1,4 @@
EDITOR = vim
EDITOR = nvim
TZ = America/New_York
BROWSER = w3m
LANG = C.UTF-8