From 93fadc0cbdcf9d9993e7f62c773b78ee3712ae58 Mon Sep 17 00:00:00 2001 From: hedy Date: Fri, 30 Jun 2023 22:04:37 +0800 Subject: [PATCH] BREAKING (nvim): Use lua config - LazyVim - Replaced many plugins with lua versions - So much faster! - Added devicons - And more! --- .config/nvim/autocmds.vim | 3 - .config/nvim/coc.vim | 107 --------- .config/nvim/ftdetect/moon.vim | 1 + .config/nvim/ftplugin/moon.vim | 3 + .config/nvim/functions.vim | 1 - .config/nvim/general.vim | 105 --------- .config/nvim/init.lua | 10 + .config/nvim/init.vim | 11 - .config/nvim/lua/autocmds.lua | 0 .config/nvim/lua/autopair.lua | 12 - .config/nvim/lua/general.lua | 62 +++++ .config/nvim/lua/linting.lua | 6 - .config/nvim/lua/loadlazy.lua | 12 + .config/nvim/lua/mappings.lua | 118 ++++++++++ .config/nvim/lua/plugin_spec.lua | 130 ++++++++++ .config/nvim/lua/plugins/autopair.lua | 5 + .config/nvim/lua/{ => plugins}/complete.lua | 27 ++- .config/nvim/lua/plugins/icons.lua | 40 ++++ .config/nvim/lua/plugins/linting.lua | 12 + .config/nvim/lua/{ => plugins}/lsp.lua | 41 ++-- .config/nvim/lua/plugins/statusline.lua | 74 ++++++ .config/nvim/mappings.vim | 103 -------- .config/nvim/plugins.vim | 248 -------------------- 23 files changed, 512 insertions(+), 619 deletions(-) delete mode 100644 .config/nvim/autocmds.vim delete mode 100644 .config/nvim/coc.vim create mode 100644 .config/nvim/ftdetect/moon.vim create mode 100644 .config/nvim/ftplugin/moon.vim delete mode 100644 .config/nvim/functions.vim delete mode 100644 .config/nvim/general.vim create mode 100644 .config/nvim/init.lua delete mode 100644 .config/nvim/init.vim create mode 100644 .config/nvim/lua/autocmds.lua delete mode 100644 .config/nvim/lua/autopair.lua create mode 100644 .config/nvim/lua/general.lua delete mode 100644 .config/nvim/lua/linting.lua create mode 100644 .config/nvim/lua/loadlazy.lua create mode 100644 .config/nvim/lua/mappings.lua create mode 100644 .config/nvim/lua/plugin_spec.lua create mode 100644 .config/nvim/lua/plugins/autopair.lua rename .config/nvim/lua/{ => plugins}/complete.lua (68%) create mode 100644 .config/nvim/lua/plugins/icons.lua create mode 100644 .config/nvim/lua/plugins/linting.lua rename .config/nvim/lua/{ => plugins}/lsp.lua (85%) create mode 100644 .config/nvim/lua/plugins/statusline.lua delete mode 100644 .config/nvim/mappings.vim delete mode 100644 .config/nvim/plugins.vim diff --git a/.config/nvim/autocmds.vim b/.config/nvim/autocmds.vim deleted file mode 100644 index 6940e31..0000000 --- a/.config/nvim/autocmds.vim +++ /dev/null @@ -1,3 +0,0 @@ -if has("nvim-0.6") - au BufWritePost lua require('lint').try_lint() -endif diff --git a/.config/nvim/coc.vim b/.config/nvim/coc.vim deleted file mode 100644 index 9a7947d..0000000 --- a/.config/nvim/coc.vim +++ /dev/null @@ -1,107 +0,0 @@ -" NOTE: To be deprecated in the future -" -" This file is only executed if we don't have nvim-0.5, if we do, lua LSP will -" be used instead. See plugins.vim -" -" ============== -" CoC Settings -" ============== - -" === coc installs === -" TODO: Track .config/coc in dotfiles so I can remove this -" coc-go -" coc-html -" coc-snippets -" coc-python -" coc-marketplace - -" coc-yank -nnoremap y :CocList -A --normal yank - -" Below is mostly or completely copied from coc's readme - -" Use tab for trigger completion with characters ahead and navigate. -" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by -" other plugin before putting this into your config. -inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ coc#refresh() -inoremap pumvisible() ? "\" : "\" - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use to trigger completion. -inoremap coc#refresh() - -" Use to confirm completion, `u` means break undo chain at current -" position. Coc only does snippet and additional edit on confirm. -" could be remapped by other vim plugin, try `:verbose imap `. -if exists('*complete_info') - inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" -else - inoremap pumvisible() ? "\" : "\u\" -endif - -" Use `[g` and `]g` to navigate diagnostics -nmap [g (coc-diagnostic-prev) -nmap ]g (coc-diagnostic-next) - -" GoTo code navigation. -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use K to show documentation in preview window. -nnoremap K :call show_documentation() - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction - -" Highlight the symbol and its references when holding the cursor. -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Symbol renaming. -nmap (coc-rename) - -" Formatting selected code. -xmap f (coc-format-selected) -nmap f (coc-format-selected) - - -" Add `:Format` command to format current buffer. -command! -nargs=0 Format :call CocAction('format') - -" Add `:Fold` command to fold current buffer. -command! -nargs=? Fold :call CocAction('fold', ) - -" Add `:OR` command for organize imports of the current buffer. -command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') - -" Mappings using CoCList: -" Show all diagnostics. -nnoremap a :CocList diagnostics -" Manage extensions. -nnoremap e :CocList extensions -" Show commands. -nnoremap c :CocList commands -" Find symbol of current document. -nnoremap o :CocList outline -" Search workspace symbols. -nnoremap s :CocList -I symbols -" Do default action for next item. -nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev -" Resume latest coc list. -nnoremap p :CocListResume - diff --git a/.config/nvim/ftdetect/moon.vim b/.config/nvim/ftdetect/moon.vim new file mode 100644 index 0000000..c9eb8f6 --- /dev/null +++ b/.config/nvim/ftdetect/moon.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.moon set filetype=moon diff --git a/.config/nvim/ftplugin/moon.vim b/.config/nvim/ftplugin/moon.vim new file mode 100644 index 0000000..8a2075f --- /dev/null +++ b/.config/nvim/ftplugin/moon.vim @@ -0,0 +1,3 @@ +setl tabstop=2 +setl shiftwidth=2 +setl softtabstop=2 diff --git a/.config/nvim/functions.vim b/.config/nvim/functions.vim deleted file mode 100644 index 36858b5..0000000 --- a/.config/nvim/functions.vim +++ /dev/null @@ -1 +0,0 @@ -source $HOME/iswsl.vim diff --git a/.config/nvim/general.vim b/.config/nvim/general.vim deleted file mode 100644 index 38dab91..0000000 --- a/.config/nvim/general.vim +++ /dev/null @@ -1,105 +0,0 @@ -" ================ -" General settings -" ================ - -set number " Relative number lines can be toggled, see mappings.vim -set mouse=a " allow mouse for all; TODO: I rarely use mouse (duh) so maybe remove this -set cursorline " highlight current cursor line (this is SO GOOD) -set showcmd " show incomplete commands -set hlsearch " highlight search -set wildmenu " command line's tab complete in a menu -set noerrorbells " no beeps please -set visualbell " flash screen instead -set title " set window title to file name -set incsearch " incrementally find next match while typing search -set scrolloff=6 " screen lines to keep above and below cursor -set sidescrolloff=8 " screen columns to keep on left and right of cursor -set confirm " display confirmation when closing unsaved file -set encoding=utf-8 " set encoding with Unicode -set showmatch " match brackets when cursor is over it -set mat=2 " how many tenths of second to blink when matching brackets -set inccommand=nosplit " neovim only - -" Indenting -set autoindent " Keep indentation from previous line when RET (I think) -set expandtab " AIUI, tab -> spaces -set softtabstop=4 " indent by 2 spaces with tab -set tabstop=4 " show existing tabs with 4 spaces width -set shiftwidth=4 " Put or remove 4 spaces with using < and > -set smarttab " Delete spaces at tabstop width -set copyindent " Copy indentation from previous line - -" Settings required from coc -" Still keeping this if we're using lua+lsp instead of CoC because why not -set hidden " Let's you switch to another file while current is unsaved. -set cmdheight=2 -" set updatetime=300 " This is horrible - can't even finish reading those -" messages before they disappear! -" set shortmess+=c " This wouldve disabled ins-completion-menu messages -" (see :help shortmes) -" Always show the signcolumn, otherwise it would shift the text each time -" diagnostics appear/become resolved. -if has("patch-8.1.1564") - " Recently vim can merge signcolumn and number column into one - set signcolumn=number -else - set signcolumn=yes -endif - -" Bunch of shit really, spent *hours* trying to get tmux + nvim true colors to work -" TODO: check has('termguicolors') and set a env var or something -set termguicolors - -" Let and h, l keys be able to move to previous or next line -" when currently on start or end of line respectively -set whichwrap+=<,>,h,l - -" fold settings -set foldenable -set foldlevelstart=10 -set foldnestmax=10 -set foldmethod=manual -set foldcolumn=2 - -" Set the swp, backup and undo settings -set noswapfile -set nobackup nowritebackup -set undodir=~/.local/share/nvim/undodir/ -set undofile - -" Ignore compiled files -set wildignore=*.o,*~,*.pyc -if has("win16") || has("win32") - set wildignore+=.git\*,.hg\*,.svn\* -else - set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store -endif - -" Return to last edit position when opening files -au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif - -" highlight trailing whitespace -match ErrorMsg '\s\+$' - -" setting the shell for fish to bash -if &shell =~# 'fish$' - set shell=bash -endif - -" IsWSL function sourced in functions.vim, declared in ~/iswsl.vim -" I think this is a neovim-only thing, +1 for neovim :smirk: -if IsWSL() - let g:clipboard = { - \ 'name': 'WSLClip', - \ 'copy': { - \ '+': 'clip.exe', - \ '*': 'clip.exe', - \ }, - \ 'paste': { - \ '+': 'pbpaste', - \ '*': 'pbpaste', - \ }, - \ 'cache_enabled': 0, - \ } -endif - diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..d43d6ca --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,10 @@ +vim.g.mapleader = [[ ]] +vim.g.maplocalleader = [[;]] +-- The cool thing about ';' is that it is at the same +-- position as ':', the char used for commands. + +require('loadlazy') + +require('general') +require('mappings') +require('autocmds') diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim deleted file mode 100644 index aa08497..0000000 --- a/.config/nvim/init.vim +++ /dev/null @@ -1,11 +0,0 @@ -set nocompatible -let mapleader=";" " setting leader key to ';' -nmap , ; -" ',' as leader key is useful in some occasions. - -source $HOME/.config/nvim/functions.vim -source $HOME/.config/nvim/general.vim -source $HOME/.config/nvim/mappings.vim -source $HOME/.config/nvim/autocmds.vim -source $HOME/.config/nvim/plugins.vim - diff --git a/.config/nvim/lua/autocmds.lua b/.config/nvim/lua/autocmds.lua new file mode 100644 index 0000000..e69de29 diff --git a/.config/nvim/lua/autopair.lua b/.config/nvim/lua/autopair.lua deleted file mode 100644 index 89db6ed..0000000 --- a/.config/nvim/lua/autopair.lua +++ /dev/null @@ -1,12 +0,0 @@ -require('nvim-autopairs').setup({ - enable_check_bracket_line = false, -- Don't close pair when next char is a closing pair - ignored_next_char = "[%w%.]", -- will ignore alphanumeric and `.` symbol -}) - --- require("nvim-autopairs.completion.compe").setup({ --- map_cr = true, -- map on insert mode --- map_complete = true, -- it will auto insert `(` after select function or method item --- auto_select = false, -- auto select first item --- }) - --- TODO: add fastwrap and other stuff support diff --git a/.config/nvim/lua/general.lua b/.config/nvim/lua/general.lua new file mode 100644 index 0000000..5724e99 --- /dev/null +++ b/.config/nvim/lua/general.lua @@ -0,0 +1,62 @@ +local o = vim.opt + +o.number = true +o.mouse = "a" + +o.cursorline = true -- highlight current cursor line (this is SO GOOD) +o.showcmd = true -- show incomplete commands +o.hlsearch = true -- highlight search +o.wildmenu = true -- command line's tab complete in a menu +o.errorbells = false-- no beeps please +o.visualbell = true -- flash screen instead +o.title = true -- set window title to file name +o.incsearch = true -- incrementally find next match while typing search +o.scrolloff = 6 -- screen lines to keep above and below cursor +o.sidescrolloff = 8 -- screen columns to keep on left and right of cursor +o.confirm = true +o.showmatch = true + +o.encoding = "utf-8" +o.mat = 2 +o.inccommand = "nosplit" -- neovim only +o.autoindent = true +o.fileformat = "unix" + +o.expandtab = true-- AIUI, tab -> spaces +o.softtabstop = 4 -- indent by 2 spaces with tab +o.tabstop = 4 -- show existing tabs with 4 spaces width +o.shiftwidth=4 -- Put or remove 4 spaces with using < and > +o.smarttab = true -- Delete spaces at tabstop width +o.copyindent = true -- Copy indentation from previous line +o.hidden = true -- Let's you switch to another file while current is unsaved. +o.cmdheight = 2 + +-- Show LSP W/E hints on another column next to the line numbers +o.signcolumn = "yes" -- Set to "number" will merge the LSP W/E hints with the number col + +-- Bunch of shit really, spent *hours* trying to get tmux + nvim true colors to work +o.termguicolors = true +o.whichwrap:append '<,>,h,l' + +-- fold settings +o.foldenable = true +o.foldlevelstart = 10 +o.foldnestmax = 10 +o.foldmethod = "manual" +o.foldcolumn = "2" + +-- Set the swp, backup and undo settings +o.swapfile = false +o.backup = false +o.undodir = vim.fn.expand("~") .. "/.local/share/nvim/undodir/" +o.undofile = true + +-- Ignore compiled files +o.wildignore = { "*.o", "*~", "*.pyc", "*/.git/*", "*/.hg/*", "*/.svn/*", "*/.DS_Store" } + +-- Return to last edit position when opening files +vim.api.nvim_create_autocmd("BufReadPost", { + pattern = "*", command = [[if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif]] +}) + +vim.cmd [[ match ErrorMsg '\s\+$' ]] diff --git a/.config/nvim/lua/linting.lua b/.config/nvim/lua/linting.lua deleted file mode 100644 index 316b14e..0000000 --- a/.config/nvim/lua/linting.lua +++ /dev/null @@ -1,6 +0,0 @@ --- https://github.com/errata-ai/vale/releases -require('lint').linters_by_ft = { - markdown = {'codespell',}, - lua = {'luacheck',}, - python = {'codespell',}, -} diff --git a/.config/nvim/lua/loadlazy.lua b/.config/nvim/lua/loadlazy.lua new file mode 100644 index 0000000..58884e1 --- /dev/null +++ b/.config/nvim/lua/loadlazy.lua @@ -0,0 +1,12 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", "clone", "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", "--branch=stable", + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) +vim.opt.completeopt = { "menuone", "noinsert", "noselect", "preview" } + +require('lazy').setup('plugin_spec') diff --git a/.config/nvim/lua/mappings.lua b/.config/nvim/lua/mappings.lua new file mode 100644 index 0000000..3bf21a8 --- /dev/null +++ b/.config/nvim/lua/mappings.lua @@ -0,0 +1,118 @@ +local silent = { silent = true } +local function map(...) vim.keymap.set(...) end +-- ==============-= +-- Leader mappings +-- =============== +map("n", "rn", 'set relativenumber!') +-- Open all folds in current buffer (Reduce) +map("n", "z", "zR") +-- The 3 mappings that I use most often out of all vim mappings :D +map("n", "w", "w") +map("n", "x", "xa") +map("n", "q", "qa") +-- Clear search +map("n", "nh", "noh") +-- Paste (rarely used because I commonly work in ssh'ed environments) +map("n", "pa", "+p") +-- Show what registers contain +map("n", "rg", "registers") + + +-- ============================= +-- Normal and Universal Mappings +-- ============================= +-- Close a buffer, useful when doing PlugInstall and then closing that +-- Or is it close a window? frame? DAMN all this emacs terminology got me so +-- confused +map("n", "Q", "q") + +-- NOTE: These mappings Just Work in wsl so no need the extra binding like +-- in vimrc, this is why you use neovim instead of vim ;) +map("", "", "m+1==") +map("", "", "m-2==") +map("", "", "t.==") +map("", "", "t.-1==") + +-- =============== +-- VIsual mappings +-- =============== +-- dot command in visual mode +map("v", ".", "normal.") + +-- Move visual selection +map("v", "J", "m '>+1gv=gv") +map("v", "K", "m '<-2gv=gv") + +-- Visual mode pressing * or # searches for the current selection +map("v", "*", "call VisualSelection('', '')/=@/", silent) +map("v", "#", "call VisualSelection('', '')?=@/", silent) + +-- Keep text selected after indentation +-- This is... really useful sometimes but annoying other times +map("v", "<", "", ">gv") + + +-- ========================== +-- Window/Buffer/Tab mappings +-- ========================== +-- Better way to move between windows +map("", "", "j") +map("", "", "k") +map("", "", "h") +map("", "", "l") + +-- Managing buffers +-- map("n", "bd", "bd") -- I now use moll/vim-bbye, see plugin_spec.lua +map("n", "bn", "bnext") +map("n", "bp", "bprev") + +-- Useful mappings for managing tabs +-- Tab create +map("n", "tc", "tabnew") +map("n", "to", "tabonly") +-- Tab delete +map("n", "td", "tabclose") +-- I rarely have >3 tabs, let alone organize their placements D but it's here +-- because why not +map("n", "tm", "tabmove") +-- Switching tabs +map("n", "tn", "tabnext") +map("n", "tp", "tabprev") + + +if vim.fn.has("macunix") == 1 then + -- WTF?? (I checked using C-v in insert mode) + -- TODO: Fix in tmux + map("", "", "split term://fishi") +else + map("", "", "split term://fishi") +end +map("n", "t", "echom 'Deprecated. Please use C-` instead'") +map("t", "", "") + +-- SHUSH +map("n", "lsh", "LspStop") +map("n", "lst", "LspStart") + + +vim.api.nvim_create_autocmd("BufReadPost", { + pattern = "*", + callback = function() + vim.b.lsp_lines_enabled = false + end +}) + +map("n", "lx", function() + require("lsp_lines").toggle() + -- Disable virtual_text since it's redundant due to lsp_lines. + if vim.b.lsp_lines_enabled then + -- IT was enabled, now it's disabled. + vim.diagnostic.config({ virtual_text = true }) + vim.b.lsp_lines_enabled = false + else + vim.diagnostic.config({ virtual_text = false }) + vim.b.lsp_lines_enabled = true + end + end +) diff --git a/.config/nvim/lua/plugin_spec.lua b/.config/nvim/lua/plugin_spec.lua new file mode 100644 index 0000000..2e997a8 --- /dev/null +++ b/.config/nvim/lua/plugin_spec.lua @@ -0,0 +1,130 @@ +-- Used by Lazy.nvim in loadlazy.lua +return { + { "dracula/vim", name = "dracula", init = function() + -- THE most important nvim configuration + vim.cmd("colorscheme dracula") + end }, + { + "nvim-tree/nvim-tree.lua", + config = function() + require("nvim-tree").setup({ + view = { width = 20, }, + -- renderer = { group_empty = true, }, + -- filters = { dotfiles = true, }, + }) + end + }, + "tpope/vim-fugitive", + "jreybert/vimagit", -- emacs' magit ✨ + "tpope/vim-surround", -- quoting and parenthesizing manipulation + "tpope/vim-commentary", -- I'd rather not clog mappings with nerd commentor + "airblade/vim-gitgutter", -- Show git diff overview stuff in the left column + { -- Quickly jump to a symbol in buffer (one of my most used). Requires exuberant ctags + "majutsushi/tagbar", + config = function() + vim.keymap.set("n", "tt", "TagbarToggle") + vim.g.tagbar_width = 20 + end, + }, + "bling/vim-bufferline", -- I prefer this over taking over the tabline space thanks + "tpope/vim-endwise", -- Add those 'endif'/'fi'/'done' + { "moll/vim-bbye", -- smart buffer closer + config = function() + vim.keymap.set("n", "bd", "Bdelete") + vim.keymap.set("n", "bx", "Bwipeout") -- like bd but removes from jumplist + end + }, + { + "nvim-tree/nvim-web-devicons", lazy = true, + enabled = vim.fn.has("nvim-0.7") == 1, + config = function() require('plugins/icons') end, + }, + { -- STATUS LINE + "nvim-lualine/lualine.nvim", + dependencies = { 'nvim-tree/nvim-web-devicons', opt = true }, + config = function() require('plugins/statusline') end, + }, + { -- Neat popout window to browse dirs and manipulate within the editor! + "echasnovski/mini.files", + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() require('mini.files').setup() end, + }, + { + "lukas-reineke/indent-blankline.nvim", + config = function() + require("indent_blankline").setup({ + -- These require treesitter + -- show_current_context = true, + -- show_current_context_start = true, + }) + end, + }, + + --- File type, syntax, language helper plugins --- + { + url = "https://git.sr.ht/~torresjrjr/gemini.vim", + -- ft = "gemini", + }, + { "cespare/vim-toml", }, + { "blankname/vim-fish", }, + { + url = "https://git.rawtext.club/slope-lang/slope-vim-syntax", + -- ft = "slope", + }, + { "mzlogin/vim-markdown-toc", }, + { "leafo/moonscript-vim", }, + + ------ LSP and autopair plugins ------ + -- This plugin below is really good, but whenever I'm on a commented line, + -- press o, press backspace, the line below is joined up above. You won't + -- believe how long it took me to debug this problem and finally realize it's + -- because of this plugin. + -- "jiangmiao/auto-pairs", + -- + -- So now I'm using this instead: + -- windwp/nvim-autopairs - extremely customizable, written in lua - + -- integrates wth hrsh7th/nvim-cmp + -- For nvim < 0.5, use: townk/vim-autoclose + "nvim-lua/plenary.nvim", -- Helper lua functions many plugins depend on + { + "mfussenegger/nvim-lint", enabled = vim.fn.has("nvim-0.6") == 1, + config = function() require("plugins/linting") end, + + }, + { "windwp/nvim-autopairs", commit = vim.fn.has("nvim-0.7") == 1 and "b7672cd", + config = function() require("plugins/autopair") end, + }, + + -- Best IDE autocomplete setup ever + -- Please see ./lua/complete.lua + { "neovim/nvim-lspconfig", config = function() require('plugins/lsp') end }, + { "hrsh7th/cmp-nvim-lsp", dependencies = "neovim/nvim-lspconfig" }, + -- Completions of words in current buffer + { "hrsh7th/cmp-buffer", dependencies = "hrsh7th/nvim-cmp" }, + -- File paths + { "hrsh7th/cmp-path", dependencies = "hrsh7th/nvim-cmp" }, + -- Fire your way through the neovim cmd line + { "hrsh7th/cmp-cmdline", dependencies = "hrsh7th/nvim-cmp" }, + { "hrsh7th/cmp-calc", dependencies = "hrsh7th/nvim-cmp" }, + -- 😏 :smirk: + { "hrsh7th/cmp-emoji", dependencies = "hrsh7th/nvim-cmp" }, + { "mtoohey31/cmp-fish", dependencies = "hrsh7th/nvim-cmp" }, + { "petertriho/cmp-git", dependencies = "hrsh7th/nvim-cmp" }, + -- τ long live \tau + { "kdheepak/cmp-latex-symbols", dependencies = "hrsh7th/nvim-cmp" }, + { "dcampos/nvim-snippy", enabled = vim.fn.has("nvim-0.7") == 1 }, + { "dcampos/cmp-snippy", + enabled = vim.fn.has("nvim-0.7") == 1, + dependencies = {"hrsh7th/nvim-cmp", "dcampos/nvim-snippy"}, + }, + { "hrsh7th/nvim-cmp", config = function() require('plugins/complete') end }, + + "onsails/lspkind.nvim", -- Symbols in the completion + { + "https://git.sr.ht/~whynothugo/lsp_lines.nvim", + config = function() + require("lsp_lines").setup() + vim.diagnostic.config({ virtual_lines = false }) + end, + }, +} diff --git a/.config/nvim/lua/plugins/autopair.lua b/.config/nvim/lua/plugins/autopair.lua new file mode 100644 index 0000000..b202ba2 --- /dev/null +++ b/.config/nvim/lua/plugins/autopair.lua @@ -0,0 +1,5 @@ +require('nvim-autopairs').setup({ + enable_check_bracket_line = false, -- Don't close pair when next char is a closing pair + ignored_next_char = "[%w%.]", -- will ignore alphanumeric and `.` symbol + fast_wrap = {}, +}) diff --git a/.config/nvim/lua/complete.lua b/.config/nvim/lua/plugins/complete.lua similarity index 68% rename from .config/nvim/lua/complete.lua rename to .config/nvim/lua/plugins/complete.lua index 9d42afb..9dc922a 100644 --- a/.config/nvim/lua/complete.lua +++ b/.config/nvim/lua/plugins/complete.lua @@ -8,8 +8,27 @@ cmp.setup({ end, }, window = { - completion = cmp.config.window.bordered(), - documentation = cmp.config.window.bordered(), + completion = { + border = "shadow", + -- winhighlight = "Normal:CmpNormal", + }, + documentation = { + border = "shadow", + -- winhighlight = "Normal:CmpDocNormal", + } + }, + formatting = { + format = function(entry, vim_item) + if vim.tbl_contains({ 'path' }, entry.source.name) then + local icon, hl_group = require('nvim-web-devicons').get_icon(entry:get_completion_item().label) + if icon then + vim_item.kind = icon + vim_item.kind_hl_group = hl_group + return vim_item + end + end + return require('lspkind').cmp_format({ with_text = false })(entry, vim_item) + end }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), @@ -79,3 +98,7 @@ cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done() ) + +-- Set the completion item color of unmatched portion to white +-- Somehow it is set to black by default ever since I switched my config to lua. +vim.api.nvim_set_hl(0, "CmpItemAbbr", { fg=vim.g['dracula#palette.fg'] }) diff --git a/.config/nvim/lua/plugins/icons.lua b/.config/nvim/lua/plugins/icons.lua new file mode 100644 index 0000000..ff55133 --- /dev/null +++ b/.config/nvim/lua/plugins/icons.lua @@ -0,0 +1,40 @@ +-- Remember to install the Symbols Only font zip, then configure terminal to +-- use that font too. +-- Used by lazy, nvim-tree, and others + +-- https://github.com/nvim-tree/nvim-web-devicons +require'nvim-web-devicons'.setup { + -- your personnal icons can go here (to override) + -- you can specify color or cterm_color instead of specifying both of them + -- DevIcon will be appended to `name` + -- + -- globally enable different highlight colors per icon (default to true) + -- if set to false all icons will have the default icon's color + color_icons = true; + -- globally enable default icons (default to false) + -- will get overriden by `get_icons` option + -- default = true; + -- globally enable "strict" selection of icons - icon will be looked up in + -- different tables, first by filename, and if not found by extension; this + -- prevents cases when file doesn't have any extension but still gets some icon + -- because its name happened to match some extension (default to false) + strict = true; + -- same as `override` but specifically for overrides by filename + -- takes effect when `strict` is true + override_by_filename = { + [".gitignore"] = { + icon = "", + color = "#f1502f", -- Add the color so it's readable + name = "Gitignore" + } + }; + -- same as `override` but specifically for overrides by extension + -- takes effect when `strict` is true + -- override_by_extension = { + -- ["log"] = { + -- icon = "", + -- color = "#81e043", + -- name = "Log" + -- } + -- }; +} diff --git a/.config/nvim/lua/plugins/linting.lua b/.config/nvim/lua/plugins/linting.lua new file mode 100644 index 0000000..9683112 --- /dev/null +++ b/.config/nvim/lua/plugins/linting.lua @@ -0,0 +1,12 @@ +-- https://github.com/errata-ai/vale/releases +local lint = require('lint') +lint.linters_by_ft = { + markdown = {'codespell'}, + python = {'codespell'}, + mail = {'proselint'}, + template = {'proselint'}, + c = {'cpplint'}, + cpp = {'cpplint'}, +} + +vim.api.nvim_create_autocmd("BufWritePost", { pattern = "*", callback = function() lint.try_lint() end }) diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/plugins/lsp.lua similarity index 85% rename from .config/nvim/lua/lsp.lua rename to .config/nvim/lua/plugins/lsp.lua index e91737b..fa83792 100644 --- a/.config/nvim/lua/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -59,6 +59,7 @@ local servers = { "bashls", -- sudo npm i -g bash-language-server "vimls", -- sudo npm i -g vim-language-server "marksman", -- https://github.com/artempyanykh/marksman/releases + "ccls", -- https://github.com/MaskRay/ccls/wiki } for _, lsp in pairs(servers) do lspconfig[lsp].setup { @@ -76,7 +77,6 @@ lspconfig.pylsp.setup{ on_attach = on_attach, capabilities = capabilities, settings = { - -- formatCommand = {"black"}, pylsp = { plugins = { pylint = { enabled = true }, @@ -112,24 +112,23 @@ lspconfig.gopls.setup{ usePlaceholders = true, } } --- https://github.com/sumneko/lua-language-server/wiki/Getting-Started#command-line --- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua -lspconfig.sumneko_lua.setup { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = {'vim'}, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - telemetry = { enable = false }, - }, - }, +-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#lua_ls +lspconfig.lua_ls.setup { + settings = { + Lua = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + runtime = { version = 'LuaJIT' }, + -- Get the language server to recognize the `vim` global + diagnostics = { + globals = {'vim'}, + }, + -- Make the server aware of Neovim runtime files + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { enable = false }, + }, + }, } diff --git a/.config/nvim/lua/plugins/statusline.lua b/.config/nvim/lua/plugins/statusline.lua new file mode 100644 index 0000000..648bbbd --- /dev/null +++ b/.config/nvim/lua/plugins/statusline.lua @@ -0,0 +1,74 @@ +local function lineinfo() + local total = tostring(vim.fn.line('$')) + -- Left pad the current line count to max width of this value, to avoid jittering + return string.format("%"..total:len().."d", vim.fn.line('.'))..'/'..total +end + +local diagnostics_config = { + 'diagnostics', + symbols = {error = 'E:', warn = 'W:', info = 'I:', hint = 'H:'}, +} + +require('lualine').setup { + options = { + icons_enabled = true, + theme = 'auto', + component_separators = { left = '/', right = '/'}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {{ 'mode', fmt = function(str) + if str == "NORMAL" then + return "NORM" + elseif str == "INSERT" then + return "INS" + elseif str == "COMMAND" then + return "CMD" + elseif str == "VISUAL" then + return "VIS" + elseif str == "REPLACE" then + return "REP" + elseif str == "VISUAL BLOCK" then + return "VBL" + elseif str == "TERMINAL" then + return "TERM" + elseif str == "SUBSTITUTE" then + return "SUB" + end + return str + end }}, + lualine_b = {'branch', 'diff'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', { 'fileformat', + icons_enabled = true, + symbols = { unix = 'LF', dos = 'CRLF', mac = 'CR', }, + }, 'filetype'}, + lualine_y = {diagnostics_config}, + lualine_z = {lineinfo}, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {'brach', 'diff'}, + lualine_c = {'filename'}, + lualine_x = {diagnostics_config}, + lualine_y = {'searchcount'}, + lualine_z = {lineinfo}, + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {'nvim-tree'}, +} + diff --git a/.config/nvim/mappings.vim b/.config/nvim/mappings.vim deleted file mode 100644 index 2c06c67..0000000 --- a/.config/nvim/mappings.vim +++ /dev/null @@ -1,103 +0,0 @@ -" ======== -" Mappings -" ======== - -" === Leader Mappings === -" Leader is mapped to ';' in init.vim -" Toggle relative number -nnoremap rn :set relativenumber! -" Open all folds in current buffer (Reduce) -nnoremap z zR -" The 3 mappings that I use most often out of all vim mappings :D -nnoremap w :w -nnoremap x :xa -nnoremap q :qa -" Clear search -nnoremap nh :noh -" Paste (rarely used because I commonly work in ssh'ed environments) -nnoremap pa "+p -" Show what registers contain -nnoremap rg :registers - - -" === Normal and Universal Mappings === -" Close a buffer, useful when doing PlugInstall and then closing that -" Or is it close a window? frame? DAMN all this emacs terminology got me so -" confused -nnoremap Q :q - -" NOTE: These mappings Just Work in wsl so no need the extra binding like -" in vimrc, this is why you use neovim instead of vim ;) -noremap :m+1== -noremap :m-2== -noremap :t.== -noremap :t.-1== - - -" === Visual Mappings === -" dot command in visual mode -vnoremap . :normal. - -" Move visual selection -vnoremap J :m '>+1gv=gv -vnoremap K :m '<-2gv=gv - -" Visual mode pressing * or # searches for the current selection -vnoremap * :call VisualSelection('', '')/=@/ -vnoremap # :call VisualSelection('', '')?=@/" - -" Keep text selected after indentation -" This is... really useful sometimes but annoying other times -vnoremap < >gv - - -" === Window/Buffer/Tab mappings === -" Better way to move between windows -noremap j -noremap k -noremap h -noremap l - -" Managing buffers -nnoremap bd :bd -nnoremap bn :bnext -nnoremap bp :bprev - -" Useful mappings for managing tabs -" Tab create -nnoremap tc :tabnew -nnoremap to :tabonly -" Tab delete -nnoremap td :tabclose -" I rarely have >3 tabs, let alone organize their placements :D but it's here -" because why not -nnoremap tm :tabmove -" Switching tabs -nnoremap tn :tabnext -nnoremap tp :tabprev - - -" === Misc Mappings === -" Hooray for neovim :))))) -" Terminal mappings -if has('macunix') - " WTF?? (I checked using C-v in insert mode) - " TODO: Fix in tmux - noremap :split term://fishi -else - noremap :split term://fishi -endif -" LOL! -nnoremap t :echom 'Deprecated. Please use C-` instead' -tnoremap - -" Command mode mappings -cnoremap PlugInstall -cnoremap Format - -" Quickly apply (n)vimrc changes -" Does not load ftplugins though -command! ReloadConfig so $HOME/.config/nvim/init.vim -nnoremap rc :ReloadConfig - diff --git a/.config/nvim/plugins.vim b/.config/nvim/plugins.vim deleted file mode 100644 index d005586..0000000 --- a/.config/nvim/plugins.vim +++ /dev/null @@ -1,248 +0,0 @@ -" ========================== -" Plugins and their settings -" ========================== -" -" === Plugin declarations === -call plug#begin(stdpath('data') . '/plugged') - -" dracula color theme (THE most important plugin, yes) -Plug 'dracula/vim', {'name': 'dracula'} -Plug 'preservim/nerdtree' " Perhaps switch to nvim-tree when I drop - " v0.5 support -Plug 'Xuyuanp/nerdtree-git-plugin' " Show git statuses in NERDTree -Plug 'Yggdroot/indentLine' " Show indentation levels with vertical bars -Plug 'tpope/vim-fugitive' " git commands -Plug 'jreybert/vimagit' " emacs' magit ✨ -Plug 'tpope/vim-surround' " quoting and parenthesizing manipulation -Plug 'tpope/vim-commentary' " I'd rather not clog mappings - " with nerd commentor -Plug 'itchyny/lightline.vim' " airline was throwing shitty errors so yeah. - " Pretty and customizable status bar; faster than - " other vim statusline plugins, for components - " see below; TODO: switch to galaxyline, lualine - " or express_line in the future? -" Commented out because I realized I never use it (lol) -" Plug 'mbbill/undotree' " undo tree -Plug 'bling/vim-bufferline' " buffer line (one of my most used plugins!) -Plug 'ctrlpvim/ctrlp.vim' " Quickly find a fine with fuzzy find - " TODO: use telescope instead -Plug 'airblade/vim-gitgutter' " Show git diff overview stuff in the left - " column -Plug 'majutsushi/tagbar' " Quickly jump to a symbol in buffer (one of my - " most used). Requires exuberant ctags -Plug 'tpope/vim-endwise' " Add those 'endif'/'fi'/'done' - " TODO: work with nvim-cmp - -" === File type, syntax, or language helper plugins === -" gemtext syntax highlighting; I know there are more popular alternatives but -" this is the best IMO -Plug 'https://git.sr.ht/~torresjrjr/gemini.vim' , { 'for': 'gemini' } -Plug 'cespare/vim-toml' , { 'for': 'toml' } -Plug 'blankname/vim-fish' , { 'for': 'fish' } -Plug 'hedyhli/vim-bun' , { 'for': 'bun' } -Plug 'https://git.rawtext.club/slope-lang/slope-vim-syntax' , { 'for': 'slope' } -Plug 'mzlogin/vim-markdown-toc' , { 'for': 'markdown' } -Plug 'leafo/moonscript-vim' , { 'for': 'moon' } - -" beware, this -" Plug 'github/copilot.vim' - -" === LSP and autopair plugins === -" This plugin below is really good, but whenever I'm on a commented line, -" press o, press backspace, the line below is joined up above. You won't -" believe how long it took me to debug this problem and finally realize it's -" because of this plugin. -" Plug 'jiangmiao/auto-pairs' -" -" So now I'm using these instead: -" 1. windwp/nvim-autopairs - extremely customizable, written in lua - -" integrates wth hrsh7th/nvim-cmp -" 2. townk/vim-autoclose - fallback if nvim < v0.5 -if has('nvim-0.5') - Plug 'nvim-lua/plenary.nvim' " Helper lua functions many plugins depend on - Plug 'mfussenegger/nvim-lint' - - if has('nvim-0.7') - Plug 'windwp/nvim-autopairs' - else - Plug 'windwp/nvim-autopairs', { 'commit': 'b7672cd' } - endif - " Best IDE autocomplete setup ever - " Please see ./lua/complete.lua - Plug 'neovim/nvim-lspconfig' - Plug 'hrsh7th/cmp-nvim-lsp' - Plug 'hrsh7th/cmp-buffer' " Completions of words in current buffer - Plug 'hrsh7th/cmp-path' " File paths - Plug 'hrsh7th/cmp-cmdline' " Fire your way through the neovim cmd line - Plug 'hrsh7th/cmp-calc' - Plug 'hrsh7th/cmp-emoji' " 😏 :smirk: - Plug 'mtoohey31/cmp-fish', { 'for': 'fish' } - Plug 'petertriho/cmp-git' - Plug 'kdheepak/cmp-latex-symbols' " τ long live \tau - Plug 'hrsh7th/nvim-cmp' - " Snippets - if has('nvim-0.7') - Plug 'dcampos/nvim-snippy' - Plug 'dcampos/cmp-snippy' - endif -else - Plug 'townk/vim-autoclose' - " Picking the right LSP completion method, see bottom of file for more - if has('node') - Plug 'neoclide/coc.nvim', {'branch': 'release'} - endif -endif - -call plug#end() -" Plugin declarations ends here - - -colorscheme dracula " THE most important nvim configuration - - -" === Statusline ✨ === -let g:lightline = { - \ 'colorscheme': 'dracula', - \ 'mode_map': { - \ 'n' : 'NORM', - \ 'i' : 'INS', - \ 'R' : 'REP', - \ 'v' : 'VIS', - \ 'V' : 'VL', - \ "\": 'VB', - \ 'c' : 'C', - \ 's' : 'S', - \ 'S' : 'SL', - \ "\": 'SB', - \ 't': 'T', - \ }, - \ 'component': { - \ 'tagbar': '%{tagbar#currenttag("[%s]", "")}', - \ }, - \ 'component_function': { - \ 'fugitive': 'LightlineFugitive', - \ 'diagnosticscount': 'LightlineDiagnostics', - \ 'morelineinfo': 'LightlineMoreLineinfo', - \ }, - \ 'component_type': { - \ 'diagnosticscount': 'error', - \ }, - \ 'active': { - \ 'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ], ['tagbar'] ], - \ 'right': [ [ 'diagnosticscount' ], ['morelineinfo'], ['fileformat', 'fileencoding', 'filetype'] ] - \ }, - \ } - -function! LightlineMoreLineinfo() - " Like lineinfo but appends total line number and removes col num: - " 123/200 (cur line / total lines) - " This shows current line and total lines together at a glimpse. - " NOTE: Current col number can be obtained using g. - " The col number is used less than current line number, plus the value - " updates at every keystroke, hence it doesn't make the status bar very - " performant, so it isn't included in the status line. - return printf("%7s", line('.').'/'.line('$')) - " Left pad so his component doesn't need dynamic widths - makes status bar - " appear to glitch less. -endfunction - -function! LightlineFugitive() - " Referenced from Lightline docs; I'm not 100% sure what this does but seems - " like it just grabs the current git branch - try - if expand('%:t') !~? 'Tagbar\|Gundo\|NERD' && &ft !~? 'vimfiler' && - \ exists('*FugitiveHead') - let mark = '' " I'm not sure what this mark does either - let branch = FugitiveHead() - return branch !=# '' ? mark.branch : '' - endif - catch - endtry - return '' -endfunction - -function! GetDiagnosticCount(level) - return len(luaeval('vim.diagnostic.get(0, {severity = vim.diagnostic.severity.' . a:level . '})')) -endfunction - -function! LightlineDiagnostics() - " Grabs the current buffer's diagnostics count and displays it in the - " format 'E:x W:x i:x h:x' - " If all 4 types of diagnostics are 0 then don't display anything - if !has('nvim-0.5') - " TODO: if we don't have nvim-0.5 then call some CoC function? - return '!0.5' - endif - - let errors = GetDiagnosticCount('ERROR') - let warnings = GetDiagnosticCount('WARN') - let infos = GetDiagnosticCount('INFO') - let hints = GetDiagnosticCount('HINT') - if (errors + warnings + infos + hints) == 0 - return '' " Exit early even though this case is handled below - endif - - let string = '' - if errors != 0 - let string = string . 'E:' . errors . ' ' - endif - if warnings != 0 - let string = string . 'W:' . warnings . ' ' - endif - if infos != 0 - let string = string . 'i:' . infos . ' ' - endif - if hints != 0 - let string = string . 'h:' . hints . ' ' - endif - - return substitute(string, '\s$', '', '') " Strip trailing whitespace -endfunction - - -" === Other plugins' settings === -let NERDTreeWinSize = 20 -" Open current dir in nerdtree -noremap nf :NERDTreeFind -noremap nt :NERDTreeToggle - -" NerdTree Git plugin -let g:NERDTreeGitStatusIndicatorMapCustom = { - \ "Modified" : "M", - \ "Staged" : "A", - \ "Untracked" : "?", - \ "Renamed" : "R", - \ "Unmerged" : "═", - \ "Deleted" : "D", - \ "Dirty" : "X", - \ "Clean" : "✔︎", - \ 'Ignored' : 'i', - \ "Unknown" : "?" - \ } - -" tagbar -nnoremap tt :TagbarToggle -let g:tagbar_width = 20 - -" Make indentLine still work, but disable conceal characters. eg, hiding the -" asterisks for a bold text in markdown is extremely annoying when you want to -" delete or change those asterisks. -let g:markdown_syntax_conceal=0 -let g:vim_json_conceal=0 - -" === LSP === -if has("nvim-0.5") - " Set completeopt to have a better completion experience - set completeopt=menuone,noinsert,noselect,preview - lua require('autopair') - lua require('lsp') - lua require('complete') - if has('nvim-0.6') - lua require('linting') - endif -else - if has('node') - source $HOME/.config/nvim/coc.vim - endif -endif -