commit 94bf4f62c1ef66a102bb4322ef2d042cc936df6f Author: jaredgoldman Date: Sat Apr 6 21:14:14 2024 -0600 initial commit diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f4409b1 --- /dev/null +++ b/init.lua @@ -0,0 +1,12 @@ +require("options") +require("plugins") +require("config.telescope") +require("keymaps") +require("lsp") +require("colorscheme") +require("config.mason") +require("config.nvim-tree") +require("config.comment") +require("config.themery") +require("config.theme") +require("config.lualine") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..092490b --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,23 @@ +{ + "LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" }, + "catppuccin": { "branch": "main", "commit": "aebe43db9cb26e1c70fc5b2fd4158169c405e720" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "lazy.nvim": { "branch": "main", "commit": "bef521ac89c8d423f9d092e37b58e8af0c099309" }, + "lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" }, + "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "9dfcf2036c223920826140f0151d929a43f9eceb" }, + "mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" }, + "monokai.nvim": { "branch": "master", "commit": "b8bd44d5796503173627d7a1fc51f77ec3a08a63" }, + "nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, + "nvim-comment": { "branch": "main", "commit": "e9ac16ab056695cad6461173693069ec070d2b23" }, + "nvim-lspconfig": { "branch": "master", "commit": "9619e53d3f99f0ca4ea3b88f5d97fce703131820" }, + "nvim-tree.lua": { "branch": "master", "commit": "81eb8d519233c105f30dc0a278607e62b20502fd" }, + "nvim-web-devicons": { "branch": "master", "commit": "93ddac6966d5d3416f96df728d7b92e27aaa4452" }, + "plenary.nvim": { "branch": "master", "commit": "8aad4396840be7fc42896e3011751b7609ca4119" }, + "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, + "themery.nvim": { "branch": "main", "commit": "1005a58801276d29c4b1e11244cf7631250f9143" }, + "vim-maximizer": { "branch": "master", "commit": "2e54952fe91e140a2e69f35f22131219fcd9c5f1" } +} \ No newline at end of file diff --git a/lua/colorscheme.lua b/lua/colorscheme.lua new file mode 100644 index 0000000..a166fb5 --- /dev/null +++ b/lua/colorscheme.lua @@ -0,0 +1,8 @@ +-- define your colorscheme here +local colorscheme = 'monokai_pro' + +local is_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) +if not is_ok then + vim.notify('colorscheme ' .. colorscheme .. ' not found!') + return +end diff --git a/lua/config/comment.lua b/lua/config/comment.lua new file mode 100644 index 0000000..f1783e6 --- /dev/null +++ b/lua/config/comment.lua @@ -0,0 +1 @@ +require('nvim_comment').setup({comment_empty = false}) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua new file mode 100644 index 0000000..4414826 --- /dev/null +++ b/lua/config/lualine.lua @@ -0,0 +1,8 @@ +-- local base16 = require'lualine.themes.base16' +local ayu_dark = require'lualine.themes.ayu_dark' + +-- Change the background of lualine_c section for normal mode + +require('lualine').setup { + options = { theme = ayu_dark }, +} diff --git a/lua/config/mason.lua b/lua/config/mason.lua new file mode 100644 index 0000000..b6e2caa --- /dev/null +++ b/lua/config/mason.lua @@ -0,0 +1,24 @@ +-- Mason +require('mason').setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗" + } + } +}) +-- A list of servers to automatically install if they're not already installed +require('mason-lspconfig').setup({ + ensure_installed = { + 'cssls', + 'cssmodules_ls', + 'graphql', + 'html', + 'intelephense', + 'tailwindcss', + 'tsserver', + 'jsonls', + 'lua_ls' + }, +}) diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua new file mode 100644 index 0000000..337abab --- /dev/null +++ b/lua/config/nvim-cmp.lua @@ -0,0 +1,78 @@ +local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil +end + +local luasnip = require("luasnip") +local cmp = require("cmp") + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = cmp.mapping.preset.insert({ + -- Use to scroll the docs + [''] = cmp.mapping.scroll_docs( -4), + [''] = cmp.mapping.scroll_docs(4), + -- Use to switch in items + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + -- Use (Enter) to confirm selection + -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.confirm({ select = true }), + -- A super tab + -- sourc: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip + [""] = cmp.mapping(function(fallback) + -- Hint: if the completion menu is visible select next one + if cmp.visible() then + cmp.select_next_item() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), -- i - insert mode; s - select mode + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable( -1) then + luasnip.jump( -1) + else + fallback() + end + end, { "i", "s" }), + }), + + -- Let's configure the item's appearance + -- source: https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance + formatting = { + -- Set order from left to right + -- kind: single letter indicating the type of completion + -- abbr: abbreviation of "word"; when not empty it is used in the menu instead of "word" + -- menu: extra text for the popup menu, displayed after "word" or "abbr" + fields = { 'abbr', 'menu' }, + + -- customize the appearance of the completion menu + format = function(entry, vim_item) + vim_item.menu = ({ + nvim_lsp = '[Lsp]', + luasnip = '[Luasnip]', + buffer = '[File]', + path = '[Path]', + })[entry.source.name] + return vim_item + end, + }, + + -- Set source precedence + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, -- For nvim-lsp + { name = 'luasnip' }, -- For luasnip user + { name = 'buffer' }, -- For buffer word completion + { name = 'path' }, -- For path completion + }) +}) diff --git a/lua/config/nvim-tree.lua b/lua/config/nvim-tree.lua new file mode 100644 index 0000000..86cc36c --- /dev/null +++ b/lua/config/nvim-tree.lua @@ -0,0 +1,14 @@ +require("nvim-tree").setup({ + sort = { + sorter = "case_sensitive", + }, + view = { + width = 30, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = true, + }, +}) diff --git a/lua/config/telescope.lua b/lua/config/telescope.lua new file mode 100644 index 0000000..3fa81ec --- /dev/null +++ b/lua/config/telescope.lua @@ -0,0 +1,30 @@ +local actions = require("telescope.actions") + +require('telescope').setup { + defaults = { + -- Default configuration for telescope goes here: + -- config_key = value, + mappings = { + i = { + [""] = actions.close, + [""] = false + } + } + }, + pickers = { + -- Default configuration for builtin pickers goes here: + -- picker_name = { + -- picker_config_key = value, + -- ... + -- } + -- Now the picker_config_key will be applied every time you call this + -- builtin picker + }, + extensions = { + -- Your extension configuration goes here: + -- extension_name = { + -- extension_config_key = value, + -- } + -- please take a look at the readme of the extension you want to configure + } +} diff --git a/lua/config/theme.lua b/lua/config/theme.lua new file mode 100644 index 0000000..b6daebe --- /dev/null +++ b/lua/config/theme.lua @@ -0,0 +1,5 @@ +-- Themery block +-- This block will be replaced by Themery. +vim.cmd("colorscheme catppuccin-mocha") +vim.g.theme_id = 2 +-- end themery block diff --git a/lua/config/themery.lua b/lua/config/themery.lua new file mode 100644 index 0000000..b89ff82 --- /dev/null +++ b/lua/config/themery.lua @@ -0,0 +1,13 @@ +-- Set custom name to the list +require("themery").setup({ + themes = { { + name = "Day", + colorscheme = "catppuccin-latte", + }, + { + name = "Night", + colorscheme = "catppuccin-mocha", + } }, + themeConfigFile = "~/.config/nvim/lua/config/theme.lua", -- Desibed below + livePreview = true, -- Apply theme while browsing. Default to true. +}) diff --git a/lua/keymaps.lua b/lua/keymaps.lua new file mode 100644 index 0000000..fedc054 --- /dev/null +++ b/lua/keymaps.lua @@ -0,0 +1,50 @@ +local keymap = vim.api.nvim_set_keymap +local opts = { noremap = true, silent = true } + +local mappings = { + n = { + ["nh"] = ":nohl", + ["sv"] = "s", + ["sh"] = "v", + ["se"] = "=", + ["sx"] = ":close", + -- nvim-tree + ["e"] = ":NvimTreeToggle", + ["cf"] = ":NvimTreeCollapse", + -- lsp + ["ls"] = ":lspstop", + ["lo"] = ":lspstart", + -- move between buffers + [""] = "h", + [""] = "j", + [""] = "k", + [""] = "l", + ["ff"] = "Telescope find_files", + ["fw"] = "Telescope live_grep", + ["fc"] = "Telescope grep_string", + ["th"] = "Themery", + ["sm"] = ":MaximizerToggle" + }, + x = { + ["J"] = ":move '>+1gv-gv", + ["K"] = ":move '<-2gv-gv", + [""] = ":move '>+1gv-gv", + [""] = ":move '<-2gv-gv", + }, + i = { + ["c-j"] = [[lua require('copilot').accept()]], + [""] = "", + }, +} + +for mode, mode_mappings in pairs(mappings) do + for key, mapping in pairs(mode_mappings) do + if type(mapping) == "function" then + keymap(mode, key, "lua " .. mapping() .. "<>", opts) + elseif type(mapping) == "table" then + keymap(mode, key, mapping[1], mapping[2] or opts) + else + keymap(mode, key, mapping, opts) + end + end +end diff --git a/lua/lsp.lua b/lua/lsp.lua new file mode 100644 index 0000000..8ab0d23 --- /dev/null +++ b/lua/lsp.lua @@ -0,0 +1,75 @@ +-- Set different settings for different languages' LSP +-- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md +-- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D +-- - the settings table is sent to the LSP +-- - on_attach: a lua callback function to run after LSP attaches to a given buffer +local lspconfig = require('lspconfig') + +-- Customized on_attach function +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap = true, silent = true } + +local mappings = { + ['k'] = vim.diagnostic.open_float, + ['[d'] = vim.diagnostic.goto_prev, + [']d'] = vim.diagnostic.goto_next, + ['q'] = vim.diagnostic.setloclist, + ['gD'] = vim.lsp.buf.declaration, + ['gd'] = vim.lsp.buf.definition, + ['K'] = vim.lsp.buf.hover, + ['gi'] = vim.lsp.buf.implementation, + ['wa'] = vim.lsp.buf.add_workspace_folder, + ['wr'] = vim.lsp.buf.remove_workspace_folder, + ['wl'] = function() + print(vim.inspect(vim.lsp.buf.list_workleader_folders())) + end, + ['D'] = vim.lsp.buf.type_definition, + ['rn'] = vim.lsp.buf.rename, + ['ca'] = vim.lsp.buf.code_action, + ['gr'] = vim.lsp.buf.references, + ['fm'] = function() + vim.lsp.buf.format({ async = true }) + end, +} + +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + local bufopts = { noremap = true, silent = true, buffer = bufnr } + for key, mapping in pairs(mappings) do + vim.keymap.set('n', key, mapping, bufopts) + end +end + +local servers = { + "tsserver", + "intelephense", + "tailwindcss", + "lua_ls", +} +local capabilities = vim.lsp.protocol.make_client_capabilities() + +capabilities.textDocument.completion.completionItem = { + documentationFormat = { "markdown", "plaintext" }, + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { valueSet = { 1 } }, + resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, + }, +} + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = on_attach, + capabilities = capabilities, + } +end diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..1c53cc6 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,48 @@ +local opt = vim.opt +local api = vim.api +local global = vim.g + +-- Hint: use `:h