diff options
Diffstat (limited to 'nvim/lua/core')
-rw-r--r-- | nvim/lua/core/autocmds.lua | 30 | ||||
-rw-r--r-- | nvim/lua/core/keymaps.lua | 55 | ||||
-rw-r--r-- | nvim/lua/core/options.lua | 38 | ||||
-rw-r--r-- | nvim/lua/core/statusline.lua | 55 |
4 files changed, 178 insertions, 0 deletions
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 + +-- <leader> -> \ +vim.g.mapleader = "\\" +keymap.set("n", "<leader>pv", vim.cmd.Ex) + +-- alter indentation in visual mode +keymap.set("v", "<", "<gv") +keymap.set("v", ">", ">gv") + +-- Grab visual selection and place the line(s) anywhere +keymap.set("v", "J", ":m '>+1<CR>gv=gv") +keymap.set("v", "K", ":m '<-2<CR>gv=gv") + +-- Half-page Navigation, position preservation +keymap.set("n", "<C-d>", "<C-d>zz") +keymap.set("n", "<C-u>", "<C-u>zz") + +-- file-wide replace-substitution +keymap.set("n", "<leader>r", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]]) + +-- Make it executable +keymap.set("n", "<leader>x", "<cmd>!chmod +x %<CR>", { silent = true }) + +-- Map CTRL-BS -> CTRL-W (delete prev. word) +keymap.set("i", "<C-h>", "<C-\\><C-o>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:', '<Nop>', { noremap = true, silent = true }) + + + +--[[-- Tabs --]] + +-- Open a new tab +keymap.set("n", "<M-n>", ":tabnew ", { noremap = true }) + +-- Close the current tab +keymap.set("n", "<C-n>", ":tabclose<CR>", { noremap = true, silent = true }) + +-- Switch to the next tab (Normal, Insert, and Command modes) +keymap.set("n", "<M-Tab>", ":<C-U>tabnext<CR>", { noremap = true }) +keymap.set("i", "<M-Tab>", "<C-\\><C-N>:tabnext<CR>", { noremap = true }) +keymap.set("c", "<M-Tab>", "<C-C>:tabnext<CR>", { noremap = true }) + +-- Switch to the previous tab (Normal, Insert, and Command modes) +keymap.set("n", "<S-Tab>", ":<C-U>tabprevious<CR>", { noremap = true }) +keymap.set("i", "<S-Tab>", "<C-\\><C-N>:tabprevious<CR>", { noremap = true }) +keymap.set("c", "<S-Tab>", "<C-C>:tabprevious<CR>", { noremap = true }) + +-- Enable Spell Check +keymap.set("n", "<leader>s", ":setlocal spell! spelllang=en_us<CR>", { 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<CR><CR>', +{ 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 |