diff options
Diffstat (limited to 'nvim')
-rw-r--r-- | nvim/README.md | 19 | ||||
-rw-r--r-- | nvim/init.lua | 33 | ||||
-rw-r--r-- | nvim/lazy-lock.json | 28 | ||||
-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 | ||||
-rw-r--r-- | nvim/lua/plugins/auto-pairs.lua | 7 | ||||
-rw-r--r-- | nvim/lua/plugins/colors.lua | 142 | ||||
-rw-r--r-- | nvim/lua/plugins/comment.lua | 50 | ||||
-rw-r--r-- | nvim/lua/plugins/diffview.lua | 13 | ||||
-rw-r--r-- | nvim/lua/plugins/gitsigns.lua | 112 | ||||
-rw-r--r-- | nvim/lua/plugins/init.lua | 11 | ||||
-rw-r--r-- | nvim/lua/plugins/lsp.lua | 100 | ||||
-rw-r--r-- | nvim/lua/plugins/markdown-preview.lua | 11 | ||||
-rw-r--r-- | nvim/lua/plugins/telescope.lua | 52 | ||||
-rw-r--r-- | nvim/lua/plugins/todo-comments.lua | 54 | ||||
-rw-r--r-- | nvim/lua/plugins/treesitter.lua | 30 | ||||
-rw-r--r-- | nvim/lua/plugins/undotree.lua | 9 |
19 files changed, 849 insertions, 0 deletions
diff --git a/nvim/README.md b/nvim/README.md new file mode 100644 index 0000000..64531f5 --- /dev/null +++ b/nvim/README.md @@ -0,0 +1,19 @@ +# Lua based Neovim Configuration + +## Directory Structure +In ```~/.config/nvim``` +``` +|-- lua +| |-- core +| |-- lsp +| |-- plugins +| | |-- plug 1 +|-- init.lua +``` + + +## Plugins +## Mappings +## UI +### Theme +### Vimline diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..b32a682 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,33 @@ +-- Bootstrap 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", + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +require("core.options") +require("core.keymaps") +require("core.statusline").setup() +require("core.autocmds") +require("lazy").setup("plugins") + +--[[-- TODO: --]] +-- gennaro-tedesco/nvim-commaround (comments) +-- kylechui/nvim-surround (surround vim) +-- "tpope/vim-fugitive" +-- iamcco/markdown-preview.nvim + +-- s1n7ax/nvim-terminal +--"https://github.com/rmagatti/goto-preview +--"https://github.com/SmiteshP/nvim-navbuddy +-- look into harpoon? diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..6dabd45 --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,28 @@ +{ + "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, + "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, + "c-syntax.vim": { "branch": "master", "commit": "e0f36366b8ad6ba9eca32c9e50eb4d47f0eac197" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, + "friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" }, + "gitsigns.nvim": { "branch": "main", "commit": "2eaa30537365f6889c850bd46ef6f18ddf8fac70" }, + "lazy.nvim": { "branch": "main", "commit": "d8f26efd456190241afd1b0f5235fe6fdba13d4a" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "ab2a3413646fedd77aa0eab4214a6473e62f6a64" }, + "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "97d9f1d3ad205dece6bcafd1d71cf1507608f3c7" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "nvim-autopairs": { "branch": "master", "commit": "d65a9678336c8b48753dba8bff49672cbeb7c892" }, + "nvim-cmp": { "branch": "main", "commit": "8c82d0bd31299dbff7f8e780f5e06d2283de9678" }, + "nvim-lspconfig": { "branch": "master", "commit": "88157521e890fe7fdf18bee22438875edd6300a6" }, + "nvim-treesitter": { "branch": "master", "commit": "8ca76960ae75e0a3bb231402558eb50e79433161" }, + "papercolor-theme": { "branch": "master", "commit": "0cfe64ffb24c21a6101b5f994ca342a74c977aef" }, + "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, + "telescope-undo.nvim": { "branch": "main", "commit": "2971cc9f193ec09e0c5de3563f99cbea16b63f10" }, + "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, + "undotree": { "branch": "master", "commit": "2556c6800b210b2096b55b66e74b4cc1d9ebbe4f" } +} 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 diff --git a/nvim/lua/plugins/auto-pairs.lua b/nvim/lua/plugins/auto-pairs.lua new file mode 100644 index 0000000..7fdb560 --- /dev/null +++ b/nvim/lua/plugins/auto-pairs.lua @@ -0,0 +1,7 @@ +return { + { + 'windwp/nvim-autopairs', + event = "InsertEnter", + config = true + }, +} diff --git a/nvim/lua/plugins/colors.lua b/nvim/lua/plugins/colors.lua new file mode 100644 index 0000000..25d016d --- /dev/null +++ b/nvim/lua/plugins/colors.lua @@ -0,0 +1,142 @@ +return { + --[[-- PaperColor --]] + + { + "NLKNguyen/papercolor-theme", + lazy = false, + priority = 1000, + config = function() + vim.opt.background = "dark" + vim.cmd.colorscheme "PaperColor" + + vim.api.nvim_set_hl(0, "Normal", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "NormalNC", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "NormalFloat", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "SignColumn", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "LineNr", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "Folded", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "NonText", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "SpecialKey", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "VertSplit", { bg = "NONE", ctermbg = "NONE" }) + vim.api.nvim_set_hl(0, "Comment", { fg = "#ADD8E6", italic = true }) + vim.api.nvim_set_hl(0, "TabChar", { fg = "#1A1A1A", ctermfg = "darkgray"}) + vim.api.nvim_set_hl(0, "String", { fg = "#b58c4a" }) + vim.api.nvim_set_hl(0, "cType", { fg = "NONE" }) + + --vim.api.nvim_set_hl(0, "Type", { fg = "NONE" , bold=false}) + vim.api.nvim_set_hl(0, "Type", { fg = "#FFFF00" , bold=false}) + vim.api.nvim_set_hl(0, "cType", { fg = "#FFFF00" , bold=false}) + vim.api.nvim_set_hl(0, "Constant", { fg = "#d7875f"}) + vim.api.nvim_set_hl(0, "Identifier", { fg = "NONE" }) + end, + }, + + --[[-- PaperColor Slim --]] + + -- { + -- "pappasam/papercolor-theme-slim", + -- lazy = false, + -- priority = 1000, + -- config = function() + -- vim.opt.background = "dark" + --vim.cmd.colorscheme "PaperColorSlim" + + -- vim.api.nvim_set_hl(0, "Normal", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "NormalNC", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "NormalFloat", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "SignColumn", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "LineNr", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "Folded", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "NonText", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "SpecialKey", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "VertSplit", { bg = "NONE", ctermbg = "NONE" }) + -- vim.api.nvim_set_hl(0, "Comment", { fg = "#ADD8E6", italic = true }) + -- vim.api.nvim_set_hl(0, "TabChar", { fg = "#1A1A1A", ctermfg = "darkgray"}) + -- vim.api.nvim_set_hl(0, "String", { fg = "#b58c4a" }) + + -- end, + -- }, + + + --[[ + { + "catppuccin/nvim", + config = function() + require("catppuccin").setup({ + flavour = "auto", -- latte, frappe, macchiato, mocha + background = { -- :h background + light = "latte", + dark = "mocha", + }, + transparent_background = false, -- disables setting the background color. + show_end_of_buffer = false, -- shows the '~' characters after the end of buffers + term_colors = false, -- sets terminal colors (e.g. `g:terminal_color_0`) + dim_inactive = { + enabled = false, -- dims the background color of inactive window + shade = "dark", + percentage = 0.15, -- percentage of the shade to apply to the inactive window + }, + no_italic = false, -- Force no italic + no_bold = false, -- Force no bold + no_underline = false, -- Force no underline + styles = { -- Handles the styles of general hi groups (see `:h highlight-args`): + comments = { "italic" }, -- Change the style of comments + conditionals = { "italic" }, + loops = {}, + functions = {}, + keywords = {}, + strings = {}, + variables = {}, + numbers = {}, + booleans = {}, + properties = {}, + types = {}, + operators = {}, + -- miscs = {}, -- Uncomment to turn off hard-coded styles + }, + color_overrides = {}, + custom_highlights = {}, + default_integrations = true, + integrations = { + cmp = true, + gitsigns = true, + nvimtree = true, + treesitter = true, + notify = false, + mini = { + enabled = true, + indentscope_color = "", + }, + -- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations) + }, + }) + + -- setup must be called before loading + --vim.cmd.colorscheme "catppuccin" -- catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha + vim.cmd.colorscheme "catppuccin-macchiato" + + + vim.api.nvim_set_hl(0, "Normal", { bg = "NONE", ctermbg = "NONE" }) + end, + }, + --]] + + + --[[-- Additional Syntax Support --]] + { + "NLKNguyen/c-syntax.vim" + }, + + { + --"junegunn/rainbow_parentheses.vim", + --"luochen1990/rainbow", + --"kien/rainbow_parentheses.vim", + + --[[ -- does work + "luochen1990/rainbow", + event = { 'BufReadPre', 'BufNewFile' }, + init = function() vim.g.rainbow_active = 1 end, + config = function() vim.cmd('RainbowToggleOn') end, + --]] + }, +} diff --git a/nvim/lua/plugins/comment.lua b/nvim/lua/plugins/comment.lua new file mode 100644 index 0000000..e485b9b --- /dev/null +++ b/nvim/lua/plugins/comment.lua @@ -0,0 +1,50 @@ +return { + { + "numToStr/Comment.nvim", + config = function() + require('Comment').setup({ + ---Add a space b/w comment and the line + padding = true, + ---Whether the cursor should stay at its position + sticky = true, + ---Lines to be ignored while (un)comment + ignore = nil, + ---LHS of toggle mappings in NORMAL mode + toggler = { + ---Line-comment toggle keymap + line = 'gcc', + ---Block-comment toggle keymap + block = 'gbc', + }, + ---LHS of operator-pending mappings in NORMAL and VISUAL mode + opleader = { + ---Line-comment keymap + line = 'gc', + ---Block-comment keymap + block = 'gb', + }, + ---LHS of extra mappings + extra = { + ---Add comment on the line above + above = 'gcO', + ---Add comment on the line below + below = 'gco', + ---Add comment at the end of line + eol = 'gcA', + }, + ---Enable keybindings + ---NOTE: If given `false` then the plugin won't create any mappings + mappings = { + ---Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` + basic = true, + ---Extra mapping; `gco`, `gcO`, `gcA` + extra = true, + }, + ---Function to call before (un)comment + pre_hook = nil, + ---Function to call after (un)comment + post_hook = nil, + }) + end, + }, +} diff --git a/nvim/lua/plugins/diffview.lua b/nvim/lua/plugins/diffview.lua new file mode 100644 index 0000000..ec440b1 --- /dev/null +++ b/nvim/lua/plugins/diffview.lua @@ -0,0 +1,13 @@ +return { + { + "sindrets/diffview.nvim", + config = function() + -- TODO: keymaps + -- :DiffviewOpen + -- :DiffviewClose + -- :DiffviewToggleFiles + -- :DiffviewFileHistory + -- :DiffviewFileHistory % + end, + }, +} diff --git a/nvim/lua/plugins/gitsigns.lua b/nvim/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..6ee0348 --- /dev/null +++ b/nvim/lua/plugins/gitsigns.lua @@ -0,0 +1,112 @@ +return { + { + "lewis6991/gitsigns.nvim", + config = function() + + require('gitsigns').setup { + signs = { + add = { text = '+' }, + --change = { text = '┃' }, + change = { text = 'Δ' }, + delete = { text = '-' }, + topdelete = { text = '-' }, + changedelete = { text = 'Δ-' }, + untracked = { text = '~' }, + }, + signs_staged = { + add = { text = '+' }, + --change = { text = '┃' }, + change = { text = 'Δ' }, + delete = { text = '-' }, + topdelete = { text = '-' }, + changedelete = { text = 'Δ-' }, + untracked = { text = '~' }, + }, + signs_staged_enable = true, + signcolumn = true, -- Toggle with `:Gitsigns toggle_signs` + numhl = false, -- Toggle with `:Gitsigns toggle_numhl` + linehl = false, -- Toggle with `:Gitsigns toggle_linehl` + word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff` + watch_gitdir = { + follow_files = true + }, + auto_attach = true, + attach_to_untracked = false, + current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame` + current_line_blame_opts = { + virt_text = true, + virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align' + delay = 1000, + ignore_whitespace = false, + virt_text_priority = 100, + use_focus = true, + }, + current_line_blame_formatter = '<author>, <author_time:%R> - <summary>', + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, -- Use default + max_file_length = 40000, -- Disable if file is longer than this (in lines) + preview_config = { + -- Options passed to nvim_open_win + border = 'single', + style = 'minimal', + relative = 'cursor', + row = 0, + col = 1 + }, + + --[[-- Key Maps --]] + + on_attach = function(bufnr) + local gitsigns = require('gitsigns') + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal({']c', bang = true}) + else + gitsigns.nav_hunk('next') + end + end) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal({'[c', bang = true}) + else + gitsigns.nav_hunk('prev') + end + end) + vim.api.nvim_set_hl(0, "GitSignsChangeDelete", { fg = "#E1341E", bg = "NONE" }) + vim.api.nvim_set_hl(0, "GitSignsTopDelete", { fg = "#E1341E", bg = "NONE" }) + vim.api.nvim_set_hl(0, "GitSignsDelete", { fg = "#E1341E", bg = "NONE" }) + + + -- Actions + --[[ + map('n', '<leader>hs', gitsigns.stage_hunk) + map('n', '<leader>hr', gitsigns.reset_hunk) + map('v', '<leader>hs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('v', '<leader>hr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('n', '<leader>hS', gitsigns.stage_buffer) + map('n', '<leader>hu', gitsigns.undo_stage_hunk) + map('n', '<leader>hR', gitsigns.reset_buffer) + map('n', '<leader>hp', gitsigns.preview_hunk) + map('n', '<leader>hb', function() gitsigns.blame_line{full=true} end) + map('n', '<leader>tb', gitsigns.toggle_current_line_blame) + map('n', '<leader>hd', gitsigns.diffthis) + map('n', '<leader>hD', function() gitsigns.diffthis('~') end) + map('n', '<leader>td', gitsigns.toggle_deleted) + -- Text object + map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>') + --]] + end, + } + end, + } +} diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..ffd4623 --- /dev/null +++ b/nvim/lua/plugins/init.lua @@ -0,0 +1,11 @@ +return { + require("plugins.telescope"), + require("plugins.treesitter"), + require("plugins.lsp"), + require("plugins.colors"), + require("plugins.todo-comments"), + require("plugins.auto-pairs"), + require("plugins.gitsigns"), + require("plugins.comment"), + require("plugins.markdown-preview"), +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..e33925e --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,100 @@ +return +{ + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + dependencies = { + -- LSP Support + {'neovim/nvim-lspconfig'}, + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + {'folke/todo-comments.nvim'}, -- doesn't load for some reason + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/cmp-buffer'}, + {'hrsh7th/cmp-path'}, + {'saadparwaiz1/cmp_luasnip'}, + {'hrsh7th/cmp-nvim-lua'}, + + -- Snippets + {'L3MON4D3/LuaSnip'}, + {'rafamadriz/friendly-snippets'}, + }, + + config = function() + local lsp_zero = require('lsp-zero') + + lsp_zero.on_attach(function(client, bufnr) + -- see :help lsp-zero-keybindings + -- to learn the available actions + lsp_zero.default_keymaps({buffer = bufnr}) + + vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts) + vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts) + vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts) + vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts) + vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts) + vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts) + vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts) + end) + + -- to learn how to use mason.nvim with lsp-zero + -- read this: https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/integrate-with-mason-nvim.md + require('mason').setup({}) + require('mason-lspconfig').setup({ + ensure_installed = { + 'lua_ls', + 'clangd', + 'texlab', + }, + handlers = { + lsp_zero.default_setup, + }, + }) + + -- Setup completion + local cmp = require('cmp') + local cmp_action = lsp_zero.cmp_action() + + cmp.setup({ + mapping = cmp.mapping.preset.insert({ + ['<CR>'] = cmp.mapping.confirm({select = false}), + ['<C-Space>'] = cmp.mapping.complete(), + ['<C-f>'] = cmp_action.luasnip_jump_forward(), + ['<C-b>'] = cmp_action.luasnip_jump_backward(), + ['<C-u>'] = cmp.mapping.scroll_docs(-4), + ['<C-d>'] = cmp.mapping.scroll_docs(4), + }), + snippet = { + expand = function(args) + -- You need Neovim v0.10 to use vim.snippet + vim.snippet.expand(args.body) + end, + }, + }) + + require('lspconfig').lua_ls.setup({ + capabilities = lsp_capabilities, + settings = { + Lua = { + runtime = { + version = 'LuaJIT' + }, + diagnostics = { + globals = {'vim'}, + disable = { 'unused-function' }, + }, + workspace = { + library = { + vim.env.VIMRUNTIME, + } + } + } + } + }) + + + end + +} diff --git a/nvim/lua/plugins/markdown-preview.lua b/nvim/lua/plugins/markdown-preview.lua new file mode 100644 index 0000000..b325fdd --- /dev/null +++ b/nvim/lua/plugins/markdown-preview.lua @@ -0,0 +1,11 @@ +return { + { + "iamcco/markdown-preview.nvim", + cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, + build = "cd app && yarn install", + init = function() + vim.g.mkdp_filetypes = { "markdown" } + end, + ft = { "markdown" }, + }, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..bd26f0f --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,52 @@ +return { + { + 'nvim-telescope/telescope.nvim', tag = '0.1.8', + dependencies = { 'nvim-lua/plenary.nvim' }, + + config = function() + local builtin = require('telescope.builtin') + vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' }) + vim.keymap.set('n', '<C-p>', builtin.git_files, { desc = 'hello world' }) + vim.keymap.set('n', '<leader>ps', function() + builtin.grep_string({ search = vim.fn.input("Grep > ") }); + end) + + vim.keymap.set("n", "<leader>rw", function() + builtin.grep_string { search = vim.fn.expand "<cword>", } + end, { silent = true}) + end + }, + + { + "debugloop/telescope-undo.nvim", + dependencies = { -- note how they're inverted to above example + { + "nvim-telescope/telescope.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + }, + keys = { + { -- lazy style key map + "<leader>u", + "<cmd>Telescope undo<cr>", + desc = "undo history", + }, + }, + opts = { + -- don't use `defaults = { }` here, do this in the main telescope spec + extensions = { + undo = { + -- telescope-undo.nvim config, see below + }, + -- no other extensions here, they can have their own spec too + }, + }, + config = function(_, opts) + -- Calling telescope's setup from multiple specs does not hurt, it will happily merge the + -- configs for us. We won't use data, as everything is in it's own namespace (telescope + -- defaults, as well as each extension). + require("telescope").setup(opts) + require("telescope").load_extension("undo") + end, + }, +} diff --git a/nvim/lua/plugins/todo-comments.lua b/nvim/lua/plugins/todo-comments.lua new file mode 100644 index 0000000..b62212c --- /dev/null +++ b/nvim/lua/plugins/todo-comments.lua @@ -0,0 +1,54 @@ +-- lua/plugins/todo-comments.lua +return { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + event = { "BufReadPost", "BufNewFile" }, + config = function() + require("todo-comments").setup({ + signs = true, + sign_priority = 8, + + keywords = { + FIX = { + icon = " ", + color = "error", + alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, -- keywords that map to FIX + }, + TODO = { icon = " ", color = "info" }, + HACK = { icon = " ", color = "warning" }, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, + TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + DEBUG = { icon = "🐛", color = "info"}, + FIX = { icon = "🔧", color = "#FF00FF"}, + + }, + colors = { + error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, + warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, + info = { "DiagnosticInfo", "#2563EB" }, + hint = { "DiagnosticHint", "#10B981" }, + default = { "Identifier", "#7C3AED" }, + test = { "Identifier", "#FF00FF" } + }, + highlight = { + multiline = true, -- enable multine todo comments + } + + }) + + -- Add some keymaps for todo-comments + vim.keymap.set("n", "]t", function() + require("todo-comments").jump_next() + end, { desc = "Next todo comment" }) + + vim.keymap.set("n", "[t", function() + require("todo-comments").jump_prev() + end, { desc = "Previous todo comment" }) + + -- Search todo comments + vim.keymap.set("n", "<leader>cf", ":TodoTelescope<CR>", + { desc = "Find todo comments", silent = true }) + end, +} diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..f3f4dd0 --- /dev/null +++ b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,30 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + event = { "BufReadPost", "BufNewFile" }, + + config = function() + require("nvim-treesitter.configs").setup({ + ensure_installed = { + --"c", + "bash", + "markdown", + "markdown_inline", + "bibtex", + "latex", + "vimdoc", + }, + --ignore_installed = { "c" }, + sync_install = false, + auto_install = true, + + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + disable = { "c", "cpp", "h" } + } + }) + end, + }, +} diff --git a/nvim/lua/plugins/undotree.lua b/nvim/lua/plugins/undotree.lua new file mode 100644 index 0000000..e874811 --- /dev/null +++ b/nvim/lua/plugins/undotree.lua @@ -0,0 +1,9 @@ +return { + { + "mbbill/undotree", + + config = function() + vim.keymap.set('n', '<leader>u', vim.cmd.UndotreeToggle) + end + }, +} |