Created
July 10, 2023 13:09
-
-
Save shekohex/c178c2112657845948cba9e5d6b42e35 to your computer and use it in GitHub Desktop.
Minimum Neovim Config file to work on Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Contains Neovim/Vim API and Settings. | |
vim.g.mapleader = " " | |
vim.g.maplocalleader = " " | |
local opt = vim.opt | |
opt.hlsearch = false | |
opt.autowrite = true -- Enable auto write | |
opt.clipboard = "unnamedplus" -- Sync with system clipboard | |
opt.completeopt = "menu,menuone,noselect" | |
opt.conceallevel = 0 | |
opt.confirm = true -- Confirm to save changes before exiting modified buffer | |
opt.cursorline = true -- Enable highlighting of the current line | |
opt.expandtab = true -- Use spaces instead of tabs | |
opt.formatoptions = "jcroqlnt" -- tcqj | |
opt.grepformat = "%f:%l:%c:%m" | |
opt.grepprg = "rg --vimgrep" | |
opt.ignorecase = true -- Ignore case | |
opt.inccommand = "nosplit" -- preview incremental substitute | |
opt.laststatus = 0 | |
opt.list = true -- Show some invisible characters (tabs... | |
opt.mouse = "a" -- Enable mouse mode | |
opt.number = true -- Print line number | |
opt.pumblend = 10 -- Popup blend | |
opt.pumheight = 10 -- Maximum number of entries in a popup | |
opt.relativenumber = true -- Relative line numbers | |
opt.scrolloff = 4 -- Lines of context | |
opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } | |
opt.shiftround = true -- Round indent | |
opt.shiftwidth = 2 -- Size of an indent | |
opt.shortmess:append({ W = true, I = true, c = true }) | |
opt.showmode = false -- Dont show mode since we have a statusline | |
opt.sidescrolloff = 8 -- Columns of context | |
opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time | |
opt.smartcase = true -- Don't ignore case with capitals | |
opt.smartindent = true -- Insert indents automatically | |
opt.spelllang = { "en" } | |
opt.splitbelow = true -- Put new windows below current | |
opt.splitright = true -- Put new windows right of current | |
opt.tabstop = 2 -- Number of spaces tabs count for | |
opt.termguicolors = true -- True color support | |
opt.timeoutlen = 300 | |
opt.undofile = true | |
opt.undolevels = 10000 | |
opt.updatetime = 200 -- Save swap file and trigger CursorHold | |
opt.wildmode = "longest:full,full" -- Command-line completion mode | |
opt.winminwidth = 5 -- Minimum window width | |
opt.wrap = false -- Disable line wrap | |
if vim.fn.has("nvim-0.9.0") == 1 then | |
opt.splitkeep = "screen" | |
opt.shortmess:append({ C = true }) | |
end | |
local function augroup(name) | |
return vim.api.nvim_create_augroup("shekohex_" .. name, { clear = true }) | |
end | |
-- Check if we need to reload the file when it changed | |
vim.api.nvim_create_autocmd({ "FocusGained", "TermClose", "TermLeave" }, { | |
group = augroup("checktime"), | |
command = "checktime", | |
}) | |
-- Highlight on yank | |
vim.api.nvim_create_autocmd("TextYankPost", { | |
group = augroup("highlight_yank"), | |
callback = function() | |
vim.highlight.on_yank() | |
end, | |
}) | |
-- resize splits if window got resized | |
vim.api.nvim_create_autocmd({ "VimResized" }, { | |
group = augroup("resize_splits"), | |
callback = function() | |
vim.cmd("tabdo wincmd =") | |
end, | |
}) | |
-- go to last loc when opening a buffer | |
vim.api.nvim_create_autocmd("BufReadPost", { | |
group = augroup("last_loc"), | |
callback = function() | |
local mark = vim.api.nvim_buf_get_mark(0, '"') | |
local lcount = vim.api.nvim_buf_line_count(0) | |
if mark[1] > 0 and mark[1] <= lcount then | |
pcall(vim.api.nvim_win_set_cursor, 0, mark) | |
end | |
end, | |
}) | |
-- close some filetypes with <q> | |
vim.api.nvim_create_autocmd("FileType", { | |
group = augroup("close_with_q"), | |
pattern = { | |
"PlenaryTestPopup", | |
"help", | |
"lspinfo", | |
"man", | |
"notify", | |
"qf", | |
"spectre_panel", | |
"startuptime", | |
"tsplayground", | |
"checkhealth", | |
}, | |
callback = function(event) | |
vim.bo[event.buf].buflisted = false | |
vim.keymap.set("n", "q", "<cmd>close<cr>", { buffer = event.buf, silent = true }) | |
end, | |
}) | |
-- wrap and check for spell in text filetypes | |
vim.api.nvim_create_autocmd("FileType", { | |
group = augroup("wrap_spell"), | |
pattern = { "gitcommit", "markdown" }, | |
callback = function() | |
vim.opt_local.wrap = true | |
vim.opt_local.spell = true | |
end, | |
}) | |
-- Auto create dir when saving a file, in case some intermediate directory does not exist | |
vim.api.nvim_create_autocmd({ "BufWritePre" }, { | |
group = augroup("auto_create_dir"), | |
callback = function(event) | |
if event.match:match("^%w%w+://") then | |
return | |
end | |
local file = vim.loop.fs_realpath(event.match) or event.match | |
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") | |
end, | |
}) | |
-- Setup Lazy.nvim | |
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
if not vim.loop.fs_stat(lazypath) then | |
vim.fn.system({ | |
"git", | |
"clone", | |
"--filter=blob:none", | |
"https://github.com/folke/lazy.nvim.git", | |
"--branch=stable", -- latest stable release | |
lazypath, | |
}) | |
end | |
vim.opt.rtp:prepend(lazypath) | |
require("lazy").setup({ | |
{ "stevearc/dressing.nvim", event = "VeryLazy" }, | |
{ "nvim-tree/nvim-web-devicons", lazy = true }, | |
{ | |
"nvim-treesitter/nvim-treesitter", | |
config = function() | |
require('nvim-treesitter.configs').setup({ | |
ensure_installed = { | |
"lua", | |
"vim", | |
"vimdoc", | |
"toml", | |
"yaml", | |
"json", | |
}, | |
highlight = { enable = true }, | |
}) | |
end | |
}, | |
{ | |
"catppuccin/nvim", | |
name = "catppuccin", | |
config = function() | |
require("catppuccin").setup({ | |
flavour = "mocha", -- latte, frappe, macchiato, mocha | |
background = { -- :h background | |
light = "latte", | |
dark = "mocha", | |
}, | |
}); | |
vim.cmd.colorscheme "catppuccin" | |
end | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment