diff options
| author | Blista Kanjo | 2023-06-23 03:49:02 -0400 |
|---|---|---|
| committer | Blista Kanjo | 2023-06-23 03:49:02 -0400 |
| commit | 22f4fa182c2048d1f07dcd6e5729cd946771c9f9 (patch) | |
| tree | a527dcf6f755db72940a7533343705e5dce2fa47 /.config/nvim/lua | |
| parent | b6405dff5dac31b5c1d070d77437095315f290a2 (diff) | |
refactor: added lua folder
Diffstat (limited to '.config/nvim/lua')
| -rw-r--r-- | .config/nvim/lua/coc.lua | 191 | ||||
| -rw-r--r-- | .config/nvim/lua/keys.lua | 19 | ||||
| -rw-r--r-- | .config/nvim/lua/look.lua | 37 | ||||
| -rw-r--r-- | .config/nvim/lua/opts.lua | 53 | ||||
| -rw-r--r-- | .config/nvim/lua/plug.lua | 15 |
5 files changed, 315 insertions, 0 deletions
diff --git a/.config/nvim/lua/coc.lua b/.config/nvim/lua/coc.lua new file mode 100644 index 0000000..35b7099 --- /dev/null +++ b/.config/nvim/lua/coc.lua @@ -0,0 +1,191 @@ +-- old coc.nvim config (minimal) +-- vim.cmd [[ +-- function! CheckBackspace() abort +-- let col = col('.') - 1 +-- return !col || getline('.')[col - 1] =~# '\s' +-- endfunction +-- +-- inoremap <silent><expr> <TAB> +-- \ coc#pum#visible() ? coc#pum#next(1) : +-- \ CheckBackspace() ? "\<Tab>" : +-- \ coc#refresh() +-- inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>" +-- ]] + +-- some servers have issues with backup files, see #649 +vim.opt.backup = false +vim.opt.writebackup = false + +-- having longer updatetime (default is 4000 ms = 4s) leads to noticeable +-- delays and poor user experience +vim.opt.updatetime = 300 + +-- always show the signcolumn, otherwise it would shift the text each time +-- diagnostics appeared/became resolved +vim.opt.signcolumn = "yes" + +local keyset = vim.keymap.set +-- autocomplete +function _G.check_back_space() + local col = vim.fn.col('.') - 1 + return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil +end + +-- use tab for trigger completion with characters ahead and navigate +-- note: there's always a completion item selected by default, you may want to enable +-- no select by setting `"suggest.noselect": true` in your configuration file +-- note: use command ':verbose imap <tab>' to make sure tab is not mapped by +-- other plugins before putting this into your config +local opts = {silent = true, noremap = true, expr = true, replace_keycodes = false} +keyset("i", "<TAB>", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "<TAB>" : coc#refresh()', opts) +keyset("i", "<S-TAB>", [[coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"]], opts) + +-- make <cr> to accept selected completion item or notify coc.nvim to format +-- <c-g>u breaks current undo, please make your own choice +keyset("i", "<cr>", [[coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"]], opts) + +-- use <c-j> to trigger snippets +keyset("i", "<c-j>", "<Plug>(coc-snippets-expand-jump)") +-- use <c-space> to trigger completion +keyset("i", "<c-space>", "coc#refresh()", {silent = true, expr = true}) + +-- use `[g` and `]g` to navigate diagnostics +-- use `:cocdiagnostics` to get all diagnostics of current buffer in location list +keyset("n", "[g", "<Plug>(coc-diagnostic-prev)", {silent = true}) +keyset("n", "]g", "<Plug>(coc-diagnostic-next)", {silent = true}) + +-- goto code navigation +keyset("n", "gd", "<Plug>(coc-definition)", {silent = true}) +keyset("n", "gy", "<Plug>(coc-type-definition)", {silent = true}) +keyset("n", "gi", "<Plug>(coc-implementation)", {silent = true}) +keyset("n", "gr", "<Plug>(coc-references)", {silent = true}) + +-- use k to show documentation in preview window +function _G.show_docs() + local cw = vim.fn.expand('<cword>') + if vim.fn.index({'vim', 'help'}, vim.bo.filetype) >= 0 then + vim.api.nvim_command('h ' .. cw) + elseif vim.api.nvim_eval('coc#rpc#ready()') then + vim.fn.CocActionAsync('doHover') + else + vim.api.nvim_command('!' .. vim.o.keywordprg .. ' ' .. cw) + end +end +keyset("n", "K", '<CMD>lua _G.show_docs()<CR>', {silent = true}) + +-- highlight the symbol and its references on a cursorhold event(cursor is idle) +vim.api.nvim_create_augroup("CocGroup", {}) +vim.api.nvim_create_autocmd("CursorHold", { + group = "CocGroup", + command = "silent call CocActionAsync('highlight')", + desc = "Highlight symbol under cursor on CursorHold" +}) + +-- symbol renaming +keyset("n", "<leader>rn", "<Plug>(coc-rename)", {silent = true}) + +-- formatting selected code +keyset("x", "<leader>f", "<Plug>(coc-format-selected)", {silent = true}) +keyset("n", "<leader>f", "<Plug>(coc-format-selected)", {silent = true}) + +-- setup formatexpr specified filetype(s) +vim.api.nvim_create_autocmd("FileType", { + group = "CocGroup", + pattern = "typescript,json", + command = "setl formatexpr=CocAction('formatSelected')", + desc = "Setup formatexpr specified filetype(s)." +}) + +-- update signature help on jump placeholder +vim.api.nvim_create_autocmd("User", { + group = "CocGroup", + pattern = "CocJumpPlaceholder", + command = "call CocActionAsync('showSignatureHelp')", + desc = "Update signature help on jump placeholder" +}) + +-- apply codeaction to the selected region +-- example: `<leader>aap` for current paragraph +local opts = {silent = true, nowait = true} +keyset("x", "<leader>a", "<Plug>(coc-codeaction-selected)", opts) +keyset("n", "<leader>a", "<Plug>(coc-codeaction-selected)", opts) + +-- remap keys for apply code actions at the cursor position. +keyset("n", "<leader>ac", "<Plug>(coc-codeaction-cursor)", opts) +-- remap keys for apply source code actions for current file. +keyset("n", "<leader>as", "<Plug>(coc-codeaction-source)", opts) +-- apply the most preferred quickfix action on the current line. +keyset("n", "<leader>qf", "<Plug>(coc-fix-current)", opts) + +-- remap keys for apply refactor code actions. +keyset("n", "<leader>re", "<Plug>(coc-codeaction-refactor)", { silent = true }) +keyset("x", "<leader>r", "<Plug>(coc-codeaction-refactor-selected)", { silent = true }) +keyset("n", "<leader>r", "<Plug>(coc-codeaction-refactor-selected)", { silent = true }) + +-- run the code lens actions on the current line +keyset("n", "<leader>cl", "<Plug>(coc-codelens-action)", opts) + + +-- map function and class text objects +-- note: requires 'textdocument.documentsymbol' support from the language server +keyset("x", "if", "<Plug>(coc-funcobj-i)", opts) +keyset("o", "if", "<Plug>(coc-funcobj-i)", opts) +keyset("x", "af", "<Plug>(coc-funcobj-a)", opts) +keyset("o", "af", "<Plug>(coc-funcobj-a)", opts) +keyset("x", "ic", "<Plug>(coc-classobj-i)", opts) +keyset("o", "ic", "<Plug>(coc-classobj-i)", opts) +keyset("x", "ac", "<Plug>(coc-classobj-a)", opts) +keyset("o", "ac", "<Plug>(coc-classobj-a)", opts) + + +-- remap <c-f> and <c-b> to scroll float windows/popups +---@diagnostic disable-next-line: redefined-local +local opts = {silent = true, nowait = true, expr = true} +keyset("n", "<C-f>", 'coc#float#has_scroll() ? coc#float#scroll(1) : "<C-f>"', opts) +keyset("n", "<C-b>", 'coc#float#has_scroll() ? coc#float#scroll(0) : "<C-b>"', opts) +keyset("i", "<C-f>", + 'coc#float#has_scroll() ? "<c-r>=coc#float#scroll(1)<cr>" : "<Right>"', opts) +keyset("i", "<C-b>", + 'coc#float#has_scroll() ? "<c-r>=coc#float#scroll(0)<cr>" : "<Left>"', opts) +keyset("v", "<C-f>", 'coc#float#has_scroll() ? coc#float#scroll(1) : "<C-f>"', opts) +keyset("v", "<C-b>", 'coc#float#has_scroll() ? coc#float#scroll(0) : "<C-b>"', opts) + +-- use ctrl-s for selections ranges +-- requires 'textdocument/selectionrange' support of language server +keyset("n", "<C-s>", "<Plug>(coc-range-select)", {silent = true}) +keyset("x", "<C-s>", "<Plug>(coc-range-select)", {silent = true}) + +-- add `:format` command to format current buffer +vim.api.nvim_create_user_command("Format", "call CocAction('format')", {}) + +-- " add `:fold` command to fold current buffer +vim.api.nvim_create_user_command("Fold", "call CocAction('fold', <f-args>)", {nargs = '?'}) + +-- add `:or` command for organize imports of the current buffer +vim.api.nvim_create_user_command("OR", "call CocActionAsync('runCommand', 'editor.action.organizeImport')", {}) + +-- add (neo)vim's native statusline support +-- note: please see `:h coc-status` for integrations with external plugins that +-- provide custom statusline: lightline.vim, vim-airline +vim.opt.statusline:prepend("%{coc#status()}%{get(b:,'coc_current_function','')}") + +-- mappings for coclist +-- code actions and coc stuff +---@diagnostic disable-next-line: redefined-local +local opts = {silent = true, nowait = true} +-- show all diagnostics +keyset("n", "<space>a", ":<C-u>CocList diagnostics<cr>", opts) +-- manage extensions +keyset("n", "<space>e", ":<C-u>CocList extensions<cr>", opts) +-- show commands +keyset("n", "<space>c", ":<C-u>CocList commands<cr>", opts) +-- find symbol of current document +keyset("n", "<space>o", ":<C-u>CocList outline<cr>", opts) +-- search workspace symbols +keyset("n", "<space>s", ":<C-u>CocList -I symbols<cr>", opts) +-- do default action for next item +keyset("n", "<space>j", ":<C-u>CocNext<cr>", opts) +-- do default action for previous item +keyset("n", "<space>k", ":<C-u>CocPrev<cr>", opts) +-- resume latest coc list +keyset("n", "<space>p", ":<C-u>CocListResume<cr>", opts) diff --git a/.config/nvim/lua/keys.lua b/.config/nvim/lua/keys.lua new file mode 100644 index 0000000..0cc493e --- /dev/null +++ b/.config/nvim/lua/keys.lua @@ -0,0 +1,19 @@ +-- legacy keybinds for x11 clipboard +vim.cmd [[ + vnoremap <C-c> "+y + vmap <C-x> "+x + map <C-p> "+p + map <Leader>p "+P +]] + +-- vertical motion remappings +vim.api.nvim_set_keymap("n", "<C-d>", "<C-d>zz", { noremap = true }) +vim.api.nvim_set_keymap("n", "<C-u>", "<C-u>zz", { noremap = true }) +vim.api.nvim_set_keymap("n", "n", "nzzzv", { noremap = true }) +vim.api.nvim_set_keymap("n", "N", "Nzzzv", { noremap = true }) + +-- nerdtree keybinds +vim.api.nvim_set_keymap("n", "<leader>n", ":NERDTreeFocus<CR>", { noremap = true }) +vim.api.nvim_set_keymap("n", "<C-n>", ":NERDTree<CR>", { noremap = true }) +vim.api.nvim_set_keymap("n", "<C-t>", ":NERDTreeToggle<CR>", { noremap = true }) +vim.api.nvim_set_keymap("n", "<leader>/", ":NERDTreeFind<CR>", { noremap = true }) diff --git a/.config/nvim/lua/look.lua b/.config/nvim/lua/look.lua new file mode 100644 index 0000000..c3b449f --- /dev/null +++ b/.config/nvim/lua/look.lua @@ -0,0 +1,37 @@ +-- colorscheme declaration +vim.cmd("colorscheme tender") + +-- coc.nvim colors +vim.cmd("highlight CocFloating ctermbg=0") +vim.cmd("highlight CocErrorFloat ctermfg=15") + +-- appearanec of splits and vsplits +vim.cmd("highlight VertSplit ctermfg=235 guifg=#3c3836") +vim.cmd("highlight StatusLine ctermfg=black ctermbg=lightgray") +vim.cmd("highlight StatusLineNC ctermfg=darkgray ctermbg=lightgray") + +-- gui appearance declarations +if vim.fn.has('gui_running') == 1 then + vim.opt.t_Co = 256 + vim.opt.guifont = "JetBrains Mono 11" + vim.opt.guioptions:remove("m") + vim.opt.guioptions:remove("T") + vim.opt.guioptions:remove("r") + vim.opt.guioptions:remove("L") + vim.cmd("colorscheme tender") +end + +-- remove trailing whitespace from python and fortran files +vim.api.nvim_exec([[ + autocmd BufWritePre *.py :%s/\s\+$//e + autocmd BufWritePre *.f90 :%s/\s\+$//e + autocmd BufWritePre *.f95 :%s/\s\+$//e + autocmd BufWritePre *.for :%s/\s\+$//e +]], false) + +-- other appearance settings that I don't know how to set in lua +vim.cmd("filetype plugin on") +vim.cmd("syntax on") +vim.cmd("highlight Cursorline cterm=bold ctermbg=black") +vim.cmd("filetype indent on") + diff --git a/.config/nvim/lua/opts.lua b/.config/nvim/lua/opts.lua new file mode 100644 index 0000000..547b697 --- /dev/null +++ b/.config/nvim/lua/opts.lua @@ -0,0 +1,53 @@ +local opts = { + -- clipboard = "unnamedplus", + -- textwidth = 80, + autochdir = true, + autoindent = true, + cursorline = true, + expandtab = true, + hlsearch = true, + ignorecase = true, + listchars = { tab = ">-", trail = "~", extends = ">", precedes = "<", space = "." }, + mouse = "a", + number = true, + relativenumber = true, + shiftwidth = 4, + showmatch = true, + smartcase = true, + softtabstop = 4, + tabstop = 4, + termguicolors = true, + ttimeout = true, + ttimeoutlen = 1, + ttyfast = true, +} + +-- Customize split dividers +vim.opt.fillchars = vim.opt.fillchars + { + vert = "â–ˆ", + fold = "â–ˆ", + diff = "â–ˆ", + stl = "=", + stlnc = "=", + stl = "=" +} + +-- Use a line cursor within insert mode and a block cursor everywhere else. +-- Reference chart of values: +-- Ps = 0 -> blinking block. +-- Ps = 1 -> blinking block (default). +-- Ps = 2 -> steady block. +-- Ps = 3 -> blinking underline. +-- Ps = 4 -> steady underline. +-- Ps = 5 -> blinking bar (xterm). +-- Ps = 6 -> steady bar (xterm). +vim.g.t_SI = "\27[6 q" +vim.g.t_EI = "\27[2 q" + +if vim.env.TERM == "alacritty" then + vim.opt.ttymouse = "sgr" +end + +for x, y in pairs(opts) do + vim.opt[x] = y +end diff --git a/.config/nvim/lua/plug.lua b/.config/nvim/lua/plug.lua new file mode 100644 index 0000000..63eac2e --- /dev/null +++ b/.config/nvim/lua/plug.lua @@ -0,0 +1,15 @@ +-- Plugin manager (vim-plug) +vim.cmd [[ + call plug#begin() + Plug 'https://github.com/preservim/nerdtree', { 'on': 'NERDTreeToggle' } + " Plug 'LunarWatcher/auto-pairs' + Plug 'tmsvg/pear-tree' + Plug 'https://github.com/adelarsq/vim-matchit' + Plug 'neoclide/coc.nvim', {'branch': 'release'} + Plug 'tpope/vim-surround' + Plug 'sbdchd/neoformat' + Plug 'ThePrimeagen/vim-be-good' + Plug 'junegunn/fzf' + call plug#end() +]] + |
