Reorganize Neovim config and migrate to lazy.nvim

This commit is contained in:
Mikkel Svartveit 2023-03-20 23:03:15 +01:00
parent 682ee7ab7f
commit 7b13102909
6 changed files with 459 additions and 369 deletions

View file

@ -4,7 +4,7 @@ alias icloud="cd ~/Library/Mobile\ Documents/com~apple~CloudDocs"
alias pi="ssh pi@185.138.33.80 -p 1733"
alias zshrc="nvim ~/.zshrc"
alias fishconfig="cd ~/.config/fish && nvim config.fish && cd -"
alias nvimconfig="cd ~/.config/nvim && nvim init.vim && cd -"
alias nvimconfig="cd ~/.config/nvim && nvim && cd -"
alias ai="sgpt -se"
alias y="open -a Yoink"

1
.config/nvim/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.plugins.lua.swp

View file

@ -86,372 +86,8 @@ au VimLeave * set guicursor=a:ver100
" Use Bash as shell for internal Vim commands (fish is slow)
set shell=/bin/bash
" Load plugins from separate file
lua require("plugins")
" PLUGINS - installation and configuration
" Install Plug (plugin manager) if not already installed
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * q
endif
" Install plugins automatically when launching Neovim
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
" Fetch plugins with Plug
call plug#begin()
" Color theme
Plug 'sonph/onehalf', { 'rtp': 'vim' }
" Plug 'arcticicestudio/nord-vim'
" VSCode-like language server
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Syntax highlighting for almost every language
Plug 'sheerun/vim-polyglot'
" Add two-character motions with s and S
Plug 'ggandor/leap.nvim'
Plug 'tpope/vim-repeat'
" VSCode-like multi-cursor support
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
" Easy commenting/uncommenting
Plug 'numToStr/Comment.nvim'
" Easy handling of surroundings (tags, brackets etc.)
Plug 'tpope/vim-surround'
" Github Copilot
Plug 'github/copilot.vim'
" Auto-restore session when opening Neovim
Plug 'rmagatti/auto-session'
" File explorer sidebar
Plug 'kyazdani42/nvim-web-devicons'
Plug 'kyazdani42/nvim-tree.lua', { 'commit': 'e14989c' }
" Fuzzy finder for files, buffers, etc. (including dependencies)
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' }
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
" Persistent terminal that can be toggled with a keybinding
Plug 'akinsho/toggleterm.nvim', {'tag': '2.3.0'}
" Easily run code with a keybinding
Plug 'CRAG666/code_runner.nvim'
" Live Markdown preview in browser
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npm install' }
" Git integration: show modified lines next to line numbers
Plug 'lewis6991/gitsigns.nvim'
" Tool for resolving Git merge conflicts
Plug 'rhysd/conflict-marker.vim'
" VSCode-like scrollbar with Git and diagnostic markers
Plug 'petertriho/nvim-scrollbar'
" Smooth scrolling
Plug 'karb94/neoscroll.nvim'
" End of plugin fetching
call plug#end()
" Set color scheme
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
colorscheme onehalfdark
let g:terminal_color_8 = '#6f7a90'
" Install Coc extenstions
let g:coc_global_extensions = [
\ 'coc-pyright',
\ 'coc-clangd',
\ 'coc-tsserver',
\ '@yaegassy/coc-volar',
\ 'coc-svelte',
\ 'coc-emmet',
\ 'coc-prettier',
\ 'coc-eslint',
\ ]
" Custom options for Coc
let g:python_highlight_space_errors = 0
command! -nargs=0 Format :CocCommand format
command! -nargs=0 F :Format
command! -nargs=0 Prettier :CocCommand prettier.forceFormatDocument
" Configure vim-polyglot
let g:vim_svelte_plugin_load_full_syntax = 1
let g:vim_svelte_plugin_use_typescript = 1
let g:vim_svelte_plugin_use_sass = 1
" Configure leap
lua require('leap').add_default_mappings()
" Configure Comment.nvim
lua require('Comment').setup()
" Disable Github Copilot on launch and configure commands
autocmd BufRead * let b:copilot_enabled = v:false
command! -nargs=0 CPE :let b:copilot_enabled = v:true
command! -nargs=0 CPD :let b:copilot_enabled = v:false
" Configure auto-session
lua require("auto-session").setup{
\ log_level = "error",
\ }
" Configure nvim-tree
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
nmap gx :!open <c-r><c-a>
nnoremap <silent><leader>n :NvimTreeToggle<CR>
lua require("nvim-tree").setup({
\ update_focused_file = {
\ enable = true,
\ },
\ view = {
\ signcolumn = "auto",
\ adaptive_size = true,
\ mappings = {
\ list = {
\ { key = "+", action = "cd" },
\ },
\ },
\ },
\ })
" Configure Telescope
lua require('telescope').setup{}
lua require('telescope').load_extension('fzf')
nnoremap <leader>p <cmd>Telescope find_files<cr>
nnoremap <leader>f <cmd>Telescope live_grep<cr>
nnoremap <leader>b <cmd>Telescope buffers<cr>
nnoremap <leader>o <cmd>Telescope oldfiles<cr>
nnoremap <leader>t <cmd>Telescope tags<cr>
nnoremap <leader>: <cmd>Telescope commands<cr>
nnoremap <leader>d <cmd>Telescope git_status<cr>
nnoremap <leader><leader> <cmd>Telescope resume<cr>
" Configure ToggleTerm
lua require("toggleterm").setup{
\ size = 20,
\ hide_numbers = true,
\ direction = 'horizontal',
\ open_mapping = [[<C-j>]],
\ shade_terminals = true,
\ shading_factor = 2,
\ shell = 'fish'
\ }
" Configure code_runner
lua require('code_runner').setup{
\ mode = "toggleterm",
\ filetype = {
\ python = "python",
\ javascript = "node",
\ typescript = "node",
\ c = "gcc -o main % && ./main",
\ },
\ }
nnoremap <leader><CR> :w<CR>:RunCode<CR>
" Configure markdown-preview
let g:mkdp_auto_close = 0
" Configure gitsigns.nvim
lua require('gitsigns').setup()
lua require("scrollbar.handlers.gitsigns").setup()
" Configure conflict-marker
let g:conflict_marker_highlight_group = ''
let g:conflict_marker_begin = '^<<<<<<< .*$'
let g:conflict_marker_end = '^>>>>>>> .*$'
highlight ConflictMarkerBegin guibg=#2f7366
highlight ConflictMarkerOurs guibg=#2e5049
highlight ConflictMarkerTheirs guibg=#344f69
highlight ConflictMarkerEnd guibg=#2f628e
highlight ConflictMarkerCommonAncestorsHunk guibg=#754a81
" Configure nvim-scrollbar
lua require("scrollbar").setup({
\ marks = {
\ Search = { color = "#ff9e64" },
\ Error = { color = "#db4b4b" },
\ Warn = { color = "#e0af68" },
\ Info = { color = "#0db9d7" },
\ Hint = { color = "#1abc9c" },
\ Misc = { color = "#9d7cd8" },
\ GitAdd = { color = "#9ece6a" },
\ GitChange = { color = "#e0af68" },
\ GitDelete = { color = "#914c54" },
\ }
\ })
" Configure neoscroll
lua require('neoscroll').setup({ easing_function = 'sine' })
" COC DEFAULT CONFIG - required for autocompletion etc. to work properly
" Copied from the readme: github.com/neoclide/coc.nvim
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
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>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
" xmap <leader>f <Plug>(coc-format-selected)
" nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Run the Code Lens action on the current line.
nmap <leader>cl <Plug>(coc-codelens-action)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 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.
" set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
" Load default Coc config from separate file
lua require("coc-defaults")

