diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..21bacd2 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,3 @@ +require("config.options") +require("config.keybinds") +require("config.lazy") diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..a09d39a --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,27 @@ +{ + "LuaSnip": { "branch": "master", "commit": "eda5be8f0ce9816278671f0b578cdbb8b762c701" }, + "better-indent-support-for-php-with-html": { "branch": "master", "commit": "e907f07b53dd6d6b7b2f6956cd18202ef3f26c24" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, + "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, + "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, + "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, + "harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" }, + "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "c4c84f4521d62de595c0d0f718a9a40c1890c8ce" }, + "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-highlight-colors": { "branch": "main", "commit": "b42a5ccec7457b44e89f7ed3b3afb1b375bb2093" }, + "nvim-lspconfig": { "branch": "master", "commit": "6bba673aa8993eceec233be17b42ddfb9540794b" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "nvim-web-devicons": { "branch": "master", "commit": "19d6211c78169e78bab372b585b6fb17ad974e82" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "tokyonight.nvim": { "branch": "main", "commit": "057ef5d260c1931f1dffd0f052c685dcd14100a3" }, + "undotree": { "branch": "master", "commit": "b951b87b46c34356d44aa71886aecf9dd7f5788a" }, + "vim-doge": { "branch": "master", "commit": "03a84072ef21b205237c77986c78914395d646c3" }, + "vim-fugitive": { "branch": "master", "commit": "593f831d6f6d779cbabb70a4d1e6b1b1936a88af" }, + "vim-oscyank": { "branch": "main", "commit": "d67d76b2f19b868b70a1cf33a779d71dc092cb30" } +} diff --git a/nvim/lua/config/keybinds.lua b/nvim/lua/config/keybinds.lua new file mode 100644 index 0000000..465a35c --- /dev/null +++ b/nvim/lua/config/keybinds.lua @@ -0,0 +1,2 @@ +vim.g.mapleader = " " +vim.keymap.set("n", "cd", vim.cmd.Ex) diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua new file mode 100644 index 0000000..bdc4284 --- /dev/null +++ b/nvim/lua/config/lazy.lua @@ -0,0 +1,23 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + local lazyrepo = "https://github.com/folke/lazy.nvim.git" + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, + { out, "WarningMsg" }, + { "\nPress any key to exit..." }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end +end +vim.opt.rtp:prepend(lazypath) + + +require("lazy").setup({ + spec = { + { import = "plugins" }, + }, + change_detection = { notify = false }, +}) diff --git a/nvim/lua/config/options.lua b/nvim/lua/config/options.lua new file mode 100644 index 0000000..6fe2d46 --- /dev/null +++ b/nvim/lua/config/options.lua @@ -0,0 +1,7 @@ +vim.opt.number = true +vim.opt.cursorline = true +vim.opt.relativenumber = true +vim.opt.shiftwidth = 4 + + + diff --git a/nvim/lua/plugins/colors.lua b/nvim/lua/plugins/colors.lua new file mode 100644 index 0000000..ca51122 --- /dev/null +++ b/nvim/lua/plugins/colors.lua @@ -0,0 +1,23 @@ +local function enable_transparency() + vim.api.nvim_set_hl(0, "Normal", {bg = "none"}) +end + +return { + { + "folke/tokyonight.nvim", + config = function() + vim.cmd([[colorscheme tokyonight]]) + enable_transparency() + end, + }, + { + "nvim-lualine/lualine.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons", + + }, + opts = { + theme = "tokyonight", + } + } +} diff --git a/nvim/lua/plugins/harpoon.lua b/nvim/lua/plugins/harpoon.lua new file mode 100644 index 0000000..d016039 --- /dev/null +++ b/nvim/lua/plugins/harpoon.lua @@ -0,0 +1,39 @@ +local conf = require('telescope.config').values +local themes = require('telescope.themes') + +-- helper function to use telescope on harpoon list. +-- change get_ivy to other themes if wanted +local function toggle_telescope(harpoon_files) + local file_paths = {} + for _, item in ipairs(harpoon_files.items) do + table.insert(file_paths, item.value) + end + local opts = themes.get_ivy({ + promt_title = "Working List" + }) + + require("telescope.pickers").new(opts, { + finder = require("telescope.finders").new_table({ + results = file_paths, + }), + previewer = conf.file_previewer(opts), + sorter = conf.generic_sorter(opts), + }):find() +end + +return { + "ThePrimeagen/harpoon", + branch = "harpoon2", + dependencies = { + "nvim-lua/plenary.nvim" + }, + config = function() + local harpoon = require('harpoon') + vim.keymap.set("n", "a", function() harpoon:list():add() end) + vim.keymap.set("n", "", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) + vim.keymap.set("n", "fl", function() toggle_telescope(harpoon:list()) end, + { desc = "Open harpoon window" }) + vim.keymap.set("n", "", function() harpoon:list():prev() end) + vim.keymap.set("n", "", function() harpoon:list():next() end) + end +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..001cafa --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,230 @@ +return { + 'neovim/nvim-lspconfig', + dependencies = { + 'williamboman/mason.nvim', + 'williamboman/mason-lspconfig.nvim', + -- Autocompletion + 'hrsh7th/nvim-cmp', + 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-path', + 'saadparwaiz1/cmp_luasnip', + 'hrsh7th/cmp-nvim-lsp', + 'hrsh7th/cmp-nvim-lua', + -- Snippets + 'L3MON4D3/LuaSnip', + 'rafamadriz/friendly-snippets', + }, + config = function() + local autoformat_filetypes = { + "lua", + } + -- Create a keymap for vim.lsp.buf.implementation + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + if not client then return end + if vim.tbl_contains(autoformat_filetypes, vim.bo.filetype) then + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = args.buf, + callback = function() + vim.lsp.buf.format({ + formatting_options = { tabSize = 4, insertSpaces = true }, + bufnr = args.buf, + id = client.id + }) + end + }) + end + end + }) + + -- Add borders to floating windows + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, + { border = 'rounded' } + ) + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, + { border = 'rounded' } + ) + + -- Configure error/warnings interface + vim.diagnostic.config({ + virtual_text = true, + severity_sort = true, + float = { + style = 'minimal', + border = 'rounded', + header = '', + prefix = '', + }, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = '✘', + [vim.diagnostic.severity.WARN] = '▲', + [vim.diagnostic.severity.HINT] = '⚑', + [vim.diagnostic.severity.INFO] = '»', + }, + }, + }) + + -- Add cmp_nvim_lsp capabilities settings to lspconfig + -- This should be executed before you configure any language server + local lspconfig_defaults = require('lspconfig').util.default_config + lspconfig_defaults.capabilities = vim.tbl_deep_extend( + 'force', + lspconfig_defaults.capabilities, + require('cmp_nvim_lsp').default_capabilities() + ) + + -- This is where you enable features that only work + -- if there is a language server active in the file + vim.api.nvim_create_autocmd('LspAttach', { + callback = function(event) + local opts = { buffer = event.buf } + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({ 'n', 'x' }, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end, + }) + + require('mason').setup({}) + require('mason-lspconfig').setup({ + ensure_installed = { + "lua_ls", + "intelephense", + "ts_ls", + "eslint", + }, + handlers = { + -- this first function is the "default handler" + -- it applies to every language server without a custom handler + function(server_name) + require('lspconfig')[server_name].setup({}) + end, + + -- this is the "custom handler" for `lua_ls` + lua_ls = function() + require('lspconfig').lua_ls.setup({ + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = { 'vim' }, + }, + workspace = { + library = { vim.env.VIMRUNTIME }, + }, + }, + }, + }) + end, + }, + }) + + local cmp = require('cmp') + + require('luasnip.loaders.from_vscode').lazy_load() + + vim.opt.completeopt = { 'menu', 'menuone', 'noselect' } + + cmp.setup({ + preselect = 'item', + completion = { + completeopt = 'menu,menuone,noinsert' + }, + window = { + documentation = cmp.config.window.bordered(), + }, + sources = { + { name = 'path' }, + { name = 'nvim_lsp' }, + { name = 'buffer', keyword_length = 3 }, + { name = 'luasnip', keyword_length = 2 }, + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + formatting = { + fields = { 'abbr', 'menu', 'kind' }, + format = function(entry, item) + local n = entry.source.name + if n == 'nvim_lsp' then + item.menu = '[LSP]' + else + item.menu = string.format('[%s]', n) + end + return item + end, + }, + mapping = cmp.mapping.preset.insert({ + -- confirm completion item + [''] = cmp.mapping.confirm({ select = false }), + + -- scroll documentation window + [''] = cmp.mapping.scroll_docs(5), + [''] = cmp.mapping.scroll_docs(-5), + + -- toggle completion menu + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.abort() + else + cmp.complete() + end + end), + + -- tab complete + [''] = cmp.mapping(function(fallback) + local col = vim.fn.col('.') - 1 + + if cmp.visible() then + cmp.select_next_item({ behavior = 'select' }) + elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then + fallback() + else + cmp.complete() + end + end, { 'i', 's' }), + + -- go to previous item + [''] = cmp.mapping.select_prev_item({ behavior = 'select' }), + + -- navigate to next snippet placeholder + [''] = cmp.mapping(function(fallback) + local luasnip = require('luasnip') + + if luasnip.jumpable(1) then + luasnip.jump(1) + else + fallback() + end + end, { 'i', 's' }), + + -- navigate to the previous snippet placeholder + [''] = cmp.mapping(function(fallback) + local luasnip = require('luasnip') + + if luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + }) + end +} diff --git a/nvim/lua/plugins/oneliners.lua b/nvim/lua/plugins/oneliners.lua new file mode 100644 index 0000000..17ffc91 --- /dev/null +++ b/nvim/lua/plugins/oneliners.lua @@ -0,0 +1,24 @@ +return { + { -- This helps with php/html for indentation + 'captbaritone/better-indent-support-for-php-with-html', + }, + { -- This helps with ssh tunneling and copying to clipboard + 'ojroques/vim-oscyank', + }, + { -- This generates docblocks + 'kkoomen/vim-doge', + build = ':call doge#install()' + }, + { -- Git plugin + 'tpope/vim-fugitive', + }, + { -- Show historical versions of the file locally + 'mbbill/undotree', + }, + { -- Show CSS Colors + 'brenoprata10/nvim-highlight-colors', + config = function() + require('nvim-highlight-colors').setup({}) + end + }, +} diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..6eaf581 --- /dev/null +++ b/nvim/lua/plugins/telescope.lua @@ -0,0 +1,11 @@ +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', 'ff', builtin.find_files, { desc = 'Telescope find files' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = 'Telescope live grep' }) + vim.keymap.set('n', 'fb', builtin.buffers, { desc = 'Telescope buffers' }) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) + end +} diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua new file mode 100644 index 0000000..e15b627 --- /dev/null +++ b/nvim/lua/plugins/treesitter.lua @@ -0,0 +1,19 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local configs = require("nvim-treesitter.configs") + configs.setup({ + highlight = { + enable = true, + }, + indent = { enable = true }, + autotage = { enable = true}, + ensure_installed = { + "c", "go", "rust", "typescript", "tsx", "javascript", "yaml", "json", "zig", "python", "cpp" + }, + auto_install = false + + }) + end +}