.dotfiles

/src/neovim/core - Neovim Core Settings

1. Whatโ€™s in this directory and how to use it

This directory contains the foundational Neovim settings that configure editor behavior, performance optimizations, and basic functionality. These are loaded first before any plugins or custom configurations.

Files in this directory:

core/
โ”œโ”€โ”€ init.lua        # Module loader (364B)
โ”œโ”€โ”€ options.lua     # Editor options (2.5KB)
โ”œโ”€โ”€ performance.lua # Speed optimizations (1.9KB)
โ”œโ”€โ”€ backup.lua      # Backup/swap settings (641B)
โ”œโ”€โ”€ folding.lua     # Code folding config (386B)
โ”œโ”€โ”€ indentation.lua # Tab/space settings (310B)
โ””โ”€โ”€ search.lua      # Search behavior (325B)

How to use:

-- These are automatically loaded by config/init.lua
require('core')  -- Loads all core modules

-- Or load individually
require('config.core.options')
require('config.core.performance')

-- Check current settings
:set option?           -- View option value
:verbose set option?   -- See where it was set

Load order matters:

  1. performance.lua - Disable unused features first
  2. options.lua - Set general options
  3. indentation.lua - Configure tabs/spaces
  4. search.lua - Search behavior
  5. folding.lua - Code folding
  6. backup.lua - Backup/swap files

2. Why this directory exists

Purpose:

Core settings form the foundation that everything else builds upon. Wrong settings here can break plugins, slow down the editor, or cause unexpected behavior.

Why separate files:

  1. Logical grouping - Related settings together
  2. Easy debugging - Isolate problem areas
  3. Selective loading - Can disable specific modules
  4. Clear documentation - Each file has focused purpose
  5. Performance - Load only whatโ€™s needed

Why loaded first:

Why these specific settings:

3. Comprehensive overview

Module Details:

init.lua - Module Loader

-- Simple loader that requires all core modules
require('config.core.performance')  -- Must be first!
require('config.core.options')
require('config.core.backup')
-- etc...

options.lua - Editor Options

Key settings:

performance.lua - Speed Optimizations

Critical optimizations:

-- Disable unused providers (saves ~50ms)
g.loaded_python_provider = 0
g.loaded_ruby_provider = 0
g.loaded_node_provider = 0
g.loaded_perl_provider = 0

-- Disable built-in plugins (saves ~20ms)
g.loaded_gzip = 1
g.loaded_tarPlugin = 1
g.loaded_zipPlugin = 1

-- Large file optimizations
opt.synmaxcol = 1000  -- Syntax highlighting column limit
opt.maxmempattern = 2000  -- Pattern memory limit

-- LSP logging
vim.lsp.set_log_level("ERROR")  -- Reduce log spam

backup.lua - Data Protection

opt.backup = false      -- No backup files
opt.writebackup = false -- No backup during write
opt.swapfile = false    -- No swap files
opt.undofile = true     -- Persistent undo
opt.undodir = vim.fn.stdpath('data') .. '/undo'

folding.lua - Code Folding

opt.foldenable = true
opt.foldlevelstart = 99  -- Start unfolded
opt.foldmethod = 'expr'  -- Use treesitter
opt.foldexpr = 'v:lua.vim.treesitter.foldexpr()'

indentation.lua - Tab/Space Settings

opt.expandtab = true    -- Spaces instead of tabs
opt.shiftwidth = 2      -- 2-space indents
opt.tabstop = 2         -- Tab width
opt.smartindent = true  -- Auto-indent

search.lua - Search Configuration

opt.ignorecase = true   -- Case-insensitive
opt.smartcase = true    -- Unless uppercase used
opt.hlsearch = true     -- Highlight matches
opt.incsearch = true    -- Show matches while typing

Performance Impact:

4. LLM Guidance

For AI Assistants:

When modifying core settings, understand:

  1. Load order is critical - Performance must be first
  2. Settings cascade - Later settings override earlier
  3. Plugin dependencies - Many plugins assume defaults
  4. Performance impact - Every setting affects startup
  5. User experience - Core defines how Neovim feels

Adding new settings:

-- Always document why
-- WRONG: Just set the option
opt.something = true

-- RIGHT: Explain the reasoning
-- Enable something because it improves X by Y%
-- This fixes issue Z that occurs when...
opt.something = true

Testing changes:

# Profile startup time
nvim --startuptime /tmp/startup.log

# Check specific module
nvim -c "lua require('config.core.performance')" -c "q"

# Verify no errors
nvim --headless -c "checkhealth" -c "q"

Common patterns:

-- Conditional settings
if vim.fn.has('mac') == 1 then
  -- macOS-specific settings
end

-- Safe provider detection
local python3_path = vim.fn.exepath('python3')
if python3_path ~= '' then
  g.python3_host_prog = python3_path
else
  g.loaded_python3_provider = 1  -- Disable if not found
