From 97ed2b6a18fcf2c11ae4d4cd0f11acbe31078650 Mon Sep 17 00:00:00 2001 From: tonybanters Date: Sun, 9 Feb 2025 19:30:29 -0800 Subject: [PATCH] First commit. --- .gitignore | 1 + init.lua | 3 + lua/config/keybinds.lua | 5 + lua/config/lazy.lua | 21 ++++ lua/config/options.lua | 12 ++ lua/plugins/colors.lua | 15 +++ lua/plugins/harpoon.lua | 39 +++++++ lua/plugins/init.lua | 6 + lua/plugins/lsp.lua | 230 +++++++++++++++++++++++++++++++++++++ lua/plugins/one-liners.lua | 18 +++ lua/plugins/statusline.lua | 13 +++ lua/plugins/telescope.lua | 49 ++++++++ lua/plugins/treesitter.lua | 43 +++++++ 13 files changed, 455 insertions(+) create mode 100644 .gitignore create mode 100644 init.lua create mode 100644 lua/config/keybinds.lua create mode 100644 lua/config/lazy.lua create mode 100644 lua/config/options.lua create mode 100644 lua/plugins/colors.lua create mode 100644 lua/plugins/harpoon.lua create mode 100644 lua/plugins/init.lua create mode 100644 lua/plugins/lsp.lua create mode 100644 lua/plugins/one-liners.lua create mode 100644 lua/plugins/statusline.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/plugins/treesitter.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e033bc6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lazy-lock.json diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..e7df95d --- /dev/null +++ b/init.lua @@ -0,0 +1,3 @@ +require('config.options') +require('config.keybinds') +require('config.lazy') diff --git a/lua/config/keybinds.lua b/lua/config/keybinds.lua new file mode 100644 index 0000000..88edc00 --- /dev/null +++ b/lua/config/keybinds.lua @@ -0,0 +1,5 @@ +-- KEYBINDS + +vim.g.mapleader = " " + +vim.keymap.set("n", "cd", vim.cmd.Ex) diff --git a/lua/config/lazy.lua b/lua/config/lazy.lua new file mode 100644 index 0000000..987478a --- /dev/null +++ b/lua/config/lazy.lua @@ -0,0 +1,21 @@ +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) + +-- Setup lazy.nvim +require("lazy").setup({ + spec = "plugins", + change_detection = { notify = false }, +}) diff --git a/lua/config/options.lua b/lua/config/options.lua new file mode 100644 index 0000000..33466c4 --- /dev/null +++ b/lua/config/options.lua @@ -0,0 +1,12 @@ +-- OPTIONS +local set = vim.opt + +--line nums +set.relativenumber = true +set.number = true + +--tab spaces globally +set.shiftwidth = 4 + +-- signcolumn and cursor +set.signcolumn = 'yes' diff --git a/lua/plugins/colors.lua b/lua/plugins/colors.lua new file mode 100644 index 0000000..e4d39e7 --- /dev/null +++ b/lua/plugins/colors.lua @@ -0,0 +1,15 @@ +return { + -- { + -- "Mofiqul/voscode.nvim", + -- name = 'vscode', + -- config = function() + -- vim.cmd.colorscheme "vscode" + -- end + -- } + { + "folke/tokyonight.nvim", + config = function() + vim.cmd.colorscheme "tokyonight" + end + } +} diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua new file mode 100644 index 0000000..7103794 --- /dev/null +++ b/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/lua/plugins/init.lua b/lua/plugins/init.lua new file mode 100644 index 0000000..e5acb8b --- /dev/null +++ b/lua/plugins/init.lua @@ -0,0 +1,6 @@ +return { + -- { + -- "nvim-lua/plenary.nvim", + -- name = "plenary" + -- }, +} diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..8c0992e --- /dev/null +++ b/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/lua/plugins/one-liners.lua b/lua/plugins/one-liners.lua new file mode 100644 index 0000000..9b6e8ea --- /dev/null +++ b/lua/plugins/one-liners.lua @@ -0,0 +1,18 @@ +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', + }, +} diff --git a/lua/plugins/statusline.lua b/lua/plugins/statusline.lua new file mode 100644 index 0000000..87b9fa9 --- /dev/null +++ b/lua/plugins/statusline.lua @@ -0,0 +1,13 @@ +return { + { + 'echasnovski/mini.nvim', + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + config = function() + local statusline = require 'mini.statusline' + statusline.setup { use_icons = true } + end + } +} + diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..e23c7e9 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,49 @@ +return { + 'nvim-telescope/telescope.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + config = function() + local actions = require('telescope.actions') + require('telescope').setup({ + defaults = { + 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, -- send selected to quickfixlist + } + } + } + }) + + local builtin = require('telescope.builtin') + vim.keymap.set('n', 'ff', builtin.find_files, {}) + vim.keymap.set('n', 'fg', builtin.git_files, {}) + vim.keymap.set('n', 'fo', builtin.oldfiles, {}) + vim.keymap.set('n', 'fq', builtin.quickfix, {}) + vim.keymap.set('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) + vim.keymap.set('n', 'fb', builtin.buffers, { desc = 'Telescope buffers' }) + + -- Rip grep + Fzf + vim.keymap.set('n', 'fg', function() + builtin.grep_string({ search = vim.fn.input("Grep > ") }); + end) + + -- Find instance instance of current view being included + vim.keymap.set('n', 'fc', function() + local filename_without_extension = vim.fn.expand('%:t:r') + builtin.grep_string({ search = filename_without_extension }) + end, {desc = "Find current file: "}) + + -- Grep current string (for when gd doesn't work) + vim.keymap.set('n', 'fs', function() + builtin.grep_string({}) + end, {desc = "Find current string: "}) + + -- find files in vim config + vim.keymap.set('n', 'fi', function() + builtin.find_files({cwd="~/.config/nvim/"}); + end) + end +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua new file mode 100644 index 0000000..ce906c1 --- /dev/null +++ b/lua/plugins/treesitter.lua @@ -0,0 +1,43 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local configs = require("nvim-treesitter.configs") + configs.setup({ + -- enable syntax highlighting + highlight = { + enable = true, + }, + -- enable indentation + indent = { enable = true }, + -- enable autotagging (w/ nvim-ts-autotag plugin) + autotag = { enable = true }, + -- ensure these language parsers are installed + ensure_installed = { + "json", + "javascript", + "query", + "typescript", + "tsx", + "php", + "yaml", + "html", + "css", + "markdown", + "markdown_inline", + "bash", + "lua", + "vim", + "vimdoc", + "c", + "dockerfile", + "gitignore", + "astro", + }, + -- auto install above language parsers + auto_install = true, + }) + end + } +}