From d6bc5033ae1d7e70f96cb160054e3825097cfb61 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Thu, 28 Nov 2024 13:13:57 -0800 Subject: [PATCH] feat: Set options --- nix/neovim-overlay.nix | 3 +- nvim/init.lua | 4 +- nvim/lua/keymaps.lua | 4 ++ nvim/lua/lib/lazyvim/ui.lua | 25 +++++++ nvim/lua/options.lua | 138 ++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 nvim/lua/keymaps.lua create mode 100644 nvim/lua/lib/lazyvim/ui.lua create mode 100644 nvim/lua/options.lua diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 6adf5bb..b1eb4bc 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -31,9 +31,10 @@ with final.pkgs.lib; let ]; extraPackages = with pkgs; [ + ripgrep # language servers, etc. lua-language-server - nixd # nix LSP + nixd ]; in { # This is the neovim derivation returned by the overlay. diff --git a/nvim/init.lua b/nvim/init.lua index 7f4dda1..ecbb6a4 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,6 +1,8 @@ - -- Native plugins vim.cmd.filetype('plugin', 'indent', 'on') -- let sqlite.lua (which some plugins depend on) know where to find sqlite vim.g.sqlite_clib_path = require('luv').os_getenv('LIBSQLITE') + +require('options') +require('keymaps') diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua new file mode 100644 index 0000000..2568ca2 --- /dev/null +++ b/nvim/lua/keymaps.lua @@ -0,0 +1,4 @@ +local g = vim.g + +g.mapleader = ' ' +g.maplocalleader = '\\' diff --git a/nvim/lua/lib/lazyvim/ui.lua b/nvim/lua/lib/lazyvim/ui.lua new file mode 100644 index 0000000..ae5d3e0 --- /dev/null +++ b/nvim/lua/lib/lazyvim/ui.lua @@ -0,0 +1,25 @@ +--https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/ui.lua + +---@class lib.lazyvim.ui +local M = {} + +-- Optimized treesitter foldexpr for Neovim >= 0.10.0 +function M.foldexpr() + local buf = vim.api.nvim_get_current_buf() + if vim.b[buf].ts_folds == nil then + -- as long as we don't have a filetype, don't bother checking if treesitter + -- is available (it won't be) + if vim.bo[buf].filetype == '' then + return '0' + end + if vim.bo[buf].filetype:find('dashboard') then + vim.b[buf].ts_folds = false + else + vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf) + end + end + + return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or '0' +end + +return M diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua new file mode 100644 index 0000000..56775a4 --- /dev/null +++ b/nvim/lua/options.lua @@ -0,0 +1,138 @@ +local g = vim.g +local opt = vim.opt + +-- Root dir detection options. +-- Each entry can be: +-- * the name of a detector function like `lsp` or `cwd` +-- * a pattern or array of patterns like `.git` or `lua` +-- * a function with signature `function(buf) -> string|string[]` +g.root_spec = { 'lsp', { '.git', 'lua' }, 'cwd' } + +-- Only set clipboard if not in SSH, to make sure the OSC 52 integration works +-- automatically. Requires Neovim >= 0.10.0. +-- `unnamedplus` is the system clipboard. +opt.clipboard = vim.env.SSH_TTY and '' or 'unnamedplus' + +-- Relative line numbers. +opt.number = true +opt.relativenumber = true + +-- Set to 2 spaces. +opt.expandtab = true +opt.shiftwidth = 2 +opt.tabstop = 2 + +-- Smart/auto indenting. +opt.shiftround = true +opt.smartindent = true +opt.breakindent = true + +-- Show matches in real time while searching. +opt.hlsearch = true +opt.incsearch = true + +-- Disable text wrap. +opt.wrap = false + +-- Better splitting. +opt.splitbelow = true +opt.splitright = true + +-- Enable mouse mode. +opt.mouse = 'a' + +-- Smart handling of case when searching. +opt.ignorecase = true +opt.smartcase = true + +-- Use Ripgrep for searching. +opt.grepprg = 'rg --vimgrep' +opt.grepformat = '%f:%l:%c:%m' + +-- More frequent swap file saving. +opt.updatetime = 200 + +-- Completion options. +opt.completeopt = { 'menu', 'menuone', 'noselect', 'noinsert' } + +-- Persistant & bigger undo history. +opt.undofile = true +opt.undolevels = 10000 + +-- Enable 24-bit colors. +opt.termguicolors = true + +-- Always show the signcolumn to keep the text from jumping. +opt.signcolumn = 'yes' + +-- Highlight the current line. +opt.cursorline = true + +-- Fold settings. +opt.foldcolumn = '1' +opt.foldlevel = 99 +opt.foldenable = true +opt.foldmethod = 'expr' +opt.foldexpr = "v:lua.require'lib.lazyvim.ui'.foldtext()" +opt.foldtext = '' + +-- Always keep 4 lines above/below cursor. +opt.scrolloff = 4 + +-- Max width. +opt.textwidth = 80 +opt.colorcolumn = '+1' + +-- Show some invisible chars. +opt.list = true +opt.listchars = { tab = '->', trail = 'ยท' } + +-- Only show a single statusline instead of one for each window. +opt.laststatus = 3 + +-- Preview subsitutions as you type. +opt.inccommand = 'split' + +-- Ask to save changes before exiting modified buffer. +opt.confirm = true + +-- I don't understand this but LazyVim sets it and it seems like a good idea. +opt.jumpoptions = 'view' + +-- Enable a little transparency for pop-ups. +opt.pumblend = 10 + +-- Disable default line/col numbers in statusline. +opt.ruler = false + +-- What to save when calling :mksession. +opt.sessionoptions = { + 'buffers', + 'curdir', + 'tabpages', + 'winsize', + 'help', + 'globals', + 'skiprtp', + 'folds', +} + +-- Scrolling. +opt.smoothscroll = true +opt.sidescroll = 1 +opt.sidescrolloff = 8 + +-- Spelling suggestions language. +opt.spelllang = { 'en' } + +-- Allow cursor to move where there is no text in visual block mode. +opt.virtualedit = 'block' + +-- Command mode completion mode. +opt.wildmode = { 'longest:full', 'full' } + +-- Min window width when splitting. +opt.winminwidth = 5 + +-- Disable some messages. +opt.shortmess:append({ W = true, I = true, c = true, C = true })