end

-- Defer non-critical settings
vim.defer_fn(function()
  -- Settings that can wait
end, 100)

5. Lessons Learned

What NOT to do:

โŒ Donโ€™t set conflicting options

-- BAD - These conflict
opt.compatible = true    -- Vi compatible mode
opt.nocompatible = true  -- Modern Vim mode

-- GOOD - Neovim is always nocompatible
-- Don't set either, it's the default

โŒ Donโ€™t load providers unnecessarily

-- BAD - Checking providers that aren't used
g.python3_host_prog = '/usr/bin/python3'
-- This causes a 30ms delay even if not using Python plugins

-- GOOD - Disable if not needed
g.loaded_python3_provider = 1

โŒ Donโ€™t enable expensive features

-- BAD - Slows down scrolling
opt.cursorcolumn = true  -- Highlights column
opt.relativenumber = true -- Without lazy redraw
opt.cursorline = true    -- With complex syntax

-- GOOD - Be selective
opt.cursorline = true    -- Only horizontal
opt.lazyredraw = false   -- Don't use, causes issues

Known Issues:

Issue: Startup takes > 300ms

Symptom: Slow Neovim launch Cause: Providers being checked Fix: Disable unused providers

-- Add to performance.lua
g.loaded_python_provider = 0  -- Python 2
g.loaded_ruby_provider = 0
g.loaded_node_provider = 0
g.loaded_perl_provider = 0

Issue: Matchit plugin errors

Symptom: โ€œMatchit.vim already loadedโ€ errors Cause: Trying to manually load built-in plugin Fix: Donโ€™t load it, Neovim includes it

-- REMOVED: vim.cmd('runtime macros/matchit.vim')
-- It's built-in since Neovim 0.8

Issue: netrw security warning

Symptom: Security warning about rm command Cause: netrw uses shell commands for file operations Fix: Use safe, explicit command

-- Safe version with proper flags
g.netrw_localrmdir = "rm -rf"
-- The -f prevents prompts, -r for recursive
-- Netrw validates paths, but we use safest form

Issue: Verbose logging creates vimlog.txt

Symptom: Unexpected vimlog.txt file appears Cause: Verbose mode accidentally enabled Fix: Reset verbose settings

-- Only reset if not explicitly set via command line
if vim.v.verbose == 0 then
  vim.opt.verbose = 0
  vim.opt.verbosefile = ""
end

Failed Approaches:

  1. lazyredraw = true - Caused visual glitches
    • Thought it would improve performance
    • Actually made scrolling jumpy
    • Some plugins incompatible
  2. clipboard = unnamedplus via X11 xclip - Slowed everything on Linux
    • 50ms+ delay on every yank/paste from xclip round-trips
    • macOS pbcopy/pbpaste is fast, so unnamedplus IS enabled today (options.lua), with an OSC 52 copy-only provider over SSH (nvim 0.10+)
    • The lesson applies to X11 clipboard tools, not the option itself
  3. foldmethod = syntax - Too slow
    • Took 100ms+ on large files
    • Now use treesitter expression folding
    • Much faster and more accurate
  4. synmaxcol = 0 - Killed performance
    • Unlimited syntax highlighting
    • 10-second delays on long lines
    • Now limited to 1000 columns

Performance Discoveries:

  1. Provider detection order matters

    -- Fast: Check executable first
    if vim.fn.exepath('python3') ~= '' then
    
    -- Slow: Let Neovim search
    g.python3_host_prog = 'python3'
    
  2. Defer non-critical autocmds

    vim.defer_fn(function()
      -- Clear messages after startup
    end, 100)  -- 100ms delay doesn't affect UX
    
  3. Built-in plugins add 70ms

    • Each plugin ~5-10ms
    • Most never used
    • Disabling all saves significant time

Best Practices:

  1. Profile everything

    nvim --startuptime startup.log
    grep "core" startup.log  # Check core module times
    
  2. Document provider requirements

    -- Python3 needed for:
    -- - Ultisnips (if used)
    -- - Some LSP servers
    -- Disable if not using these
    
  3. Use has() for compatibility

    if vim.fn.has('nvim-0.9') == 1 then
      -- 0.9+ only features
    end
    
  4. Group related settings

    -- Window behavior
    opt.splitbelow = true
    opt.splitright = true
    opt.equalalways = false
    

Troubleshooting

Debug Commands:

" Check where option was set
:verbose set option?

" View all changed options
:set

" Profile startup
:StartupTime

" Check module load time
:lua print(vim.inspect(require('core')))

Common Problems:

  1. Slow startup
    • Run :checkhealth provider
    • Disable unused providers
    • Check :StartupTime
  2. Settings not taking effect
    • Check load order
    • Look for plugin overrides
    • Use :verbose set option?
  3. Unexpected behavior
    • Temporarily disable performance.lua
    • Check if built-in plugin needed
    • Review recent changes