View file

@ -0,0 +1,25 @@
{
"Comment.nvim": { "branch": "master", "commit": "8d3aa5c22c2d45e788c7a5fe13ad77368b783c20" },
"auto-session": { "branch": "main", "commit": "1d3dd70a2d48e0f3441128eb4fb0b437a0bf2cc4" },
"coc.nvim": { "branch": "release", "commit": "bbaa1d5d1ff3cbd9d26bb37cfda1a990494c4043" },
"code_runner.nvim": { "branch": "main", "commit": "a010649236fe245eaab2641a13228cd601499715" },
"copilot.vim": { "branch": "release", "commit": "9e869d29e62e36b7eb6fb238a4ca6a6237e7d78b" },
"git-conflict.nvim": { "branch": "main", "commit": "80bc8931d4ed8c8c4d289a08e1838fcf4741408d" },
"gitsigns.nvim": { "branch": "main", "commit": "b1f9cf7c5c5639c006c937fc1819e09f358210fc" },
"lazy.nvim": { "branch": "main", "commit": "887eb75591520a01548134c4623617b639289d0b" },
"leap.nvim": { "branch": "main", "commit": "f74473d23ebf60957e0db3ff8172349a82e5a442" },
"markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" },
"neoscroll.nvim": { "branch": "master", "commit": "d7601c26c8a183fa8994ed339e70c2d841253e93" },
"nvim-scrollbar": { "branch": "main", "commit": "f85b29805cf917f9b1d5ff0c9a52c5b1bdca5943" },
"nvim-toggleterm.lua": { "branch": "main", "commit": "2a787c426ef00cb3488c11b14f5dcf892bbd0bda" },
"nvim-tree.lua": { "branch": "master", "commit": "e14989c0eaa6f9c299d48f7e45ce1ed04b21180f" },
"nvim-web-devicons": { "branch": "master", "commit": "074e13f21f52bb45d654069bdadbcb6d7c2b65d0" },
"onehalf": { "branch": "master", "commit": "75eb2e97acd74660779fed8380989ee7891eec56" },
"plenary.nvim": { "branch": "master", "commit": "253d34830709d690f013daf2853a9d21ad7accab" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "580b6c48651cabb63455e97d7e131ed557b8c7e2" },
"telescope.nvim": { "branch": "master", "commit": "c1a2af0af69e80e14e6b226d3957a064cd080805" },
"vim-polyglot": { "branch": "master", "commit": "bc8a81d3592dab86334f27d1d43c080ebf680d42" },
"vim-repeat": { "branch": "master", "commit": "24afe922e6a05891756ecf331f39a1f6743d3d5a" },
"vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" },
"vim-visual-multi": { "branch": "master", "commit": "724bd53adfbaf32e129b001658b45d4c5c29ca1a" }
}

