diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1cfd27b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +* +!*.lua +!**/**/ +!.gitignore diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..7681b23 --- /dev/null +++ b/init.lua @@ -0,0 +1,6 @@ +require("core.keymaps") +require("core.options") +require("lazysetup") + +-- Design a custom status line +require("core.statusline") diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua new file mode 100644 index 0000000..a79b927 --- /dev/null +++ b/lua/core/keymaps.lua @@ -0,0 +1,12 @@ +-- set leader key +vim.g.mapleader = " " + +local keymap = vim.keymap + +-- General keymaps +keymap.set("i", "jj", "", { + desc = "jj to escape" +}) +keymap.set("i", "jk", "", { + desc = "jk to escape" +}) diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..1cdf26d --- /dev/null +++ b/lua/core/options.lua @@ -0,0 +1,49 @@ +local opt = vim.opt -- for conciseness + +-- line numbers +opt.relativenumber = true -- show relative line numbers +opt.number = true -- shows absolute line number on cursor line (when relative number is on) + +-- tabs & indentation +opt.tabstop = 2 -- 2 spaces for tabs (prettier default) +opt.shiftwidth = 2 -- 2 spaces for indent width +opt.expandtab = true -- expand tab to spaces +opt.autoindent = true -- copy indent from current line when starting new one + +-- line wrapping +opt.wrap = false -- disable line wrapping + +-- search settings +opt.ignorecase = true -- ignore case when searching +opt.smartcase = true -- if you include mixed case in your search, assumes you want case-sensitive + +-- cursor line +opt.cursorline = true -- highlight the current cursor line + +-- appearance + +-- turn on termguicolors for nightfly colorscheme to work +-- (have to use iterm2 or any other true color terminal) +opt.termguicolors = true +opt.background = "dark" -- colorschemes that can be light or dark will be made dark +opt.signcolumn = "yes" -- show sign column so that text doesn't shift + +-- backspace +opt.backspace = "indent,eol,start" -- allow backspace on indent, end of line or insert mode start position + +-- clipboard +opt.clipboard:append("unnamedplus") -- use system clipboard as default register + +-- split windows +opt.splitright = true -- split vertical window to the right +opt.splitbelow = true -- split horizontal window to the bottom + +-- turn off swapfile +opt.swapfile = false + +-- remove tilde on end of buffer +opt.fillchars = { + eob = " " +} + +opt.ruler = false -- disable ruler diff --git a/lua/core/statusline.lua b/lua/core/statusline.lua new file mode 100644 index 0000000..2e7d182 --- /dev/null +++ b/lua/core/statusline.lua @@ -0,0 +1,223 @@ +local modes = { + ["n"] = "N", + ["no"] = "N", + ["v"] = "V", + ["V"] = "VL", + [""] = "VB", + ["s"] = "S", + ["S"] = "SL", + [""] = "SB", + ["i"] = "I", + ["ic"] = "I", + ["R"] = "R", + ["Rv"] = "VR", + ["c"] = "COMMAND", + ["cv"] = "VIM EX", + ["ce"] = "EX", + ["r"] = "PROMPT", + ["rm"] = "MOAR", + ["r?"] = "CONFIRM", + ["!"] = "SHELL", + ["t"] = "T" +} + +vim.cmd("highlight StatusLineNormal guifg=#038e18") +vim.cmd("highlight StatusLineVisual guifg=#17508e") +vim.cmd("highlight StatusLineInsert guifg=#cd2e2e") +vim.cmd("highlight StatusLineReplace guifg=#b98d0a") +vim.cmd("highlight StatusLineCmdLine guifg=#377690") +vim.cmd("highlight StatusLineTerminal guifg=#941358") +vim.cmd("highlight StatusLineExtra guifg=#c6ab52") + +vim.cmd("highlight LspDiagnosticsSignError guifg=#991313") +vim.cmd("highlight LspDiagnosticsSignWarning guifg=#c49213") +vim.cmd("highlight LspDiagnosticsSignHint guifg=#13c9a1") +vim.cmd("highlight LspDiagnosticsSignInformation guifg=#1399c4") + +local function mode() + local current_mode = vim.api.nvim_get_mode().mode + return string.format(" %s ", modes[current_mode]):upper() +end +local function update_mode_colors() + local current_mode = vim.api.nvim_get_mode().mode + local mode_color = "%#StatusLineNormal#" + if current_mode == "n" then + mode_color = "%#StatuslineNormal#" + elseif current_mode == "i" or current_mode == "ic" then + mode_color = "%#StatuslineInsert#" + elseif current_mode == "v" or current_mode == "V" or current_mode == "" then + mode_color = "%#StatuslineVisual#" + elseif current_mode == "R" then + mode_color = "%#StatuslineReplace#" + elseif current_mode == "c" then + mode_color = "%#StatuslineCmdLine#" + elseif current_mode == "t" then + mode_color = "%#StatuslineTerminal#" + end + return mode_color +end + +local function filepath() + local fpath = vim.fn.fnamemodify(vim.fn.expand("%"), ":~:.:h") + if fpath == "" or fpath == "." then + return " " + end + return string.format(" %%<%s/", fpath) +end + +local function filename() + local fname = vim.fn.expand("%:t") + if fname == "" then + return "" + end + return fname .. " " +end + +local function lsp() + local count = {} + local levels = { + errors = "Error", + warnings = "Warn", + info = "Info", + hints = "Hint" + } + for k, level in pairs(levels) do + count[k] = vim.tbl_count(vim.diagnostic.get(0, { + severity = level + })) + end + local errors = "" + local warnings = "" + local hints = "" + local info = "" + if count["errors"] ~= 0 then + errors = " %#LspDiagnosticsSignError# " .. count["errors"] + end + if count["warnings"] ~= 0 then + warnings = " %#LspDiagnosticsSignWarning# " .. count["warnings"] + end + if count["hints"] ~= 0 then + hints = " %#LspDiagnosticsSignHint#💡 " .. count["hints"] + end + if count["info"] ~= 0 then + info = " %#LspDiagnosticsSignInformation# " .. count["info"] + end + return errors .. warnings .. hints .. info +end + +local filetype_icons = { + ["lua"] = "", + ["python"] = "", + ["javascript"] = "", + ["typescript"] = "", + ["html"] = "", + ["css"] = "", + ["json"] = "", + ["yaml"] = "", + ["markdown"] = "", + ["sh"] = "", + ["vim"] = "", + ["java"] = "", + ["c"] = "", + ["cpp"] = "", + ["haskell"] = "", + ["rust"] = "", + ["go"] = "", + ["php"] = "", + ["ruby"] = "" + -- add more filetypes and their corresponding icons here... +} + +local function filetype_with_icon() + local filetype = vim.bo.filetype + local icon = filetype_icons[filetype] or "󰈙" + return icon .. " " .. filetype +end + +local function filetype_only_icon() + local filetype = vim.bo.filetype + local icon = filetype_icons[filetype] or "󰈙" + return icon +end + +local function filetype() + return string.format(" %s ", vim.bo.filetype):upper() +end + +local function lineinfo() + if vim.bo.filetype == "alpha" then + return "" + end + return " %P %l:%c " +end +local vcs = function() + local git_info = vim.b.gitsigns_status_dict + if not git_info or git_info.head == "" then + return "" + end + local added = git_info.added and ("%#GitSignsAdd#+" .. git_info.added .. " ") or "" + local changed = git_info.changed and ("%#GitSignsChange#~" .. git_info.changed .. " ") or "" + local removed = git_info.removed and ("%#GitSignsDelete#-" .. git_info.removed .. " ") or "" + if git_info.added == 0 then + added = "" + end + if git_info.changed == 0 then + changed = "" + end + if git_info.removed == 0 then + removed = "" + end + return table.concat({ + " ", + "%#GitSignsAdd# ", + git_info.head, + " ", + added, + changed, + removed + }) +end +Statusline = {} +Statusline.active = function() + return table.concat({ + "%#Statusline#", + update_mode_colors(), + mode(), + "%#Normal# ", + filetype_only_icon(), + filepath(), + filename(), + "%#Normal#", + vcs(), + "%#Normal# ", + lsp(), + "%#Normal# ", + "%=", + -- filetype_with_icon(), + "%#StatusLineExtra#", + lineinfo() + }) +end +function Statusline.inactive() + return " %F" +end +function Statusline.short() + return " NvimTree" +end +function Statusline.terminal() + return " Terminal" +end + +vim.api.nvim_exec([[ + augroup Statusline + au! + au WinEnter,BufEnter * setlocal statusline=%!v:lua.Statusline.active() + au WinLeave,BufLeave * setlocal statusline=%!v:lua.Statusline.inactive() + au WinEnter,BufEnter,FileType NvimTree_* setlocal statusline=%!v:lua.Statusline.short() + au TermOpen * setlocal statusline=%!v:lua.Statusline.terminal() + augroup END + ]], false) + +-- vim.api.nvim_exec([[ +-- au BufEnter,BufWinEnter,WinEnter,CmdwinEnter * if bufname('%') == "NvimTree_1" | set laststatus=0 | else | set laststatus=2 | endif +-- ]], false) diff --git a/lua/lazysetup.lua b/lua/lazysetup.lua new file mode 100644 index 0000000..bd9aa72 --- /dev/null +++ b/lua/lazysetup.lua @@ -0,0 +1,14 @@ +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({{import="plugins"},{import="plugins.lsp"}}) diff --git a/lua/plugins/bufferline.lua b/lua/plugins/bufferline.lua new file mode 100644 index 0000000..e3e0d4c --- /dev/null +++ b/lua/plugins/bufferline.lua @@ -0,0 +1,13 @@ +return { + "akinsho/bufferline.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons" + }, + version = "*", + opts = { + options = { + mode = "tabs", + separator_style = "thin" + } + } +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..0c5d29b --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,16 @@ +local M = { + -- "bluz71/vim-nightfly-guicolors", + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + config = function() + require("catppuccin").setup({ + transparent_background = true + }) + vim.cmd("colorscheme catppuccin") -- catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha + -- vim.cmd( + -- "highlight Normal guibg=NONE ctermbg=NONE | highlight LineNr guibg=NONE ctermbg=NONE | highlight CursorLineNr guibg=NONE ctermbg=NONE | highlight EndOfBuffer guibg=NONE ctermbg=NONE | highlight SignColumn guibg=NONE ctermbg=NONE") + end +} + +return M diff --git a/lua/plugins/comment.lua b/lua/plugins/comment.lua new file mode 100644 index 0000000..3594a56 --- /dev/null +++ b/lua/plugins/comment.lua @@ -0,0 +1,20 @@ +-- add this to your lua/plugins.lua, lua/plugins/init.lua, or the file you keep your other plugins: +return { + 'numToStr/Comment.nvim', + event = { + "BufReadPre", + "BufNewFile" + }, + config = function() + require('Comment').setup({ + ignore = '^$', + toggler = { + line = '/' + }, + opleader = { + line = '/' + } + }) + end + +} diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 0000000..1c9fd0f --- /dev/null +++ b/lua/plugins/conform.lua @@ -0,0 +1,76 @@ +vim.api.nvim_create_user_command("FormatDisable", function(args) + if args.bang then + -- FormatDisable! will disable formatting just for this buffer + vim.b.disable_autoformat = true + else + vim.g.disable_autoformat = true + end +end, { + desc = "Disable autoformat-on-save", + bang = true +}) + +vim.api.nvim_create_user_command("FormatEnable", function() + vim.b.disable_autoformat = false + vim.g.disable_autoformat = false +end, { + desc = "Re-enable autoformat-on-save" +}) + +local options = { + lsp_fallback = true, + + formatters_by_ft = { + lua = { + "stylua" + }, + + sh = { + "shfmt" + }, + + cpp = { + "clang-format" + }, + + c = { + "clang-format" + }, + + python = { + "black" + } + }, + + format_on_save = function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + return { + timeout_ms = 3000, + lsp_fallback = true + } + end +} + +return { + "stevearc/conform.nvim", + -- for users those who want auto-save conform + lazyloading! + event = "BufWritePre", + cmd = { + "ConformInfo" + }, + config = function() + require("conform").setup(options) + end, + + -- Keymap + vim.keymap.set("n", "fm", function() + vim.lsp.buf.format { + async = true + } + end, { + desc = "Formating", + silent = true + }) +} diff --git a/lua/plugins/copilot-chat.lua b/lua/plugins/copilot-chat.lua new file mode 100644 index 0000000..c8ebe93 --- /dev/null +++ b/lua/plugins/copilot-chat.lua @@ -0,0 +1,60 @@ +return { + "CopilotC-Nvim/CopilotChat.nvim", + opts = { + show_help = "yes", -- Show help text for CopilotChatInPlace, default: yes + debug = false, -- Enable or disable debug mode, the log file will be in ~/.local/state/nvim/CopilotChat.nvim.log + disable_extra_info = 'no', -- Disable extra information (e.g: system prompt) in the response. + language = "English" -- Copilot answer language settings when using default prompts. Default language is English. + -- proxy = "socks5://127.0.0.1:3000", -- Proxies requests via https or socks. + -- temperature = 0.1, + }, + build = function() + vim.notify("Please update the remote plugins by running ':UpdateRemotePlugins', then restart Neovim.") + end, + event = "VeryLazy", + keys = { + { + "ccb", + ":CopilotChatBuffer ", + desc = "CopilotChat - Chat with current buffer" + }, + { + "cce", + "CopilotChatExplain", + desc = "CopilotChat - Explain code" + }, + { + "cct", + "CopilotChatTests", + desc = "CopilotChat - Generate tests" + }, + { + "ccT", + "CopilotChatVsplitToggle", + desc = "CopilotChat - Toggle Vsplit" -- Toggle vertical split + }, + { + "ccv", + ":CopilotChatVisual ", + mode = "x", + desc = "CopilotChat - Open in vertical split" + }, + { + "ccx", + ":CopilotChatInPlace", + mode = "x", + desc = "CopilotChat - Run in-place code" + }, + { + "ccf", + "CopilotChatFixDiagnostic", -- Get a fix for the diagnostic message under the cursor. + desc = "CopilotChat - Fix diagnostic" + }, + { + "ccr", + "CopilotChatReset", -- Reset chat history and clear buffer. + desc = "CopilotChat - Reset chat history and clear buffer" + } + } +} + diff --git a/lua/plugins/copilot.lua b/lua/plugins/copilot.lua new file mode 100644 index 0000000..c7f16f0 --- /dev/null +++ b/lua/plugins/copilot.lua @@ -0,0 +1,5 @@ +return { + "github/copilot.vim", + event = "VeryLazy", -- "InsertEnter", -- "BufRead + cmd = "Copilot" +} diff --git a/lua/plugins/dressing.lua b/lua/plugins/dressing.lua new file mode 100644 index 0000000..67724e2 --- /dev/null +++ b/lua/plugins/dressing.lua @@ -0,0 +1,4 @@ +return { + "stevearc/dressing.nvim", + event = "VeryLazy" +} diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..27323b1 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,8 @@ +return { + "lewis6991/gitsigns.nvim", + event = { + "BufReadPre", + "BufNewFile" + }, + config = true +} diff --git a/lua/plugins/lsp/lspconfig.lua b/lua/plugins/lsp/lspconfig.lua new file mode 100644 index 0000000..42f26bb --- /dev/null +++ b/lua/plugins/lsp/lspconfig.lua @@ -0,0 +1,136 @@ +return { + "neovim/nvim-lspconfig", + event = { + "BufReadPre", + "BufNewFile" + }, + dependencies = { + "hrsh7th/cmp-nvim-lsp", + { + "antosha417/nvim-lsp-file-operations", + config = true + } + }, + config = function() + -- import lspconfig plugin + local lspconfig = require("lspconfig") + + -- import cmp-nvim-lsp plugin + local cmp_nvim_lsp = require("cmp_nvim_lsp") + + local keymap = vim.keymap -- for conciseness + + local opts = { + noremap = true, + silent = true + } + local on_attach = function(client, bufnr) + opts.buffer = bufnr + + -- set keybinds + opts.desc = "Show LSP references" + keymap.set("n", "gR", "Telescope lsp_references", opts) -- show definition, references + + opts.desc = "Go to declaration" + keymap.set("n", "gD", vim.lsp.buf.declaration, opts) -- go to declaration + + opts.desc = "Show LSP definitions" + keymap.set("n", "gd", "Telescope lsp_definitions", opts) -- show lsp definitions + + opts.desc = "Show LSP implementations" + keymap.set("n", "gi", "Telescope lsp_implementations", opts) -- show lsp implementations + + opts.desc = "Show LSP type definitions" + keymap.set("n", "gt", "Telescope lsp_type_definitions", opts) -- show lsp type definitions + + opts.desc = "See available code actions" + keymap.set({ + "n", + "v" + }, "ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection + + opts.desc = "Smart rename" + keymap.set("n", "rn", vim.lsp.buf.rename, opts) -- smart rename + + opts.desc = "Show buffer diagnostics" + keymap.set("n", "D", "Telescope diagnostics bufnr=0", opts) -- show diagnostics for file + + opts.desc = "Show line diagnostics" + keymap.set("n", "d", vim.diagnostic.open_float, opts) -- show diagnostics for line + + opts.desc = "Go to previous diagnostic" + keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer + + opts.desc = "Go to next diagnostic" + keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer + + opts.desc = "Show documentation for what is under cursor" + keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor + + opts.desc = "Restart LSP" + keymap.set("n", "rs", ":LspRestart", opts) -- mapping to restart lsp if necessary + end + + -- used to enable autocompletion (assign to every lsp server config) + local capabilities = cmp_nvim_lsp.default_capabilities() + + -- Change the Diagnostic symbols in the sign column (gutter) + -- (not in youtube nvim video) + local signs = { + Error = " ", + Warn = " ", + Hint = "󰠠 ", + Info = " " + } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { + text = icon, + texthl = hl, + numhl = "" + }) + end + + -- configure clangd server + lspconfig["clangd"].setup({ + capabilities = capabilities, + on_attach = on_attach, + cmd = { + "clangd", + "--background-index", + "--suggest-missing-includes", + "--clang-tidy", + "--offset-encoding=utf-16" + } + }) + + -- configure python server + lspconfig["pyright"].setup({ + capabilities = capabilities, + on_attach = on_attach + }) + + -- configure lua server (with special settings) + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { -- custom settings for lua + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { + "vim" + } + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true + } + } + } + } + }) + end +} diff --git a/lua/plugins/lsp/mason.lua b/lua/plugins/lsp/mason.lua new file mode 100644 index 0000000..f07fe35 --- /dev/null +++ b/lua/plugins/lsp/mason.lua @@ -0,0 +1,50 @@ +return { + "williamboman/mason.nvim", + dependencies = { + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim" + }, + config = function() + -- import mason + local mason = require("mason") + + -- import mason-lspconfig + local mason_lspconfig = require("mason-lspconfig") + + local mason_tool_installer = require("mason-tool-installer") + + -- enable mason and configure icons + mason.setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } + }) + + mason_lspconfig.setup({ + -- list of servers for mason to install + ensure_installed = { + -- "clangd", -- C/C++ language server, use system clangd + -- "pyright", -- python language server, use system pyright + "lua_ls" -- lua language server + + }, + -- auto-install configured servers (with lspconfig) + automatic_installation = true -- not the same as ensure_installed + }) + + mason_tool_installer.setup({ + ensure_installed = { + "prettier", -- prettier formatter + "stylua", -- lua formatter + "isort", -- python formatter + "black", -- python formatter + "pylint", -- python linter + "clang-format" -- C/C++ formatter + } + }) + end +} diff --git a/lua/plugins/lsp_signature.lua b/lua/plugins/lsp_signature.lua new file mode 100644 index 0000000..43aecd2 --- /dev/null +++ b/lua/plugins/lsp_signature.lua @@ -0,0 +1,14 @@ +return { + 'ray-x/lsp_signature.nvim', + event = 'VeryLazy', + config = function() + require('lsp_signature').on_attach({ + bind = true, + floating_window = true, + transpancy = 80, + handler_opts = { + border = 'rounded' + } + }) + end +} diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua new file mode 100644 index 0000000..3ac2dc4 --- /dev/null +++ b/lua/plugins/nvim-autopairs.lua @@ -0,0 +1,36 @@ +return { + "windwp/nvim-autopairs", + event = { + "InsertEnter" + }, + dependencies = { + "hrsh7th/nvim-cmp" + }, + config = function() + -- import nvim-autopairs + local autopairs = require("nvim-autopairs") + + -- configure autopairs + autopairs.setup({ + check_ts = true, -- enable treesitter + ts_config = { + lua = { + "string" + }, -- don't add pairs in lua string treesitter nodes + javascript = { + "template_string" + }, -- don't add pairs in javscript template_string treesitter nodes + java = false -- don't check treesitter on java + } + }) + + -- import nvim-autopairs completion functionality + local cmp_autopairs = require("nvim-autopairs.completion.cmp") + + -- import nvim-cmp plugin (completions plugin) + local cmp = require("cmp") + + -- make autopairs and completion work together + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end +} diff --git a/lua/plugins/nvim-cmp.lua b/lua/plugins/nvim-cmp.lua new file mode 100644 index 0000000..20df895 --- /dev/null +++ b/lua/plugins/nvim-cmp.lua @@ -0,0 +1,66 @@ +return { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-buffer", -- source for text in buffer + "hrsh7th/cmp-path", -- source for file system paths + "L3MON4D3/LuaSnip", -- snippet engine + "saadparwaiz1/cmp_luasnip", -- for autocompletion + "rafamadriz/friendly-snippets", -- useful snippets + "onsails/lspkind.nvim" -- vs-code like pictograms + }, + config = function() + local cmp = require("cmp") + + local luasnip = require("luasnip") + + local lspkind = require("lspkind") + + -- loads vscode style snippets from installed plugins (e.g. friendly-snippets) + require("luasnip.loaders.from_vscode").lazy_load() + + cmp.setup({ + completion = { + completeopt = "menu,menuone,preview,noselect" + }, + snippet = { -- configure how nvim-cmp interacts with snippet engine + expand = function(args) + luasnip.lsp_expand(args.body) + end + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), -- previous suggestion + [""] = cmp.mapping.select_next_item(), -- next suggestion + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), -- show completion suggestions + [""] = cmp.mapping.abort(), -- close completion window + [""] = cmp.mapping.confirm({ + select = false + }) + }), + -- sources for autocompletion + sources = cmp.config.sources({ + { + name = "nvim_lsp" + }, + { + name = "luasnip" + }, -- snippets + { + name = "buffer" + }, -- text within current buffer + { + name = "path" + } -- file system paths + }), + -- configure lspkind for vs-code like pictograms in completion menu + formatting = { + format = lspkind.cmp_format({ + maxwidth = 50, + ellipsis_char = "..." + }) + } + }) + end +} diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..d76fb96 --- /dev/null +++ b/lua/plugins/nvim-treesitter.lua @@ -0,0 +1,45 @@ +return { + "nvim-treesitter/nvim-treesitter", + event = { + "BufReadPre", + "BufNewFile" + }, + build = ":TSUpdate", + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + "windwp/nvim-ts-autotag" + }, + + config = function() + local treesitter = require("nvim-treesitter.configs") + + treesitter.setup({ + ensure_installed = { + "lua", + "c", + "cpp", + "fortran", + "python", + "markdown", + "latex" + }, + auto_install = true, + highlight = { + enable = true + }, + -- enable indentation + indent = { + enable = true + }, + -- enable autotagging (w/ nvim-ts-autotag plugin) + autotag = { + enable = true + } + }) + + require"nvim-treesitter.install".compilers = { + "gcc" + } + end + +} diff --git a/lua/plugins/nvimtree.lua b/lua/plugins/nvimtree.lua new file mode 100644 index 0000000..060f5cf --- /dev/null +++ b/lua/plugins/nvimtree.lua @@ -0,0 +1,73 @@ +return { + "nvim-tree/nvim-tree.lua", + dependencies = { + "nvim-tree/nvim-web-devicons" + }, + config = function() + local nvimtree = require("nvim-tree") + + -- recommended settings from nvim-tree documentation + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + + -- change color for arrows in tree to light blue + -- vim.cmd([[ highlight NvimTreeFolderArrowClosed guifg=#3FC5FF ]]) + -- vim.cmd([[ highlight NvimTreeFolderArrowOpen guifg=#3FC5FF ]]) + + -- configure nvim-tree + nvimtree.setup({ + view = { + width = 35, + relativenumber = false + }, + -- change folder arrow icons + renderer = { + indent_markers = { + enable = true + }, + icons = { + glyphs = { + folder = { + arrow_closed = "", -- arrow when folder is closed + arrow_open = "" -- arrow when folder is open + } + } + } + }, + -- disable window_picker for + -- explorer to work well with + -- window splits + actions = { + open_file = { + window_picker = { + enable = false + } + } + }, + filters = { + custom = { + ".DS_Store" + } + }, + git = { + ignore = false + } + }) + + -- set keymaps + local keymap = vim.keymap -- for conciseness + + keymap.set("n", "ee", "NvimTreeToggle", { + desc = "Toggle file explorer" + }) -- toggle file explorer + keymap.set("n", "ef", "NvimTreeFindFileToggle", { + desc = "Toggle file explorer on current file" + }) -- toggle file explorer on current file + keymap.set("n", "ec", "NvimTreeCollapse", { + desc = "Collapse file explorer" + }) -- collapse file explorer + keymap.set("n", "er", "NvimTreeRefresh", { + desc = "Refresh file explorer" + }) -- refresh file explorer + end +} diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/lua/plugins/statusline.lua @@ -0,0 +1 @@ +return {} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..869c3f0 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,49 @@ +return { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { + "nvim-lua/plenary.nvim", + { + "nvim-telescope/telescope-fzf-native.nvim", + build = "make" + }, + "nvim-tree/nvim-web-devicons" + }, + config = function() + local telescope = require("telescope") + local actions = require("telescope.actions") + + telescope.setup({ + defaults = { + path_display = { + "truncate " + }, + mappings = { + i = { + [""] = actions.move_selection_previous, -- move to prev result + [""] = actions.move_selection_next, -- move to next result + [""] = actions.send_selected_to_qflist + actions.open_qflist + } + } + } + }) + + telescope.load_extension("fzf") + + -- set keymaps + local keymap = vim.keymap -- for conciseness + + keymap.set("n", "ff", "Telescope find_files", { + desc = "Fuzzy find files in cwd" + }) + keymap.set("n", "fr", "Telescope oldfiles", { + desc = "Fuzzy find recent files" + }) + keymap.set("n", "fs", "Telescope live_grep", { + desc = "Find string in cwd" + }) + keymap.set("n", "fc", "Telescope grep_string", { + desc = "Find string under cursor in cwd" + }) + end +} diff --git a/lua/plugins/toggleterm.lua b/lua/plugins/toggleterm.lua new file mode 100644 index 0000000..91c2ba4 --- /dev/null +++ b/lua/plugins/toggleterm.lua @@ -0,0 +1,22 @@ +return { + 'akinsho/toggleterm.nvim', + version = "*", + config = function() + require("toggleterm").setup({ + size = 20, + open_mapping = [[]], + hide_numbers = true, + shade_filetypes = {}, + shade_terminals = true, + shell = vim.o.shell, + direction = "float", + float_opts = { + border = "curved", + winblend = 3, + width = 80, + height = 15 + } + }) + end + +} diff --git a/lua/plugins/whichkey.lua b/lua/plugins/whichkey.lua new file mode 100644 index 0000000..f377cf8 --- /dev/null +++ b/lua/plugins/whichkey.lua @@ -0,0 +1,13 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 500 + end, + opts = { + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + } +} diff --git a/lua/unused/cmdline.lua b/lua/unused/cmdline.lua new file mode 100644 index 0000000..892ff36 --- /dev/null +++ b/lua/unused/cmdline.lua @@ -0,0 +1,32 @@ +-- lazy.nvim +return { + "folke/noice.nvim", + event = "VeryLazy", + opts = { + -- add any options here + }, + dependencies = { + "MunifTanjim/nui.nvim", + "rcarriga/nvim-notify" + }, + config = function() + require("noice").setup({ + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true -- requires hrsh7th/nvim-cmp + } + }, + -- you can enable a preset for easier configuration + presets = { + bottom_search = true, -- use a classic bottom cmdline for search + command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = false -- add a border to hover docs and signature help + } + }) + end +} diff --git a/lua/unused/floatterm.lua b/lua/unused/floatterm.lua new file mode 100644 index 0000000..e546e6d --- /dev/null +++ b/lua/unused/floatterm.lua @@ -0,0 +1,76 @@ +local term_bufnr +local term_winid +local float_terminal_open = false +local float_terminal_hidden = false + +vim.api.nvim_command('highlight MyFloatTerm guibg=none') + +function create_float_window(buff) + local buf_config = { + buftype = 'nofile', + hidden = true, + termfinish = 'close' + } + local width = vim.api.nvim_win_get_width(0) + local height = vim.api.nvim_win_get_height(0) + local win_config = { + relative = 'editor', + width = math.floor(width * 0.8), + height = math.floor(height * 0.8), + col = math.floor(width * 0.1), + row = math.floor(height * 0.1), + style = 'minimal', + border = 'rounded' + } + return vim.api.nvim_open_win(buff, true, win_config) +end + +function create_float_terminal() + term_bufnr = vim.api.nvim_create_buf(false, true) + term_winid = create_float_window(term_bufnr) + + vim.api.nvim_win_set_buf(term_winid, term_bufnr) + -- Set the background color to grey + vim.api.nvim_win_set_option(term_winid, 'winhighlight', 'Normal:MyFloatTerm') + vim.api.nvim_win_set_buf(term_winid, term_bufnr) + vim.api.nvim_command('terminal') + + -- Remove the status line + vim.api.nvim_win_set_option(term_winid, 'statusline', '') + + float_terminal_open = true + float_terminal_hidden = false + + vim.api.nvim_command('autocmd TermClose execute "bdelete! " . expand("")') + +end + +function _G.toggle_float_terminal() + if float_terminal_open then + if vim.api.nvim_buf_is_valid(term_bufnr) then + if float_terminal_hidden then + term_winid = create_float_window(term_bufnr) + vim.api.nvim_win_set_buf(term_winid, term_bufnr) + float_terminal_hidden = false + else + vim.api.nvim_win_close(term_winid, false) + float_terminal_hidden = true + end + else + float_terminal_open = false + create_float_terminal() + end + else + create_float_terminal() + end +end + +-- vim.api.nvim_set_keymap('n', '', ':lua _G.toggle_float_terminal()', { +-- noremap = true, +-- silent = true +-- }) + +-- vim.api.nvim_set_keymap('t', '', ':lua _G.toggle_float_terminal()', { +-- noremap = true, +-- silent = true +-- })