From 4fc48c3cb5e785ee27a77c1b5653905daa7561f4 Mon Sep 17 00:00:00 2001 From: Nathan Knowler Date: Sat, 24 Apr 2021 13:44:27 -0500 Subject: [PATCH] [neovim] convert config to Lua (#20) --- .Brewfile | 1 + .config/nvim/init.lua | 16 + .config/nvim/init.vim | 389 ------------------------- .config/nvim/lua/base.lua | 37 +++ .config/nvim/lua/colors.lua | 14 + .config/nvim/lua/completion.lua | 22 ++ .config/nvim/lua/keymap.lua | 20 ++ .config/nvim/lua/lsp-config.lua | 48 +++ .config/nvim/lua/lsp_config.lua | 63 ---- .config/nvim/lua/plugins.lua | 41 +++ .config/nvim/lua/treesitter-config.lua | 6 + .config/nvim/lua/treesitter_config.lua | 21 -- .config/nvim/lua/utils.lua | 34 +++ 13 files changed, 239 insertions(+), 473 deletions(-) create mode 100644 .config/nvim/init.lua delete mode 100644 .config/nvim/init.vim create mode 100644 .config/nvim/lua/base.lua create mode 100644 .config/nvim/lua/colors.lua create mode 100644 .config/nvim/lua/completion.lua create mode 100644 .config/nvim/lua/keymap.lua create mode 100644 .config/nvim/lua/lsp-config.lua delete mode 100644 .config/nvim/lua/lsp_config.lua create mode 100644 .config/nvim/lua/plugins.lua create mode 100644 .config/nvim/lua/treesitter-config.lua delete mode 100644 .config/nvim/lua/treesitter_config.lua create mode 100644 .config/nvim/lua/utils.lua diff --git a/.Brewfile b/.Brewfile index c9f82ce..354f2fc 100644 --- a/.Brewfile +++ b/.Brewfile @@ -36,6 +36,7 @@ brew "dnsmasq", restart_service: true brew "dockutil" brew "dolt" brew "dust" +brew "efm-langserver" brew "eva" brew "exa" brew "fd" diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..dc56565 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,16 @@ +--[[ + +A lot of this is a concoction of configs I copied from the following: + +- yoshuawuyts +- maybeinit +- tjdevries +- wbthomason +- tomaskallup + +--]] + +require'base' +require'colors' +require'plugins' +require'keymap' diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim deleted file mode 100644 index 7ec6725..0000000 --- a/.config/nvim/init.vim +++ /dev/null @@ -1,389 +0,0 @@ -" Plugins like this -set nocompatible - -" Use vim-plug for plugin management (install first) -" install with :PlugInstall -" update with :PlugUpdate -call plug#begin(stdpath('data') . '/plugged') - -" Essentials -" Syntax (we use another plugin for this) -let g:polyglot_disabled = ['markdown'] -Plug 'sheerun/vim-polyglot' " The only syntax highlighting package you will ever need -Plug 'tpope/vim-markdown' -Plug 'AndrewRadev/splitjoin.vim' " Easily switch between single and multi line format for stuff (split: gS | join: gJ) -Plug 'tpope/vim-fugitive' " Git for vim -Plug 'tpope/vim-rhubarb' " GitHub for vim -Plug 'tpope/vim-surround' " Surround stuff -Plug 'tpope/vim-speeddating' -Plug 'tpope/vim-repeat' -Plug 'tpope/vim-abolish' -Plug 'editorconfig/editorconfig-vim' -Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Fuzzy find stuff -Plug 'junegunn/fzf.vim' -Plug 'tommcdo/vim-exchange' - -" LSP -Plug 'neovim/nvim-lspconfig' -Plug 'hrsh7th/nvim-compe' - -Plug 'nvim-lua/popup.nvim' -Plug 'nvim-lua/plenary.nvim' -Plug 'nvim-telescope/telescope.nvim' -Plug 'nvim-telescope/telescope-github.nvim' - -" Treesitter -Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} -Plug 'nvim-treesitter/nvim-treesitter-refactor' -Plug 'romgrk/nvim-treesitter-context' - -Plug 'kyazdani42/nvim-web-devicons' -Plug 'romgrk/barbar.nvim' - -" Tmux essentials -Plug 'christoomey/vim-tmux-navigator' - -" Cosmetic -Plug 'cocopon/iceberg.vim' -Plug 'cocopon/colorswatch.vim' - -" Helpful cosmetic -Plug 'airblade/vim-gitgutter' " Show git status for lines in gutter -Plug 'vim-airline/vim-airline' - -" Helpful -Plug 'junegunn/vim-slash' " Automatically clears search highlight when cursor is moved (and more) -Plug 'junegunn/vim-peekaboo' " Show the contents of registers -Plug 'Raimondi/delimitMate' " Auto-close parans, brackets, quotes, etc. -Plug 'alvan/vim-closetag' " Auto-close XML-like tags -Plug 'pbrisbin/vim-mkdir' " Automatically create any non-existant directories before writing the buffer -Plug 'wellle/targets.vim' " Adds more text objects - -Plug 'soywod/himalaya', {'rtp': 'vim'} - -" Additional Syntax -Plug 'neoclide/jsonc.vim' - -" Personal time tracking -Plug 'wakatime/vim-wakatime' - -" Writing -Plug 'jceb/vim-orgmode' -Plug 'vimwiki/vimwiki' -Plug 'lervag/vimtex' -Plug 'junegunn/goyo.vim' -Plug 'junegunn/limelight.vim' -Plug 'reedes/vim-pencil' -Plug 'reedes/vim-wordy' -Plug 'reedes/vim-litecorrect' -Plug 'kana/vim-textobj-user' -Plug 'reedes/vim-textobj-quote' -Plug 'reedes/vim-textobj-sentence' -Plug 'reedes/vim-lexical' - -Plug 'tridactyl/vim-tridactyl' - -call plug#end() - -" Allow filetype plugins -filetype plugin indent on - -" Enable syntax -syntax on -syntax enable - -" I am Canadian -set spelllang=en_ca - -" tmux + alacritty + color scheme related -set t_Co=256 -if &term =~ '256color' | set t_ut= | endif -if (has("nvim")) - let $NVIM_TUI_ENABLE_TRUE_COLOR=1 -endif -if (has("termguicolors")) - set termguicolors -endif - -" Colorscheme in dark mode [iceberg.vim] -colorscheme iceberg -if has('mac') - if system("defaults read -g AppleInterfaceStyle") =~ '^Dark' - set background=dark - else - set background=light - endif -elseif has('unix') - set background=dark -endif - -" For terminal title -set title - -" Cosmetic -set number -set ruler -set signcolumn=yes -set noshowmode - -" Split behaviour -set splitbelow -set splitright - -" Tabs (default width 2, style spaces) -set tabstop=2 -set softtabstop=0 -set shiftwidth=0 -set expandtab -set smarttab -set smartindent -set nojoinspaces -set emoji - -" Wrap at 80 for text -set textwidth=80 - -" Fold all the things -set foldlevel=0 -set foldmethod=syntax -set foldtext=CustomFoldText('.') -set fillchars=fold:. - -" Allow mouse -set mouse=n - -" Use system clipboard -set clipboard+=unnamed -set clipboard+=unnamedplus - -" Perf -set ttyfast -set updatetime=250 - -" LSP plugins like this -set hidden -set nobackup -set nowritebackup - -" Highlight tweaks (pairs well with terminal transparency) -highlight NonText guibg=NONE ctermbg=NONE -highlight Normal guibg=NONE ctermbg=NONE -highlight EndOfBuffer guibg=NONE ctermbg=NONE -highlight LineNr guibg=NONE ctermbg=NONE - -" Disable arrow keys for navigation -noremap -noremap -noremap -noremap - -" Easier split navigation (aligns with Tmux) -map h -map j -map k -map l - -" Fuzzy find files [fzf.vim] -nnoremap :Files! - -" Italicize word [vim-surround] -nmap i TveS_ -let g:surround_{char2nr('i')} = "_\r_" - -" Embolden word [vim-surround] -nmap b TveS*gvS* -let g:surround_{char2nr('b')} = "**\r**" - -" Close XML-like tags in JS and JSX files (i.e. for React) [closetag] -let g:closetag_filenames = '*.js,*.jsx' - -" vimwiki config [vimwiki] -let g:vimwiki_list = [ - \ { 'path': '~/wiki', 'syntax': 'markdown', 'ext': '.md', 'index': 'main'} -\] -let g:vimwiki_global_ext = 0 " Do not use vimwiki for every Markdown file -let g:vimwiki_auto_header = 1 " Add a header to new files -let g:vimwiki_header_type = '#' " Use Markdown headers - -" Avoid truncation in Git commit message subject lines + improve body readability -autocmd FileType gitcommit set tw=72 cc=51,+1 - -" Auto-source this file it’s written -augroup vimrc - autocmd! - autocmd BufWritePost $MYVIMRC source $MYVIMRC -augroup end - -" Improve auto closing of stuff for files with JSX [delimitMate] -autocmd FileType javascript,javascriptreact,typescript,typescriptreact let b:delimitMate_matchpairs = "(:),[:],{:}" - -" Use JSONC for config files that support it [jsonc] -autocmd BufNewFile,BufRead {.eslintrc,tsconfig}.json set syntax=json filetype=jsonc - -" Writing [pencil,litecorrect] -let g:pencil#wrapModeDefault = 'soft' -augroup pencil - autocmd! - autocmd FileType tex,markdown,gitcommit - \ | call pencil#init() - \ | call lexical#init() - \ | call litecorrect#init() - \ | call textobj#quote#init() - autocmd FileType markdown,tex set tw=72 -augroup end - -let g:airline_section_x = '%{PencilMode()}' -let g:pencil#mode_indicators = {'hard': 'H', 'auto': 'A', 'soft': 'S', 'off': '',} - -" Typewriting mode [goyo,limelight] -" the real mvp: https://github.com/junegunn/limelight.vim/issues/39#issuecomment-466664354 -let g:limelight_conceal_ctermfg = '#3e445e' -let g:limelight_conceal_guifg = '#3e445e' - -function! s:goyo_enter() - let b:quitting = 0 - let b:quitting_bang = 0 - autocmd QuitPre let b:quitting = 1 - cabbrev q! let b:quitting_bang = 1 q! - - if executable('tmux') && strlen($TMUX) - silent !tmux set status off - silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z - endif - silent !yabai -m window mouse --toggle native-fullscreen - set noshowmode - set noshowcmd - set scrolloff=999 - nmap j jzz - nmap k kzz - nmap G Gzz - nmap gg ggzz - Limelight - let &l:statusline = '%M' -endfunction - -function! s:goyo_leave() - if executable('tmux') && strlen($TMUX) - silent !tmux set status on - silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z - endif - silent !yabai -m window mouse --toggle native-fullscreen - - " Quit Vim if this is the only remaining buffer - if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 - if b:quitting_bang - qa! - else - qa - endif - endif - - set showmode - set showcmd - set scrolloff=5 - Limelight! -endfunction - -autocmd! User GoyoEnter nested call goyo_enter() -autocmd! User GoyoLeave nested call goyo_leave() - -" Use Ripgrep + FZF for fuzzy searching code (source: FZF plugin README) [fzf.vim + ripgrep] -function! RipgrepFzf(query, fullscreen) - let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true' - let initial_command = printf(command_fmt, shellescape(a:query)) - let reload_command = printf(command_fmt, '{q}') - let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} - call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen) -endfunction -command! -nargs=* -bang RG call RipgrepFzf(, 0) -nmap r :Rg! - -" Copied from Yoshua Wuyts -" https://github.com/yoshuawuyts/dotfiles/blob/93cb44331fdfe09a942c81e33511c61d9db2b662/vim/vimrc#L81-L124 -function! CustomFoldText(string) - let fs = v:foldstart - - while getline(fs) =~ '^\s*$' | let fs = nextnonblank(fs + 1) - endwhile - - if fs > v:foldend - let line = getline(v:foldstart) - else - let line = substitute(getline(fs), '\t', repeat(' ', &tabstop), 'g') - endif - - let pat = matchstr(&l:cms, '^\V\.\{-}\ze%s\m') - let line = substitute(line, '^\s*'.pat.'\s*', '', '') - let pat = '\%('. pat. '\)\?\s*'. split(&l:fmr, ',')[0]. '\s*\d\+' - let line = substitute(line, pat, '', '') - - let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0) - - let foldSize = 1 + v:foldend - v:foldstart - let foldSizeStr = " " . foldSize . " " - let foldLevelStr = ' ' - let lineCount = line("$") - if has("float") - try - let foldPercentage = printf("[%.0f", (foldSize*1.0)/lineCount*100) . "%] " - catch /^Vim\%((\a\+)\)\=:E806/ " E806: Using Float as String - let foldPercentage = printf("[of %d] ", lineCount) - endtry - endif - if exists("*strwdith") - let expansionString = repeat(a:string, w - strwidth(foldSizeStr.line.foldLevelStr.foldPercentage)) - else - let expansionString = repeat(a:string, w - strlen(substitute(foldSizeStr.line.foldLevelStr.foldPercentage, '.', 'x', 'g'))) - endif - return line . ' ' . expansionString . foldSizeStr . foldPercentage . foldLevelStr -endf - -" Paper writing auto commands -augroup paper - autocmd! - autocmd BufRead paper.tex VimtexCompile - autocmd BufWritePost paper.tex silent !gitupdate % & -augroup end - -lua require'lsp_config' -lua require'treesitter_config' - -" Set completeopt to have a better completion experience -set completeopt=menuone,noselect - -" Avoid showing message extra message when using completion -set shortmess+=c - -let g:compe = {} -let g:compe.enabled = v:true -let g:compe.autocomplete = v:true -let g:compe.debug = v:false -let g:compe.min_length = 1 -let g:compe.preselect = 'always' -let g:compe.throttle_time = 80 -let g:compe.source_timeout = 200 -let g:compe.incomplete_delay = 400 -let g:compe.max_abbr_width = 100 -let g:compe.max_kind_width = 100 -let g:compe.max_menu_width = 100 -let g:compe.documentation = v:true - -let g:compe.source = {} -let g:compe.source.path = v:true -let g:compe.source.buffer = v:true -let g:compe.source.calc = v:true -let g:compe.source.nvim_lsp = v:true -let g:compe.source.nvim_lua = v:true -"let g:compe.source.vsnip = v:true - -inoremap compe#complete() -inoremap compe#confirm('') -inoremap compe#close('') -inoremap compe#scroll({ 'delta': +4 }) -inoremap compe#scroll({ 'delta': -4 }) - -" Run a command on the current file in a tmux split -nnoremap h :execute '!tmux split-pane -bh "tmux set-option remain-on-exit on;'.input('run left: ').' %"' -nnoremap j :execute '!tmux split-pane "tmux set-option remain-on-exit on;'.input('run below: ').' %"' -nnoremap k :execute '!tmux split-pane -b "tmux set-option remain-on-exit on;'.input('run above: ').' %"' -nnoremap l :execute '!tmux split-pane -h "tmux set-option remain-on-exit on;'.input('run right: ').' %"' diff --git a/.config/nvim/lua/base.lua b/.config/nvim/lua/base.lua new file mode 100644 index 0000000..b953a15 --- /dev/null +++ b/.config/nvim/lua/base.lua @@ -0,0 +1,37 @@ +local utils = require'utils' +local opt = utils.opt +local buffer = utils.buffer +local window = utils.window +local cmd = vim.cmd + +opt('compatible', false) + +cmd [[filetype plugin indent on]] +cmd [[syntax on]] +cmd [[syntax enable]] + +opt('title', true) +opt('mouse', 'n') +opt('ruler', true) +opt('showmode', false) +opt('clipboard', 'unnamed,unnamedplus') +opt('splitbelow', true) +opt('splitright', true) +opt('smarttab', true) +opt('smartindent', true) +opt('joinspaces', false) +opt('ttyfast', true) +opt('updatetime', 250) +opt('hidden', true) +opt('backup', false) +opt('writebackup', false) +opt('completeopt', 'menuone,noselect') + +opt('number', true, window) +opt('signcolumn', 'yes', window) + +opt('tabstop', 2, buffer) +opt('softtabstop', 0, buffer) +opt('shiftwidth', 0, buffer) +opt('expandtab', true, buffer) +opt('textwidth', 80, buffer) diff --git a/.config/nvim/lua/colors.lua b/.config/nvim/lua/colors.lua new file mode 100644 index 0000000..52fdc5a --- /dev/null +++ b/.config/nvim/lua/colors.lua @@ -0,0 +1,14 @@ +local utils = require'utils' +local opt = utils.opt +local cmd = vim.cmd + +opt('t_Co', '256') +cmd [[if &term =~ '256color' | set t_ut= | endif]] +cmd [[let $NVIM_TUI_ENABLE_TRUE_COLOR=1]] +opt('termguicolors', true) +cmd [[colorscheme iceberg]] +opt('background', 'dark') +cmd [[highlight NonText guibg=NONE ctermbg=NONE]] +cmd [[highlight Normal guibg=NONE ctermbg=NONE]] +cmd [[highlight EndOfBuffer guibg=NONE ctermbg=NONE]] +cmd [[highlight LineNr guibg=NONE ctermbg=NONE]] diff --git a/.config/nvim/lua/completion.lua b/.config/nvim/lua/completion.lua new file mode 100644 index 0000000..5937111 --- /dev/null +++ b/.config/nvim/lua/completion.lua @@ -0,0 +1,22 @@ +return require'compe'.setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'always'; + throttle_time = 80; + source_timeout = 200; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = true; + source = { + path = true; + buffer = true; + calc = true; + nvim_lsp = true; + nvim_lua = true; + vsnip = true; + }; +} diff --git a/.config/nvim/lua/keymap.lua b/.config/nvim/lua/keymap.lua new file mode 100644 index 0000000..f0dc7a4 --- /dev/null +++ b/.config/nvim/lua/keymap.lua @@ -0,0 +1,20 @@ +local map = require'utils'.map +local cmd = vim.cmd + +map('n', '', '') +map('n', '', '') +map('n', '', '') +map('n', '', '') + +map('n', '', 'h') +map('n', '', 'j') +map('n', '', 'k') +map('n', '', 'l') + +map('n', '', ':Files!') + +cmd [[inoremap compe#complete()]] +cmd [[inoremap compe#confirm('')]] +cmd [[inoremap compe#close('')]] +cmd [[inoremap compe#scroll({ 'delta': +4 })]] +cmd [[inoremap compe#scroll({ 'delta': -4 })]] diff --git a/.config/nvim/lua/lsp-config.lua b/.config/nvim/lua/lsp-config.lua new file mode 100644 index 0000000..219e2e1 --- /dev/null +++ b/.config/nvim/lua/lsp-config.lua @@ -0,0 +1,48 @@ +local lsp = require'lspconfig' + +local prettier = { + formatCommand = "prettier --stdin-filepath ${INPUT}", + formatStdin = true, +} + +local eslint = { + lintCommand = "eslint -f unix --stdin --stdin-filepath ${INPUT}", + lintIgnoreExitCode = true, + lintStdin = true, + lintFormats = {"%f:%l:%c: %m"}, +} + +lsp.cssls.setup {} +lsp.efm.setup { + init_options = { + codeAction = true, + documentFormatting = true, + }, + settings = { + rootMarkers = {".git/"}, + languages = { + javascript = {prettier, eslint}, + javascriptreact = {prettier, eslint}, + ['javascript.jsx'] = {prettier, eslint}, + }, + log_level = 1, + log_file = "~/efm.log", + }, + filetypes = { + 'javascript', + 'javascriptreact', + 'javascript.jsx', + }, + on_attach = on_attach, +} +lsp.html.setup {} +lsp.intelephense.setup {} +lsp.jsonls.setup {} +lsp.sumneko_lua.setup {} +lsp.tsserver.setup { + on_attach = function(client, bufnr) + client.resolved_capabilities.document_formatting = false + end, + settings = {documentFormatting = false}, +} +lsp.vimls.setup {} diff --git a/.config/nvim/lua/lsp_config.lua b/.config/nvim/lua/lsp_config.lua deleted file mode 100644 index 2b8ce85..0000000 --- a/.config/nvim/lua/lsp_config.lua +++ /dev/null @@ -1,63 +0,0 @@ -local lsp = require'lspconfig' - ---lsp.bashls.setup{} -lsp.cssls.setup{} -lsp.dockerls.setup{} ---lsp.graphql.setup{} -lsp.html.setup{} -lsp.intelephense.setup{} -lsp.jsonls.setup{} -lsp.rust_analyzer.setup{} -lsp.sumneko_lua.setup{} -lsp.texlab.setup{} -lsp.tsserver.setup{} -lsp.vimls.setup{} - --- Diagnostics (i.e. ESLint, Prettier, etc.) -lsp.diagnosticls.setup{ - filetypes = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", - }, - init_options = { - linters = { - eslint = { - command = "yarn eslint", - args = { "--stdin", "--stdin-filename", "%filepath", "--format", "json" }, - rootPatterns = { ".git" }, - sourceName = "eslint", - debounce = 100, - parseJson = { - errorsRoot = "[0].messages", - line = "line", - column = "column", - endLine = "endLine", - endColumn = "endColumn", - message = "[eslint] ${message} [${ruleId}]", - security = "severity", - }, - }, - }, - filetypes = { - javascript = "eslint", - javascriptreact = "eslint", - typescript = "eslint", - typescriptreact = "eslint", - }, - formatters = { - prettier = { - command = "yarn prettier", - args = { "--stdin-filepath", "%filename" }, - }, - }, - formatFiletypes = { - javascript = "prettier", - javascriptreact = "prettier", - json = "prettier", - }, - }, -} diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..135ce68 --- /dev/null +++ b/.config/nvim/lua/plugins.lua @@ -0,0 +1,41 @@ +return require'packer'.startup(function () + --Packer + use 'wbthomason/packer.nvim' + + --Essentials + use 'AndrewRadev/splitjoin.vim' -- Easily switch between single and multi line format for stuff (split: gS | join: gJ) + use 'airblade/vim-gitgutter' -- Show git status for lines in gutter + use 'pbrisbin/vim-mkdir' -- Automatically create any non-existant directories before writing the buffer + use 'christoomey/vim-tmux-navigator' + use 'cocopon/iceberg.vim' -- Colour scheme + use 'editorconfig/editorconfig-vim' + use 'junegunn/vim-peekaboo' -- Show the contens of registers + use 'junegunn/vim-slash' -- Automatically clears search highlight when cursor is moved (and more) + use 'junegunn/fzf' -- Fuzzy find stuff + use 'junegunn/fzf.vim' + use 'junegunn/goyo.vim' + use 'junegunn/limelight.vim' + use 'Raimondi/delimitMate' + use 'tpope/vim-fugitive' + use 'tpope/vim-surround' + use 'vim-airline/vim-airline' + use 'wakatime/vim-wakatime' -- Personal time tracking + + --LSP + use { + 'neovim/nvim-lspconfig', + config = function () require'lsp-config' end + } + + use { + 'nvim-treesitter/nvim-treesitter', + run = function () vim.cmd [[TSUpdate]] end, + config = function () require'treesitter-config' end + } + + --Completion + use { + 'hrsh7th/nvim-compe', + config = function () require'completion' end + } +end) diff --git a/.config/nvim/lua/treesitter-config.lua b/.config/nvim/lua/treesitter-config.lua new file mode 100644 index 0000000..9da78ef --- /dev/null +++ b/.config/nvim/lua/treesitter-config.lua @@ -0,0 +1,6 @@ +require'nvim-treesitter.configs'.setup{ + ensure_installed = "maintained", + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { enable = true }, +} diff --git a/.config/nvim/lua/treesitter_config.lua b/.config/nvim/lua/treesitter_config.lua deleted file mode 100644 index 59fff7c..0000000 --- a/.config/nvim/lua/treesitter_config.lua +++ /dev/null @@ -1,21 +0,0 @@ -require'nvim-treesitter.configs'.setup{ - ensure_installed = "maintained", - highlight = { enable = true }, - incremental_selection = { enable = true }, - indent = { enable = true }, - refactor = { - navigation = { - enable = true, - keymaps = { - goto_definition = "gnd", - list_definitions = "gnD", - list_definitions_toc = "gO", - goto_next_usage = "gnU", - goto_previous_usage = "gpU", - }, - }, - smart_rename = { enable = true }, - highlight_definitions = { enable = true }, - highlight_current_scope = { enable = false }, - }, -} diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua new file mode 100644 index 0000000..a5c0da9 --- /dev/null +++ b/.config/nvim/lua/utils.lua @@ -0,0 +1,34 @@ +-- Credit: https://github.com/wbthomason/dotfiles/blob/b5525f6899a70294c7f3db9c237f3c2cdab1dfb4/neovim/.config/nvim/lua/config/utils.lua + +local cmd = vim.cmd +local o_s = vim.o +local map_key = vim.api.nvim_set_keymap + +local function opt(o, v, scopes) + scopes = scopes or {o_s} + for _, s in ipairs(scopes) do s[o] = v end +end + +local function autocmd(group, cmds, clear) + clear = clear == nil and false or clear + if type(cmds) == 'string' then cmds = {cmds} end + cmd('augroup ' .. group) + if clear then cmd [[au!]] end + for _, c in ipairs(cmds) do cmd('autocmd ' .. c) end + cmd [[augroup END]] +end + +local function map(modes, lhs, rhs, opts) + opts = opts or {} + opts.noremap = opts.noremap == nil and true or opts.noremap + if type(modes) == 'string' then modes = {modes} end + for _, mode in ipairs(modes) do map_key(mode, lhs, rhs, opts) end +end + +return { + autocmd = autocmd, + buffer = {vim.o, vim.bo}, + map = map, + opt = opt, + window = {vim.o, vim.wo}, +} -- 2.51.2