neovim-config/lua/core/init.lua

148 lines
4.5 KiB
Lua
Raw Normal View History

2023-03-09 12:37:58 +00:00
local opt = vim.opt
local g = vim.g
-------------------------------------- globals -----------------------------------------
g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/"
2023-03-09 12:37:58 +00:00
g.toggle_theme_icon = ""
-------------------------------------- options ------------------------------------------
opt.laststatus = 3 -- global statusline
opt.showmode = false
opt.clipboard = "unnamedplus"
opt.cursorline = true
opt.cursorlineopt = "number"
2023-03-09 12:37:58 +00:00
-- Indenting
opt.expandtab = true
opt.shiftwidth = 2
opt.smartindent = true
opt.tabstop = 2
opt.softtabstop = 2
opt.fillchars = { eob = " " }
opt.ignorecase = true
opt.smartcase = true
opt.mouse = "a"
-- Numbers
opt.number = true
opt.numberwidth = 2
opt.ruler = false
-- disable nvim intro
opt.shortmess:append "sI"
opt.signcolumn = "yes"
opt.splitbelow = true
opt.splitright = true
opt.termguicolors = true
opt.timeoutlen = 400
opt.undofile = true
-- interval for writing swap file to disk, also used by gitsigns
opt.updatetime = 250
-- go to previous/next line with h,l,left arrow and right arrow
-- when cursor reaches end/beginning of line
opt.whichwrap:append "<>[]hl"
g.mapleader = " "
-- disable some default providers
for _, provider in ipairs { "node", "perl", "python3", "ruby" } do
vim.g["loaded_" .. provider .. "_provider"] = 0
end
-- add binaries installed by mason.nvim to path
local is_windows = vim.loop.os_uname().sysname == "Windows_NT"
vim.env.PATH = vim.fn.stdpath "data" .. "/mason/bin" .. (is_windows and ";" or ":") .. vim.env.PATH
2023-03-09 12:37:58 +00:00
-------------------------------------- autocmds ------------------------------------------
local autocmd = vim.api.nvim_create_autocmd
2022-07-08 13:50:57 +00:00
-- dont list quickfix buffers
autocmd("FileType", {
pattern = "qf",
callback = function()
vim.opt_local.buflisted = false
end,
2022-07-08 13:50:57 +00:00
})
2023-03-14 08:28:12 +00:00
-- reload some chadrc options on-save
autocmd("BufWritePost", {
pattern = vim.tbl_map(function(path)
return vim.fs.normalize(vim.loop.fs_realpath(path))
end, vim.fn.glob(vim.fn.stdpath "config" .. "/lua/custom/**/*.lua", true, true, true)),
group = vim.api.nvim_create_augroup("ReloadNvChad", {}),
2023-03-10 06:10:24 +00:00
callback = function(opts)
2023-03-18 05:14:42 +00:00
local fp = vim.fn.fnamemodify(vim.fs.normalize(vim.api.nvim_buf_get_name(opts.buf)), ":r") --[[@as string]]
local app_name = vim.env.NVIM_APPNAME and vim.env.NVIM_APPNAME or "nvim"
local module = string.gsub(fp, "^.*/" .. app_name .. "/lua/", ""):gsub("/", ".")
require("plenary.reload").reload_module "nvconfig"
require("plenary.reload").reload_module "base46"
2023-03-18 03:40:36 +00:00
require("plenary.reload").reload_module(module)
local config = require "nvconfig"
2023-03-14 08:28:12 +00:00
-- statusline
if config.ui.statusline.theme ~= "custom" then
require("plenary.reload").reload_module("nvchad.statusline." .. config.ui.statusline.theme)
vim.opt.statusline = "%!v:lua.require('nvchad.statusline." .. config.ui.statusline.theme .. "').run()"
end
2023-07-26 01:26:56 +00:00
-- tabufline
if config.ui.tabufline.enabled then
2023-08-09 14:52:46 +00:00
require("plenary.reload").reload_module "nvchad.tabufline.modules"
vim.opt.tabline = "%!v:lua.require('nvchad.tabufline.modules').run()"
end
2023-07-26 01:26:56 +00:00
require("base46").load_all_highlights()
2023-03-10 06:10:24 +00:00
-- vim.cmd("redraw!")
end,
})
2023-03-09 12:37:58 +00:00
-- user event that loads after UIEnter + only if file buf is there
vim.api.nvim_create_autocmd({ "UIEnter", "BufReadPost", "BufNewFile" }, {
group = vim.api.nvim_create_augroup("NvFilePost", { clear = true }),
callback = function(args)
local file = vim.api.nvim_buf_get_name(args.buf)
local buftype = vim.api.nvim_buf_get_option(args.buf, "buftype")
if not vim.g.ui_entered and args.event == "UIEnter" then
vim.g.ui_entered = true
end
if file ~= "" and buftype ~= "nofile" and vim.g.ui_entered then
vim.api.nvim_exec_autocmds("User", { pattern = "FilePost", modeline = false })
vim.api.nvim_del_augroup_by_name "NvFilePost"
vim.schedule(function()
vim.api.nvim_exec_autocmds("FileType", {})
if vim.g.editorconfig then
require("editorconfig").config(args.buf)
end
end, 0)
end
end,
})
2023-03-09 12:37:58 +00:00
-------------------------------------- commands ------------------------------------------
local new_cmd = vim.api.nvim_create_user_command
new_cmd("NvChadUpdate", function()
2023-08-09 14:52:46 +00:00
require "nvchad.updater"()
2023-03-09 12:37:58 +00:00
end, {})
2024-02-25 03:13:48 +00:00
--------------------------------------- globals -------------------------------------------
vim.g.whichkey_maps = true
vim.g.blankline_maps = true
vim.g.terminal_maps = true
vim.g.telescope_maps = true
vim.g.nvimtree_maps = true
vim.g.comment_maps = true
vim.g.tabufline_maps = true