" Basic editor behavior set relativenumber set number set autoindent set clipboard+=unnamed " Use system clipboard set termguicolors set cursorline set ts=4 sw=4 " Lightline already shows the current mode, so hide the default mode text. set noshowmode set mouse=a " Open new splits in the more common IDE-like directions. set splitright set splitbelow " Plugins call plug#begin() " File explorer Plug 'preservim/nerdtree' " Status line Plug 'itchyny/lightline.vim' " Colorschemes Plug 'gilgigilgil/anderson.vim' Plug 'sainnhe/sonokai' " Automatic bracket and quote pairing Plug 'jiangmiao/auto-pairs' " Syntax highlighting and structural selection Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Commenting helpers Plug 'numToStr/Comment.nvim' " Completion and snippet support Plug 'neovim/nvim-lspconfig' Plug 'hrsh7th/cmp-nvim-lsp' Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/cmp-path' Plug 'hrsh7th/cmp-cmdline' Plug 'hrsh7th/nvim-cmp' " Snippet backend used by nvim-cmp Plug 'hrsh7th/cmp-vsnip' Plug 'hrsh7th/vim-vsnip' call plug#end() let $NVIM_TUI_ENABLE_TRUE_COLOR=1 " NERDTree startup behavior " - No file argument: open the tree fullscreen. " - File argument or stdin: open the tree on the side and return focus to the file. " - If the tree is the last remaining window, quit Neovim. autocmd StdinReadPre * let s:std_in=1 autocmd VimEnter * call s:RegisterNERDTreeVSplitOverride() autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | execute 'NERDTree' | only | endif autocmd VimEnter * if argc() > 0 || exists("s:std_in") | NERDTree | wincmd p | endif autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif " Close NERDTree after opening a file from it. let g:NERDTreeQuitOnOpen = 1 " Open a file from NERDTree in a vertical split and close the tree. function! NERDTreeOpenVSplitAndClose(node) abort call a:node.activate({'where': 'v', 'keepopen': 0}) endfunction " Same behavior as above, but for bookmarked nodes. function! NERDTreeOpenVSplitBookmarkAndClose(bookmark) abort call a:bookmark.activate(b:NERDTree, !a:bookmark.path.isDirectory ? {'where': 'v', 'keepopen': 0} : {}) endfunction " Override NERDTree's default `s` action once the plugin has been loaded. function! s:RegisterNERDTreeVSplitOverride() abort if !exists('*NERDTreeAddKeyMap') return endif call NERDTreeAddKeyMap({ \ 'key': 's', \ 'scope': 'FileNode', \ 'callback': 'NERDTreeOpenVSplitAndClose', \ 'quickhelpText': 'open vsplit and close tree', \ 'override': 1 \ }) call NERDTreeAddKeyMap({ \ 'key': 's', \ 'scope': 'Bookmark', \ 'callback': 'NERDTreeOpenVSplitBookmarkAndClose', \ 'quickhelpText': 'open vsplit and close tree', \ 'override': 1 \ }) endfunction " Core NERDTree shortcuts nnoremap n :NERDTreeFocus nnoremap :NERDTreeToggle let g:NERDTreeGitStatusWithFlags = 1 " Example icon and color overrides kept here for later use. "let g:WebDevIconsUnicodeDecorateFolderNodes = 1 "let g:NERDTreeGitStatusNodeColorization = 1 "let g:NERDTreeColorMapCustom = { "\ "Staged" : "#0ee375", "\ "Modified" : "#d9bf91", "\ "Renamed" : "#51C9FC", "\ "Untracked" : "#FCE77C", "\ "Unmerged" : "#FC51E6", "\ "Dirty" : "#FFBD61", "\ "Clean" : "#87939A", "\ "Ignored" : "#808080" "\ } let g:NERDTreeIgnore = ['^node_modules$'] " Lightline appearance let g:lightline = { \ 'colorscheme': 'wombat', \ } " Colorscheme configuration let g:sonokai_style = 'shusia' let g:sonokai_better_performance = 1 colorscheme sonokai lua << EOF -- Treesitter config: prefer the older `configs` entrypoint, but fall back to -- the newer top-level module for the version currently installed locally. local ok, ts = pcall(require, 'nvim-treesitter.configs') if not ok then ok, ts = pcall(require, 'nvim-treesitter') end if ok then ts.setup { -- Parsers to install automatically. ensure_installed = { "c", "cpp", "python", "lua", "vim", "go", "html", "css", "javascript", "ocaml" }, -- Install all maintained parsers instead. -- ensure_installed = "all", -- Treesitter-powered syntax highlighting. highlight = { enable = true, additional_vim_regex_highlighting = false, }, -- Treesitter indentation where supported. indent = { enable = true }, -- Grow and shrink selections by syntax node instead of by raw text. incremental_selection = { enable = true, keymaps = { init_selection = "gnn", node_incremental = "grn", scope_incremental = "grc", node_decremental = "grm", }, } } else -- Keep startup working even if Treesitter is installed incorrectly. vim.notify('nvim-treesitter is installed but could not be loaded', vim.log.levels.WARN) end -- Enable default comment mappings like gcc and gc. require('Comment').setup() EOF lua <'] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), -- Use Tab to confirm the current completion item, otherwise keep normal Tab behavior. [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.confirm({ select = true }) else fallback() end end, { 'i', 's' }), }), 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' }, }) }) -- Example git completion setup left commented out for future use. --[[ cmp.setup.filetype('gitcommit', { sources = cmp.config.sources({ { name = 'git' }, }, { { name = 'buffer' }, }) }) require("cmp_git").setup() ]]-- -- Use buffer completion while searching with `/` or `?`. cmp.setup.cmdline({ '/', '?' }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = 'buffer' } } }) -- Use path and command completion for `:`. cmp.setup.cmdline(':', { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' } }, { { name = 'cmdline' } }), matching = { disallow_symbol_nonprefix_matching = false } }) -- Placeholder LSP wiring kept here because cmp-nvim-lsp is installed. local capabilities = require('cmp_nvim_lsp').default_capabilities() -- Replace with each lsp server you've enabled. vim.lsp.config('', { capabilities = capabilities }) vim.lsp.enable('') EOF