From c5fc5bc9bfb8858c9a8fdf2fd40a6372439ffd05 Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Sat, 18 Feb 2023 17:59:03 +0100 Subject: [PATCH] moved neovim config to lua and manage plugins with packer --- home/neovim/default.nix | 167 ++------------------------ home/neovim/init.lua | 260 ++++++++++++++++++++++++++++++++++++++++ home/neovim/init.vim | 231 ----------------------------------- home/nixos-common.nix | 4 +- 4 files changed, 272 insertions(+), 390 deletions(-) create mode 100644 home/neovim/init.lua delete mode 100644 home/neovim/init.vim diff --git a/home/neovim/default.nix b/home/neovim/default.nix index 8c93f77..5f4fda7 100644 --- a/home/neovim/default.nix +++ b/home/neovim/default.nix @@ -9,167 +9,18 @@ withPython3 = true; extraPackages = with pkgs; [ black - jq - # sqlfluff - nixfmt - shfmt + efm-langserver hlint - pylint + jq + lua54Packages.luacheck + nixfmt nodePackages.pyright + pylint + shfmt + stylua ]; extraPython3Packages = pyPkgs: with pyPkgs; [ pylint ]; - plugins = with pkgs.vimPlugins; - # find sha256 with: - # nix-prefetch-url --unpack https://github.com/${owner}/${repo}/archive/${rev}.tar.gz - let - nerdfont-vim = pkgs.vimUtils.buildVimPlugin { - pname = "nerdfont-vim"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "lambdalisue"; - repo = "nerdfont.vim"; - rev = "5f484cf638ca31fc9db95b33b92bf5aa4b2d1270"; - sha256 = "01lfqlsbs1192v0kydz98qypbvl6h3vkjjj5cl6zcadq52macl5s"; - }; - meta.homepage = "https://github.com/lambdalisue/nerdfont.vim"; - }; - fern-renderer-nerdfont = pkgs.vimUtils.buildVimPlugin { - pname = "fern-renderer-nerdfont"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "lambdalisue"; - repo = "fern-renderer-nerdfont.vim"; - rev = "942be10bda577ba4840c4a939200f05024b8603c"; - sha256 = "0nz5ycs9r9w0in3jjmcm121ik3jggj4mj3r88fmk8bw1jwl1hffm"; - }; - meta.homepage = - "https://github.com/lambdalisue/fern-renderer-nerdfont.vim"; - }; - glyph-palette = pkgs.vimUtils.buildVimPlugin { - pname = "glyph-palette"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "lambdalisue"; - repo = "glyph-palette.vim"; - rev = "a8ecb59733d8b4a2f45fdbcabf5174fdee18c4ec"; - sha256 = "0pzlwiyvrp994f5d9sw2vymdi1s5x7ywvwm0n4vmv3i9q9yyhxja"; - }; - meta.homepage = - "https://github.com/lambdalisue/fern-renderer-nerdfont.vim"; - }; - fern-git-status = pkgs.vimUtils.buildVimPlugin { - pname = "fern-git-status"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "lambdalisue"; - repo = "fern-git-status.vim"; - rev = "151336335d3b6975153dad77e60049ca7111da8e"; - sha256 = "1iqd035psn953v162didqd72cb7f0n7w34c2qsf15qkyq3y97pzl"; - }; - meta.homepage = "https://github.com/lambdalisue/fern-git-status.vim"; - }; - fern-mapping-git = pkgs.vimUtils.buildVimPlugin { - pname = "fern-mapping-git"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "lambdalisue"; - repo = "fern-mapping-git.vim"; - rev = "df5e7466df8596c95dd355d49a72893018919cf1"; - sha256 = "1lhppbydg9wlc520042k6bqvwblvmr7xx0w44s2xwbwbffj6hjz3"; - }; - meta.homepage = "https://github.com/lambdalisue/fern-mapping-git.vim"; - }; - fern-hijack = pkgs.vimUtils.buildVimPlugin { - pname = "fern-hijack"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "lambdalisue"; - repo = "fern-hijack.vim"; - rev = "24daa61d69b878947946e84a7711f8b58eae0f50"; - sha256 = "1z8zracqk52rar6wra7n1hlvfa1xqks1x0np7rs1aq9g7d02d6wg"; - }; - meta.homepage = "https://github.com/lambdalisue/fern-hijack.vim"; - }; - black-vim = pkgs.vimUtils.buildVimPlugin rec { - pname = "black-vim"; - version = "23.1.0"; - src = pkgs.fetchFromGitHub { - owner = "psf"; - repo = "black"; - rev = "refs/tags/${version}"; - sha256 = "08rvk15mrvpmmjw7zw1ixcgh3sx2knadzrpp21q8kamvbizbjp5f"; - }; - meta.homepage = "https://github.com/psf/black"; - }; - vim-tidal = pkgs.vimUtils.buildVimPlugin { - pname = "vim-tidal"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "tidalcycles"; - repo = "vim-tidal"; - rev = "7962ed7586db8f83fb02e89d60d1014c54719dd0"; - sha256 = "0krjn9zqcdnd5f4189djp4gbmsx0qf8hwlhfp9cd5xq19r8z3faw"; - }; - buildPhase = "# do nothing"; - }; - scvim = pkgs.vimUtils.buildVimPlugin { - pname = "scvim"; - version = "git"; - src = pkgs.fetchFromGitHub { - owner = "supercollider"; - repo = "scvim"; - rev = "4b738f8a13056e0a74227135ff928c0149d233eb"; - sha256 = "12ap94ygf9hv03ffcqa44l6h0gf714dx33yqkl6h06r834iff6ab"; - }; - meta.homepage = "https://github.com/psf/black"; - }; - - in [ # nix-env -f '' -qaP -A vimPlugins - FixCursorHold-nvim - airline - ale - csv - deoplete-nvim - easymotion - fern-vim - fugitive - fzf-vim - gitgutter - goyo - gruvbox-community - indentLine - limelight-vim - neoformat - neomake - nerdcommenter - rainbow - sensible - tmux-navigator - todo-txt-vim - ultisnips - vim-airline-themes - vim-css-color - vim-jinja - vim-ledger - vim-markdown - vim-nix - vim-slime - vim-smoothie - vim-snippets - vim-terraform - vim-unimpaired - vimwiki - - nerdfont-vim - fern-renderer-nerdfont - glyph-palette - fern-git-status - fern-mapping-git - fern-hijack - black-vim - vim-tidal - scvim - ]; - extraConfig = builtins.readFile ./init.vim; + plugins = [ pkgs.vimPlugins.packer-nvim ]; + extraLuaConfig = builtins.readFile ./init.lua; }; } diff --git a/home/neovim/init.lua b/home/neovim/init.lua new file mode 100644 index 0000000..d2e6428 --- /dev/null +++ b/home/neovim/init.lua @@ -0,0 +1,260 @@ +-- luacheck: globals vim + +require("packer").startup(function(use) + use("tpope/vim-sensible") + + use("vimwiki/vimwiki") + use("freitass/todo.txt-vim") + use("ledger/vim-ledger") + + use("Shougo/deoplete.nvim") + use("dense-analysis/ale") + + use("psliwka/vim-smoothie") + + -- navigation + use("easymotion/vim-easymotion") + use("tpope/vim-unimpaired") + use("tpope/vim-surround") + use("christoomey/vim-tmux-navigator") + + -- fern + use("lambdalisue/fern.vim") + use("lambdalisue/nerdfont.vim") + use("lambdalisue/fern-renderer-nerdfont.vim") + use("lambdalisue/glyph-palette.vim") + use("lambdalisue/fern-git-status.vim") + use("lambdalisue/fern-mapping-git.vim") -- to check + use("lambdalisue/fern-hijack.vim") + + -- airline + use("vim-airline/vim-airline") + use("vim-airline/vim-airline-themes") + + use("tpope/vim-fugitive") + use("airblade/vim-gitgutter") + + use("honza/vim-snippets") + use("SirVer/ultisnips") + + use("junegunn/fzf.vim") + + use("junegunn/goyo.vim") + use("junegunn/limelight.vim") + + use("preservim/nerdcommenter") + + use("luochen1990/rainbow") + use("ap/vim-css-color") + + use("Yggdroot/indentLine") + + use("gruvbox-community/gruvbox") + + -- language support + use("darrikonn/vim-gofmt") + use("Glench/Vim-Jinja2-Syntax") + use("preservim/vim-markdown") + use("LnL7/vim-nix") + use("hashivim/vim-terraform") + use("LaTeX-Box-Team/LaTeX-Box") + use("vito-c/jq.vim") + use("tpope/vim-haml") + use({ "psf/black", branch = "stable" }) + use("elzr/vim-json") + use("z0mbix/vim-shfmt") + use("ckipp01/stylua-nvim") + + use("jpalardy/vim-slime") + use("neovim/nvim-lspconfig") + use("lukas-reineke/lsp-format.nvim") +end) + +local o = vim.opt + +local function map(mode, shortcut, command) + vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true }) +end + +local function nmap(shortcut, command) + map("n", shortcut, command) +end + +--local function imap(shortcut, command) +-- map("i", shortcut, command) +--end + +o.wrap = false +o.number = true +o.compatible = false +o.mouse = "a" -- mouse support +o.showcmd = true -- show incomplete cmds down the bottom +o.showmode = true -- show current mode +o.showmatch = true -- set show matching parenthesis +o.visualbell = true -- no sounds +o.autoread = true -- reload files changed outside of vim +o.backspace = [[indent,eol,start]] -- allow backspacing over everything in insert mode +o.ignorecase = true -- ignore case when searching +o.shiftround = true -- use multiple of shiftwidth when indenting with '<' and '>' +o.smartcase = true -- ignore case if searching pattern is all lowecase, case-sensitive otherwise +o.smarttab = true -- insert tabs on the start of a line according to shiftwidth, not tabstop +o.hlsearch = true -- highlight search terms +o.incsearch = true -- show search matches as you type +o.hidden = true +o.ruler = true +o.clipboard = "unnamed" -- system clipboard +o.colorcolumn = "80" + +vim.cmd("syntax on") +vim.cmd("filetype plugin on") + +if vim.fn.has("multi_byte") == 1 and vim.o.encoding == "utf-8" then + o.listchars = [[tab:▸ ,extends:❯,precedes:❮,nbsp:±,trail:…]] +else + o.listchars = [[tab:> ,extends:>,precedes:<,nbsp:.,trail:_]] +end + +vim.g.mapleader = "," +vim.g.maplocaleader = "\\" + +o.splitbelow = true +o.splitright = true +nmap("", "r") + +nmap("", "1gt") +nmap("", "2gt") +nmap("", "3gt") +nmap("", "4gt") +nmap("", "5gt") +nmap("", "6gt") +nmap("", "7gt") +nmap("", "8gt") +nmap("", ":tablast") + +nmap("", ":nohl") + +-- todo: try to do it with `vim.api.nvim_set_hl` +vim.cmd("hi CursorLine cterm=NONE,underline ctermbg=NONE") -- highlight line when in insert mode + +o.timeoutlen = 1000 +o.ttimeoutlen = 0 + +vim.cmd("autocmd InsertEnter * :set cursorline") +vim.cmd("autocmd InsertLeave * :set nocursorline") + +-- indentation +vim.cmd("filetype indent on") +o.softtabstop = 4 +o.expandtab = true +o.shiftwidth = 4 +o.tabstop = 4 +o.autoindent = true +o.copyindent = true + +-- folds +o.foldmethod = "indent" +o.foldnestmax = 3 +o.foldenable = false + +o.termguicolors = true +vim.g.gruvbox_contrast_dark = "hard" +vim.g.gruvbox_contrast_light = "hard" +vim.g.gruvbox_italic = 1 +vim.g.gruvbox_invert_indent_guides = 1 +vim.g.gruvbox_vert_split = "bg1" +vim.cmd("colorscheme gruvbox") +o.background = "dark" + +vim.g.markdown_syntax_conceal = 0 + +o.updatetime = 100 -- to make gigutter more responsive + +vim.g["fern#renderer"] = "nerdfont" +vim.cmd([[ +function! s:init_fern() abort + nmap T (fern-action-open:tab) + nmap S (fern-action-open:split) + nmap V (fern-action-open:vsplit) + nmap (fern-action-mark:toggle) +endfunction + +augroup fern-custom + autocmd! * + autocmd FileType fern call s:init_fern() +augroup END + +augroup my-glyph-palette + autocmd! * + autocmd FileType fern call glyph_palette#apply() + autocmd FileType nerdtree,startify call glyph_palette#apply() +augroup END +]]) +nmap("t", ":Fern . -drawer -toggle") +nmap("f", ":Files") +nmap("rg", ":Rg") +nmap("", ": cd ..") +nmap("b", ": Buffers") + +vim.g["indentLine_char"] = "▏" +vim.g["indentLine_setConceal"] = 0 + +vim.g["slime_target"] = "tmux" +vim.g["slime_python_ipython"] = 1 + +vim.g["tmux_navigator_no_mappings"] = 1 +nmap("", ":TmuxNavigateLeft") +nmap("", ":TmuxNavigateDown") +nmap("", ":TmuxNavigateUp") +nmap("", ":TmuxNavigateRight") + +vim.g["airline_theme"] = "base16_gruvbox_dark_hard" +vim.g["airline#extensions#tabline#enabled"] = 1 +vim.g["airline#extensions#ale#enabled"] = 1 + +vim.g["ale_lint_on_text_changed"] = "never" +vim.g["ale_lint_on_insert_leave"] = 0 +vim.g["ale_lint_on_enter"] = 0 + +vim.g["deoplete#enable_at_startup"] = 1 + +-- vim.g["black_virtualenv"] = "/Users/rilla/virtualenvs/black" + +vim.g["shfmt_extra_args"] = "-i 4" +vim.g["NERDDefaultAlign"] = "left" + +vim.g["UltiSnipsExpandTrigger"] = "" +vim.g["UltiSnipsJumpForwardTrigger"] = "" +vim.g["UltiSnipsJumpBackwardTrigger"] = "" + +local formatters = { + go = ":GoFmt", + json = ":%!jq --indent 4 .", + nix = ":%!nixfmt < %", + -- python = ":Black", + python = [[lua vim.lsp.buf.format()]], + sh = ":Shfmt", + sql = ":%!sqlfluff fix -", + terraform = ":TerraformFmt", + lua = [[lua require("stylua-nvim").format_file()]], +} + +for pattern, command in pairs(formatters) do + vim.api.nvim_create_autocmd("FileType", { + pattern = pattern, + callback = function() + nmap("", command) + end, + }) +end + +require("lspconfig").pyright.setup({}) + +require("lspconfig").efm.setup({ + init_options = { documentFormatting = true }, + settings = { + rootMarkers = { ".git/", "pyproject.toml" }, + languages = { + python = { { formatCommand = "black -", formatStdin = true } }, + }, + }, +}) diff --git a/home/neovim/init.vim b/home/neovim/init.vim deleted file mode 100644 index ad0c6ae..0000000 --- a/home/neovim/init.vim +++ /dev/null @@ -1,231 +0,0 @@ -set nowrap -set nocompatible -syntax enable -filetype plugin on -set number -set mouse=a " mouse support -set showcmd " show incomplete cmds down the bottom -set showmode " show current mode -set visualbell " no sounds -set autoread " reload files changed outside vim -"set gcr=a:blinkon0 " disable cursor blink -set backspace=indent,eol,start " allow backspacing over everything in insert -mode -set shiftround " use multiple of shiftwidth when indenting with '<' and '>' -set showmatch " set show matching parenthesis -set ignorecase " ignore case when searching -set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise -set smarttab " insert tabs on the start of a line according to shiftwidth, not tabstop -set hlsearch " highlight search terms -set incsearch " show search matches as you type -set hidden -set ruler -set clipboard=unnamed " system clipboard -set list listchars=tab:\ \ ,trail:· " display tabs and trailing spaces visually -set colorcolumn=80 - -set splitbelow -set splitright -nmap r - -let mapleader="," -let maplocalleader="\\" - -" use alt-x to go to a specific tab -nnoremap 1gt -nnoremap 2gt -nnoremap 3gt -nnoremap 4gt -nnoremap 5gt -nnoremap 6gt -nnoremap 7gt -nnoremap 8gt -nnoremap :tablast - -" clean highlights when C-l -nnoremap :nohl - -" HIGHLIGHT LINE WHEN IN INSERT MODE -hi CursorLine cterm=NONE,underline ctermbg=NONE -set timeoutlen=1000 ttimeoutlen=0 " eliminate annoying delay -autocmd InsertEnter * :set cursorline -autocmd InsertLeave * :set nocursorline - -" INDENTATION: -filetype indent on -set softtabstop=4 -set expandtab -set shiftwidth=4 " number of spaces to use for autoindenting -set tabstop=4 " a tab is four spaces -set autoindent " always set autoindenting on -set copyindent " copy the previous indentation on autoindenting - -" TAG JUMPING: -command! MakeTags !ctags -R . -" - ^] to jump to tag under cursor -" - g^] for ambiguous tags -" - ^t to jump back up the tag stack - -" TURN OF SWAP FILES: -set noswapfile -set nobackup -set nowb - -"FOLDS: -set foldmethod=indent " fold based on indent -set foldnestmax=3 " deepest fold is 3 levels -set nofoldenable " don't fold by default - -" FINDING FILES: -set path+=** -set wildmenu -" - Hit tab to find for partial match -" - Use * to make it fuzzy - -let g:markdown_syntax_conceal = 0 - -set updatetime=100 " reduce vim update time so magke gitgutter more responsive - -set termguicolors - -"set fillchars+=vert:\ " cleaner vertical line - -"let g:gruvbox_contrast_dark="hard" -"let g:gruvbox_contrast_light="hard" -"let g:gruvbox_italic=1 -"let g:gruvbox_invert_indent_guides=1 -"let g:gruvbox_vert_split='bg1' - -let g:gruvbox_contrast_dark="hard" -set background=dark -colorscheme gruvbox - -let g:fern#renderer = "nerdfont" - -function! s:init_fern() abort - nmap T (fern-action-open:tab) - nmap S (fern-action-open:split) - nmap V (fern-action-open:vsplit) -endfunction - -augroup fern-custom - autocmd! * - autocmd FileType fern call s:init_fern() -augroup END - -augroup my-glyph-palette - autocmd! * - autocmd FileType fern call glyph_palette#apply() - autocmd FileType nerdtree,startify call glyph_palette#apply() -augroup END - -nnoremap t :Fern . -drawer -toggle -nnoremap f :Files -nnoremap rg :Rg -nnoremap :cd .. -nnoremap b :Buffers - -"let g:NERDTreeIndicatorMapCustom = { - "\ "Modified" : "✹", - "\ "Staged" : "✚", - "\ "Untracked" : "✭", - "\ "Renamed" : "➜", - "\ "Unmerged" : "═", - "\ "Deleted" : "✖", - "\ "Dirty" : "✗", - "\ "Clean" : "✔︎", - "\ 'Ignored' : '☒', - "\ "Unknown" : "?" - "\ } - -let g:indentLine_char = '▏' -"let g:indentLine_color_term = 2854 - -let g:indentLine_setConceal = 0 -"let g:indentLine_concealcursor="" - -let g:slime_target="tmux" -let g:slime_python_ipython=1 - -let g:tmux_navigator_no_mappings = 1 - -nnoremap :TmuxNavigateLeft -nnoremap :TmuxNavigateDown -nnoremap :TmuxNavigateUp -nnoremap :TmuxNavigateRight - -"let g:lightline = {'colorscheme': 'gruvbox'} -let g:limelight_conceal_ctermfg = 'DarkGray' - -" let g:vim_json_syntax_conceal = 0 - -let g:airline_theme='base16_gruvbox_dark_hard' -let g:airline#extensions#tabline#enabled = 1 -let g:airline#extensions#ale#enabled = 1 - -let g:ale_linters ={ - \ 'haskell': ['hlint', 'hdevtools', 'hfmt'], - \} -" let g:ale_python_auto_pipenv=1 " see ale-integrations-local-executables -"let g:ale_python_pylint_auto_pipenv=1 -" let g:ale_python_pylint_executable="pipenv" -let g:ale_python_pylint_change_directory=1 - -autocmd! User GoyoEnter Limelight -autocmd! User GoyoLeave Limelight!! - -" function LoadBraces (except) -" if (&ft != a:except) -" RainbowParenthesesLoadBraces -" endif -" endfunction -" -" " For rainbow parenhteses -" au VimEnter * RainbowParenthesesToggle -" au Syntax * RainbowParenthesesLoadRound -" au Syntax * RainbowParenthesesLoadSquare -" au Syntax * call LoadBraces('haskell') - -"autocmd! BufWritePost,BufEnter * Neomake - -let g:deoplete#enable_at_startup = 1 - -let g:rainbow_active = 1 - -let g:black_linelength=79 - -let g:NERDDefaultAlign = 'left' - -nnoremap i -inoremap -nnoremap a -inoremap - -nnoremap p "=system('xsel')p -nnoremap m :!make - -" CLOJURE -let g:clj_fmt_autosave = 0 -"autocmd FileType clojure nnoremap :hi Normal ctermbg=none -autocmd FileType clojure nnoremap :Eval -autocmd FileType clojure vnoremap :Eval -autocmd FileType clojure nnoremap :Eval (stop) -autocmd FileType clojure nnoremap :Cljfmt - -"set formatoptions+=w -"set tw=80 -"nnoremap Q gqip - -" au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4 - -let g:UltiSnipsExpandTrigger="" -let g:UltiSnipsJumpForwardTrigger="" -let g:UltiSnipsJumpBackwardTrigger="" - -autocmd FileType sql nnoremap :%!sqlfluff fix - -autocmd FileType sh nnoremap :Shfmt -autocmd FileType json nnoremap :%!jq --indent 4 . -autocmd FileType terraform nnoremap :TerraformFmt -autocmd FileType nix nnoremap :%!nixfmt < % -" autocmd FileType python nnoremap :Black -autocmd FileType python nnoremap :!black % diff --git a/home/nixos-common.nix b/home/nixos-common.nix index dc17baa..67db18e 100644 --- a/home/nixos-common.nix +++ b/home/nixos-common.nix @@ -55,6 +55,7 @@ ./browsers ./cheat ./dav + ./drawterm ./fonts ./git ./gotify @@ -119,6 +120,7 @@ ".config/chromium" ".config/kdeconnect" ".config/kicad" + ".config/nvim/plugin" ".config/syncthing" ".config/tea" ".config/whatsapp-for-linux" @@ -132,6 +134,7 @@ ".local/share/Steam" ".local/share/SuperCollider" ".local/share/TelegramDesktop" + ".local/share/nvim" { directory = ".local/share/containers"; method = "symlink"; @@ -180,7 +183,6 @@ ansible bind.dnsutils docker-compose - drawterm file gimp gnumake