Better comments, nerdtree settings

This commit is contained in:
2026-03-20 15:29:18 +00:00
parent 11c0395f8d
commit 83505fd0a2
+91 -27
View File
@@ -1,3 +1,4 @@
" Basic editor behavior
set relativenumber
set number
set autoindent
@@ -5,29 +6,30 @@ set clipboard+=unnamed " Use system clipboard
set termguicolors
set cursorline
set ts=4 sw=4
"gets rid of --INSERT-- useful bc of lighline"
" Lightline already shows the current mode, so hide the default mode text.
set noshowmode
set mouse=a
"splits"
" Open new splits in the more common IDE-like directions.
set splitright
set splitbelow
" Plugins
call plug#begin()
"file explorer"
" File explorer
Plug 'preservim/nerdtree'
"status line"
" Status line
Plug 'itchyny/lightline.vim'
"color themes"
" Colorschemes
Plug 'gilgigilgil/anderson.vim'
Plug 'sainnhe/sonokai'
"automatic parentheses"
" Automatic bracket and quote pairing
Plug 'jiangmiao/auto-pairs'
"syntax highlighting"
" Syntax highlighting and structural selection
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
"shortcut to comment multiple lines"
" Commenting helpers
Plug 'numToStr/Comment.nvim'
" Completion and snippet support
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
@@ -35,7 +37,7 @@ Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" For vsnip users.
" Snippet backend used by nvim-cmp
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
@@ -43,15 +45,56 @@ call plug#end()
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
" Start NERDTree fullscreen if no file specified, otherwise open in split
" 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 <leader>n :NERDTreeFocus<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
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 = {
@@ -67,34 +110,44 @@ let g:NERDTreeGitStatusWithFlags = 1
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
require'nvim-treesitter.configs'.setup {
-- Install parsers for languages you use
ensure_installed = { "c", "cpp", "python", "lua", "vim", "go", "html", "css", "javascript", "ocaml"},
-- 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
-- Install all maintained parsers
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",
-- Syntax highlighting
-- Treesitter-powered syntax highlighting.
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
-- Indentation based on treesitter (experimental)
-- Treesitter indentation where supported.
indent = {
enable = true
},
-- Incremental selection based on the syntax tree
-- Grow and shrink selections by syntax node instead of by raw text.
incremental_selection = {
enable = true,
keymaps = {
@@ -104,19 +157,24 @@ require'nvim-treesitter.configs'.setup {
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 <<EOF
-- Set up nvim-cmp.
-- Completion setup
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
-- nvim-cmp needs a snippet expansion function, and this config uses vsnip.
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
@@ -140,7 +198,14 @@ lua <<EOF
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
-- Use Tab to confirm the current completion item, otherwise keep normal Tab behavior.
['<Tab>'] = 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' },
@@ -153,8 +218,7 @@ lua <<EOF
})
})
-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
-- Set configuration for specific filetype.
-- Example git completion setup left commented out for future use.
--[[ cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
@@ -164,7 +228,7 @@ lua <<EOF
})
require("cmp_git").setup() ]]--
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
-- Use buffer completion while searching with `/` or `?`.
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
@@ -172,7 +236,7 @@ lua <<EOF
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
-- Use path and command completion for `:`.
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
@@ -183,7 +247,7 @@ lua <<EOF
matching = { disallow_symbol_nonprefix_matching = false }
})
-- Set up lspconfig.
-- Placeholder LSP wiring kept here because cmp-nvim-lsp is installed.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
vim.lsp.config('<YOUR_LSP_SERVER>', {