From bb2e30b412c23b76ae876e792398f4926467d962 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 8 Jan 2025 15:45:00 -0800 Subject: added current config --- nvim/lua/core/autocmds.lua | 30 ++++++++++++++++++++++++ nvim/lua/core/keymaps.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++ nvim/lua/core/options.lua | 38 ++++++++++++++++++++++++++++++ nvim/lua/core/statusline.lua | 55 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 nvim/lua/core/autocmds.lua create mode 100644 nvim/lua/core/keymaps.lua create mode 100644 nvim/lua/core/options.lua create mode 100644 nvim/lua/core/statusline.lua (limited to 'nvim/lua/core') diff --git a/nvim/lua/core/autocmds.lua b/nvim/lua/core/autocmds.lua new file mode 100644 index 0000000..9df4e6d --- /dev/null +++ b/nvim/lua/core/autocmds.lua @@ -0,0 +1,30 @@ +local augroup = vim.api.nvim_create_augroup +local autocmd = vim.api.nvim_create_autocmd + +-- Compile LaTeX on Save +autocmd("BufWritePost", { + pattern = "*.tex", + callback = function() + vim.fn.jobstart({ "pdflatex", vim.fn.expand("%:p") }, { stdout_buffered = true, stderr_buffered = true }) + end, +}) + +-- Remove White Spaces on Save +autocmd("BufWritePre", { + pattern = "*", + callback = function() + local currPos = vim.fn.getpos(".") + vim.cmd([[%s/\s\+$//e]]) + vim.cmd([[%s/\n\+\%$//e]]) + vim.fn.cursor(currPos[2], currPos[3]) + end, +}) + +-- Stop Auto comemnting +vim.api.nvim_create_autocmd("BufEnter", { + pattern = "*", + callback = function() + vim.opt.formatoptions:remove({ "r", "o" }) + vim.opt_local.formatoptions:remove({ "r", "o" }) + end, +}) diff --git a/nvim/lua/core/keymaps.lua b/nvim/lua/core/keymaps.lua new file mode 100644 index 0000000..fcaadcb --- /dev/null +++ b/nvim/lua/core/keymaps.lua @@ -0,0 +1,55 @@ +local keymap = vim.keymap + +-- -> \ +vim.g.mapleader = "\\" +keymap.set("n", "pv", vim.cmd.Ex) + +-- alter indentation in visual mode +keymap.set("v", "<", "", ">gv") + +-- Grab visual selection and place the line(s) anywhere +keymap.set("v", "J", ":m '>+1gv=gv") +keymap.set("v", "K", ":m '<-2gv=gv") + +-- Half-page Navigation, position preservation +keymap.set("n", "", "zz") +keymap.set("n", "", "zz") + +-- file-wide replace-substitution +keymap.set("n", "r", [[:%s/\<\>//gI]]) + +-- Make it executable +keymap.set("n", "x", "!chmod +x %", { silent = true }) + +-- Map CTRL-BS -> CTRL-W (delete prev. word) +keymap.set("i", "", "db", { noremap = true, silent = true }) + +-- 2 fewer keystrokes to enter another file +keymap.set("n", "E", ":e ") + +-- Get rid of this shit +vim.api.nvim_set_keymap('n', 'q:', '', { noremap = true, silent = true }) + + + +--[[-- Tabs --]] + +-- Open a new tab +keymap.set("n", "", ":tabnew ", { noremap = true }) + +-- Close the current tab +keymap.set("n", "", ":tabclose", { noremap = true, silent = true }) + +-- Switch to the next tab (Normal, Insert, and Command modes) +keymap.set("n", "", ":tabnext", { noremap = true }) +keymap.set("i", "", ":tabnext", { noremap = true }) +keymap.set("c", "", ":tabnext", { noremap = true }) + +-- Switch to the previous tab (Normal, Insert, and Command modes) +keymap.set("n", "", ":tabprevious", { noremap = true }) +keymap.set("i", "", ":tabprevious", { noremap = true }) +keymap.set("c", "", ":tabprevious", { noremap = true }) + +-- Enable Spell Check +keymap.set("n", "s", ":setlocal spell! spelllang=en_us", { silent = true }) diff --git a/nvim/lua/core/options.lua b/nvim/lua/core/options.lua new file mode 100644 index 0000000..2f4a200 --- /dev/null +++ b/nvim/lua/core/options.lua @@ -0,0 +1,38 @@ +local opt = vim.opt +local cmd = vim.cmd + +-- Syntax and colors +opt.termguicolors = true +opt.background = "dark" +opt.signcolumn = "yes" +cmd("syntax on") + +-- Line Numbers +opt.number = true +opt.relativenumber = true + +-- Tabs +opt.expandtab = false -- Use tabs instead of spaces +opt.tabstop = 4 -- Number of spaces a tab counts for +opt.shiftwidth = 4 -- Number of spaces for auto-indentation +opt.softtabstop = 4 -- Spaces used when hitting Tab or Backspace +opt.smartindent = true +opt.autoindent = true +cmd("match TabChar /\t/") +vim.opt.list = true +vim.opt.listchars = { tab = ".." } + +-- File type detection +vim.cmd("filetype on") +vim.cmd("filetype plugin on") + +-- Mouse and clipboard +vim.opt.mouse = "" +vim.opt.clipboard = "unnamedplus" +vim.api.nvim_set_keymap('v', 'yy', ':w !xclip -selection clipboard', +{ noremap = true, silent = true }) + +-- MISC +opt.swapfile = false +opt.backup = false +vim.opt.encoding = "utf-8" diff --git a/nvim/lua/core/statusline.lua b/nvim/lua/core/statusline.lua new file mode 100644 index 0000000..45a2c42 --- /dev/null +++ b/nvim/lua/core/statusline.lua @@ -0,0 +1,55 @@ +local M = {} + +local function git_branch() + local git_dir = vim.fn.system("git rev-parse --git-dir 2>/dev/null") + if vim.v.shell_error ~= 0 then + return "" + end + local branch = vim.fn.system("git branch --show-current 2>/dev/null | tr -d '\n'") + return branch +end + +function M.statusline_git() + local branch_name = git_branch() + return #branch_name > 0 and ' ' .. branch_name .. ' ' or '' +end + +function M.setup() + vim.cmd('highlight clear StatusLine') + vim.cmd('highlight clear StatusLineNC') + + local highlights = { + StatusLineGit = { bg = "#161616", fg = "#D8DEE9" }, + StatusLineBuffer = { bg = "NONE", fg = "#D8DEE9" }, + StatusLine = { bg = "NONE", fg = "#D8DEE9" }, + StatusLineFiletype = { bg = "NONE", fg = "#D8DEE9" }, + StatusLinePath = { bg = "NONE", fg = "#D8DEE9" }, + StatusLineModified = { bg = "NONE", fg = "#D8DEE9" }, + } + + for name, colors in pairs(highlights) do + vim.api.nvim_set_hl(0, name, colors) + end + + vim.opt.statusline = table.concat({ + "%#StatusLineGit#%{v:lua.require'core.statusline'.statusline_git()}", + "%#StatusLineBuffer# %n ", + "%#StatusLine#%{&ff} ", + "%#StatusLineFiletype#%y", + "%#StatusLinePath# %<%{expand('%:p:h')}/%f", + "%#StatusLineModified#%m", + "%=", + "%#StatusLine#%5l", + "/%L:%v ", + "%{char2nr(getline('.')[col('.')-1])} " + }) +end + +vim.api.nvim_create_autocmd("ColorScheme", { + pattern = "*", + callback = function() + M.setup() + end, +}) + +return M -- cgit v1.2.3