From b206ad38f081bee85660eeb5047c8f6865c50478 Mon Sep 17 00:00:00 2001 From: Alec Goncharow Date: Sat, 25 Feb 2023 15:06:03 -0600 Subject: It works? --- .config/nvim/init.lua | 6 ++++ .config/nvim/lua/autocomplete.lua | 72 +++++++++++++++++++++++++++------------ .config/nvim/lua/highlighting.lua | 47 +++++++++++++++++++++++++ .config/nvim/lua/lsp.lua | 5 +++ .config/nvim/lua/plugins.lua | 21 +++++++++--- .config/nvim/lua/powerline.lua | 4 +-- .config/nvim/lua/settings.lua | 26 +++++++++++--- .config/nvim/lua/treesitter.lua | 41 ++++++++++++++++++++++ 8 files changed, 190 insertions(+), 32 deletions(-) create mode 100644 .config/nvim/lua/highlighting.lua create mode 100644 .config/nvim/lua/treesitter.lua (limited to '.config') diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 549285c..898674a 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,5 +2,11 @@ require('plugins') require('settings') require('mappings') require('lsp') +require('treesitter') +require('highlighting') require('autocomplete') require('powerline') + + +-- plugins +require('neoscroll').setup() diff --git a/.config/nvim/lua/autocomplete.lua b/.config/nvim/lua/autocomplete.lua index 5213258..1f8798d 100644 --- a/.config/nvim/lua/autocomplete.lua +++ b/.config/nvim/lua/autocomplete.lua @@ -1,22 +1,52 @@ -local cmp = require("cmp") + -- Set up nvim-cmp. + local cmp = require'cmp' + + cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, + }) + }) + + -- Set configuration for specific filetype. + cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = 'buffer' }, + }) + }) + + -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). + cmp.setup.cmdline({ '/', '?' }, { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = 'buffer' } + } + }) -cmp.setup({ - mapping = cmp.mapping.preset.insert({ -- Preset: ^n, ^p, ^y, ^e, you know the drill.. - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - }), - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "nvim_lsp_signature_help" }, - { name = "nvim_lua" }, - { name = "luasnip" }, - { name = "path" }, - }, { - { name = "buffer", keyword_length = 3 }, - }), -}) diff --git a/.config/nvim/lua/highlighting.lua b/.config/nvim/lua/highlighting.lua new file mode 100644 index 0000000..9c4332d --- /dev/null +++ b/.config/nvim/lua/highlighting.lua @@ -0,0 +1,47 @@ +-- default configuration +require('illuminate').configure({ + -- providers: provider used to get references in the buffer, ordered by priority + providers = { + 'lsp', + 'treesitter', + 'regex', + }, + -- delay: delay in milliseconds + delay = 100, + -- filetype_overrides: filetype specific overrides. + -- The keys are strings to represent the filetype while the values are tables that + -- supports the same keys passed to .configure except for filetypes_denylist and filetypes_allowlist + filetype_overrides = {}, + -- filetypes_denylist: filetypes to not illuminate, this overrides filetypes_allowlist + filetypes_denylist = { + 'dirvish', + 'fugitive', + }, + -- filetypes_allowlist: filetypes to illuminate, this is overriden by filetypes_denylist + filetypes_allowlist = {}, + -- modes_denylist: modes to not illuminate, this overrides modes_allowlist + -- See `:help mode()` for possible values + modes_denylist = {}, + -- modes_allowlist: modes to illuminate, this is overriden by modes_denylist + -- See `:help mode()` for possible values + modes_allowlist = {}, + -- providers_regex_syntax_denylist: syntax to not illuminate, this overrides providers_regex_syntax_allowlist + -- Only applies to the 'regex' provider + -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') + providers_regex_syntax_denylist = {}, + -- providers_regex_syntax_allowlist: syntax to illuminate, this is overriden by providers_regex_syntax_denylist + -- Only applies to the 'regex' provider + -- Use :echom synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') + providers_regex_syntax_allowlist = {}, + -- under_cursor: whether or not to illuminate under the cursor + under_cursor = true, + -- large_file_cutoff: number of lines at which to use large_file_config + -- The `under_cursor` option is disabled when this cutoff is hit + large_file_cutoff = nil, + -- large_file_config: config to use for large files (based on large_file_cutoff). + -- Supports the same keys passed to .configure + -- If nil, vim-illuminate will be disabled for large files. + large_file_overrides = nil, + -- min_count_to_highlight: minimum number of matches required to perform highlighting + min_count_to_highlight = 1, +}) diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua index 65eaedc..8a8d603 100644 --- a/.config/nvim/lua/lsp.lua +++ b/.config/nvim/lua/lsp.lua @@ -43,5 +43,10 @@ require("rust-tools").setup({ }) +-- close quickfix menu after selecting choice +vim.api.nvim_create_autocmd( + "FileType", { + pattern={"qf"}, + command=[[nnoremap :cclose]]}) -- local autocmd = vim.api.nvim_create_autocmd -- autocmd({ "BufLeave" }, { pattern = { "*" }, command = "if &buftype == 'quickfix'|q|endif" }) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 165139e..a9e206c 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -4,7 +4,7 @@ return require('packer').startup(function() use 'wbthomason/packer.nvim' use 'morhetz/gruvbox' - use 'psliwka/vim-smoothie' + use 'karb94/neoscroll.nvim' use 'edkolev/tmuxline.vim' use 'romainl/vim-cool' @@ -19,6 +19,8 @@ return require('packer').startup(function() use 'rhysd/git-messenger.vim' + use 'luochen1990/rainbow' + use 'RRethy/vim-illuminate' -- better quickfix buffer use {'kevinhwang91/nvim-bqf', ft = 'qf', @@ -26,7 +28,6 @@ return require('packer').startup(function() require("bqf").setup { -- your configuration comes here -- or leave it empty to use the default settings - -- refer to the configuration section below } end } @@ -35,7 +36,18 @@ return require('packer').startup(function() -- general dev use 'neovim/nvim-lspconfig' use 'kabouzeid/nvim-lspinstall' - use 'glepnir/lspsaga.nvim' + use({ + "glepnir/lspsaga.nvim", + branch = "main", + config = function() + require("lspsaga").setup({}) + end, + requires = { + {"nvim-tree/nvim-web-devicons"}, + --Please make sure you install markdown and markdown_inline parser + {"nvim-treesitter/nvim-treesitter"} + } +}) use 'hrsh7th/nvim-cmp' use 'hrsh7th/cmp-buffer' use 'hrsh7th/cmp-nvim-lua' @@ -53,7 +65,6 @@ return require('packer').startup(function() require("which-key").setup { -- your configuration comes here -- or leave it empty to use the default settings - -- refer to the configuration section below } end } @@ -69,7 +80,7 @@ return require('packer').startup(function() use 'fatih/vim-go' -- rust - use 'rust-lang/rust.vim' + use 'rust-lang/rust.vim' use 'simrat39/rust-tools.nvim' -- debugging diff --git a/.config/nvim/lua/powerline.lua b/.config/nvim/lua/powerline.lua index 5bee6be..e7b41b5 100644 --- a/.config/nvim/lua/powerline.lua +++ b/.config/nvim/lua/powerline.lua @@ -20,7 +20,7 @@ require('lualine').setup { sections = { lualine_a = {'mode'}, lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {'filename'}, + lualine_c = {{'filename', path=1}}, lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_y = {'progress'}, lualine_z = {'location'} @@ -35,7 +35,7 @@ require('lualine').setup { }, tabline = { lualine_a = {'buffers'}, - lualine_b = {'branch'}, + lualine_b = {}, lualine_c = {}, lualine_x = {}, lualine_y = {}, diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua index cae0968..36d7949 100644 --- a/.config/nvim/lua/settings.lua +++ b/.config/nvim/lua/settings.lua @@ -1,7 +1,15 @@ +vim.cmd([[ + syntax enable + filetype plugin indent on +]]) + HOME = os.getenv("HOME") vim.g.mapleader = ' ' +vim.wo.cursorline = true +vim.opt.termguicolors = true + -- basic settings vim.o.encoding = "utf-8" vim.o.backspace = "indent,eol,start" -- backspace works on every char in insert mode @@ -25,10 +33,12 @@ vim.o.list = false -- do not display white characters vim.o.foldenable = false vim.o.foldlevel = 4 -- limit folding to 4 levels vim.o.foldmethod = 'syntax' -- use language syntax to generate folds -vim.o.wrap = false --do not wrap lines even if very long -vim.o.eol = false -- show if there's no eol char +vim.o.wrap = true --do not wrap lines even if very long +vim.o.eol = true -- show if there's no eol char vim.o.showbreak= '↪' -- character to show when line is broken +vim.opt.clipboard = 'unnamedplus' + -- Sidebar vim.o.number = true -- line number on the left vim.o.numberwidth = 3 -- always reserve 3 spaces for line number @@ -61,8 +71,6 @@ vim.o.backupdir = HOME .. '/.vim/tmp/backup//' -- backups vim.o.directory = '/.vim/tmp/swap//' -- swap files vim.cmd([[ - - au FileType python set ts=4 sw=4 au BufRead,BufNewFile *.md set ft=mkd tw=80 syntax=markdown au BufRead,BufNewFile *.ppmd set ft=mkd tw=80 syntax=markdown @@ -86,3 +94,13 @@ hi EndOfBuffer guibg=none ctermbg=none -- Commands mode vim.o.wildmenu = true -- on TAB, complete options for system command vim.o.wildignore = 'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc' + +-- https://sharksforarms.dev/posts/neovim-rust/ +local format_sync_grp = vim.api.nvim_create_augroup("Format", {}) +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.rs", + callback = function() + vim.lsp.buf.format({ timeout_ms = 200 }) + end, + group = format_sync_grp, +}) diff --git a/.config/nvim/lua/treesitter.lua b/.config/nvim/lua/treesitter.lua new file mode 100644 index 0000000..a09ad16 --- /dev/null +++ b/.config/nvim/lua/treesitter.lua @@ -0,0 +1,41 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the four listed parsers should always be installed) + ensure_installed = {"rust", "c", "lua", "vim", "help" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + -- List of parsers to ignore installing (for "all") + ignore_install = { }, + + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + + highlight = { + enable = false, + + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + disable = { }, + -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, +} -- cgit v1.2.3-70-g09d2