View file

@ -0,0 +1,189 @@
-- Default config for Coc
-- From https://github.com/neoclide/coc.nvim
-- 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 code actions affect whole buffer.
keyset("n", "<leader>as", "<Plug>(coc-codeaction-source)", opts)
-- Remap keys for applying codeActions to the current buffer
keyset("n", "<leader>ac", "<Plug>(coc-codeaction)", 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)

View file

@ -0,0 +1,239 @@
-- Install lazy.nvim (plugin manager)
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", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Install plugins
require("lazy").setup({
-- Color scheme
{
"sonph/onehalf",
lazy = false,
priority = 1000,
config = function(plugin)
vim.opt.rtp:append(plugin.dir .. "/vim")
vim.opt.termguicolors = true
vim.cmd([[colorscheme onehalfdark]])
end
},
-- VSCode-like language server
{
"neoclide/coc.nvim",
branch = "release",
init = function()
vim.g.coc_global_extensions = {
"coc-pyright",
"coc-clangd",
"coc-tsserver",
"@yaegassy/coc-volar",
"coc-svelte",
"coc-emmet",
"coc-prettier",
"coc-eslint",
}
end
},
-- Syntax highlighting for almost every language
{
"sheerun/vim-polyglot",
init = function()
vim.g.vim_svelte_plugin_load_full_syntax = 1
vim.g.vim_svelte_plugin_use_typescript = 1
vim.g.vim_svelte_plugin_use_sass = 1
end
},
-- Enable dot repeat for plugins
{
"tpope/vim-repeat",
},
-- Add two-character motions with s and S
{
"ggandor/leap.nvim",
config = function()
require('leap').add_default_mappings()
end
},
-- VSCode-like multi-cursor support
{
"mg979/vim-visual-multi",
branch = "master",
},
-- Easy commenting/uncommenting
{
"numToStr/Comment.nvim",
config = true,
},
-- Easy handling of surroundings
{
"tpope/vim-surround",
},
-- GitHub Copilot
{
"github/copilot.vim",
cmd = "CPE", -- Don't load until enable command is run
config = function()
vim.api.nvim_create_user_command("CPE", "Copilot enable", {})
vim.api.nvim_create_user_command("CPD", "Copilot disable", {})
end
},
-- Auto-restore session when opening Neovim
{
"rmagatti/auto-session",
opts = {
log_level = "error",
},
},
-- File explorer sidebar
{
"kyazdani42/nvim-tree.lua",
commit = "e14989c", -- newer versions break auto-session
dependencies = {
"kyazdani42/nvim-web-devicons",
},
opts = {
update_focused_file = {
enable = true,
},
view = {
signcolumn = "auto",
adaptive_size = true,
mappings = {
list = {
{ key = "+", action = "cd" },
},
},
},
},
init = function()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.keymap.set("n", "<leader>n", ":NvimTreeToggle<CR>", { noremap = true, silent = true })
end,
},
-- Fuzzy finder for files, buffers, etc.
{
"nvim-telescope/telescope.nvim",
tag = "0.1.1",
dependencies = {
"nvim-lua/plenary.nvim",
{"nvim-telescope/telescope-fzf-native.nvim", build = "make"},
},
config = function()
require("telescope").setup{}
require("telescope").load_extension("fzf")
vim.keymap.set("n", "<leader>p", ":Telescope find_files<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>f", ":Telescope live_grep<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>b", ":Telescope buffers<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>o", ":Telescope oldfiles<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>t", ":Telescope tags<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>:", ":Telescope commands<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>d", ":Telescope git_status<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader><leader>", ":Telescope resume<CR>", { noremap = true, silent = true })
end,
},
-- Persistent terminal that can be toggled with a keybinding
{
"akinsho/nvim-toggleterm.lua",
tag = "2.3.0",
keys = "<C-j>",
opts = {
size = 20,
hide_numbers = true,
direction = 'horizontal',
open_mapping = [[<C-j>]],
shade_terminals = true,
shading_factor = 2,
shell = 'fish'
}
},
-- Run code with a keybinding
{
"CRAG666/code_runner.nvim",
opts = {
mode = "toggleterm",
filetype = {
python = "python",
javascript = "node",
typescript = "node",
c = "gcc -o main % && ./main",
},
},
init = function()
vim.keymap.set("n", "<leader><CR>", ":RunCode<CR>", { noremap = true })
end,
},
-- Live Markdown preview in browser
{
"iamcco/markdown-preview.nvim",
build = "cd app && npm install",
ft = "markdown",
init = function()
vim.g.mkdp_auto_close = 0
end,
},
-- Git integration - show modified lines next to line numbers
{
"lewis6991/gitsigns.nvim",
config = function()
require("gitsigns").setup()
require("scrollbar.handlers.gitsigns").setup()
end,
},
-- Tool for resolving Git merge conflicts
{
"akinsho/git-conflict.nvim",
tag = "v1.0.0",
config = true,
},
-- VSCode-like scrollbar with Git and diagnostic markers
{
"petertriho/nvim-scrollbar",
opts = {
marks = {
Search = { color = "#ff9e64" },
Error = { color = "#db4b4b" },
Warn = { color = "#e0af68" },
Info = { color = "#0db9d7" },
Hint = { color = "#1abc9c" },
Misc = { color = "#9d7cd8" },
GitAdd = { color = "#9ece6a" },
GitChange = { color = "#e0af68" },
GitDelete = { color = "#914c54" },
}
}
},
-- Smooth scrolling
{
"karb94/neoscroll.nvim",
opts = {
easing_function = "sine",
}
},
})