From 63694deb4f3bbfe18e398f82751705461e620009 Mon Sep 17 00:00:00 2001 From: bunny winter Date: Sat, 4 Jan 2025 08:07:29 -0600 Subject: [PATCH] initial commit --- .gitignore | 1 + init.lua | 1 + lazy-lock.json | 23 +++++ lua/nyanko/init.lua | 7 ++ lua/nyanko/lazy/catppuccin.lua | 8 ++ lua/nyanko/lazy/cmp.lua | 85 ++++++++++++++++++ lua/nyanko/lazy/conform.lua | 47 ++++++++++ lua/nyanko/lazy/lazydev.lua | 18 ++++ lua/nyanko/lazy/lspconfig.lua | 144 ++++++++++++++++++++++++++++++ lua/nyanko/lazy/lualine.lua | 25 ++++++ lua/nyanko/lazy/telescope.lua | 26 ++++++ lua/nyanko/lazy/todo-comments.lua | 10 +++ lua/nyanko/lazy/treesitter.lua | 33 +++++++ lua/nyanko/lazy/which-key.lua | 12 +++ lua/nyanko/lazy_init.lua | 31 +++++++ lua/nyanko/opt.lua | 37 ++++++++ 16 files changed, 508 insertions(+) create mode 100644 .gitignore create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/nyanko/init.lua create mode 100644 lua/nyanko/lazy/catppuccin.lua create mode 100644 lua/nyanko/lazy/cmp.lua create mode 100644 lua/nyanko/lazy/conform.lua create mode 100644 lua/nyanko/lazy/lazydev.lua create mode 100644 lua/nyanko/lazy/lspconfig.lua create mode 100644 lua/nyanko/lazy/lualine.lua create mode 100644 lua/nyanko/lazy/telescope.lua create mode 100644 lua/nyanko/lazy/todo-comments.lua create mode 100644 lua/nyanko/lazy/treesitter.lua create mode 100644 lua/nyanko/lazy/which-key.lua create mode 100644 lua/nyanko/lazy_init.lua create mode 100644 lua/nyanko/opt.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..a61c808 --- /dev/null +++ b/init.lua @@ -0,0 +1 @@ +require("nyanko") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..1f3ccaa --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,23 @@ +{ + "LuaSnip": { "branch": "master", "commit": "33b06d72d220aa56a7ce80a0dd6f06c70cd82b9d" }, + "catppuccin": { "branch": "main", "commit": "f67b886d65a029f12ffa298701fb8f1efd89295d" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "conform.nvim": { "branch": "master", "commit": "9180320205d250429f0f80e073326c674e2a7149" }, + "fidget.nvim": { "branch": "main", "commit": "9238947645ce17d96f30842e61ba81147185b657" }, + "friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" }, + "lazydev.nvim": { "branch": "main", "commit": "8620f82ee3f59ff2187647167b6b47387a13a018" }, + "lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" }, + "luvit-meta": { "branch": "main", "commit": "57d464c4acb5c2e66bd4145060f5dc9e96a7bbb7" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "c6c686781f9841d855bf1b926e10aa5e19430a38" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "nvim-cmp": { "branch": "main", "commit": "b555203ce4bd7ff6192e759af3362f9d217e8c89" }, + "nvim-lspconfig": { "branch": "master", "commit": "8b15a1a597a59f4f5306fad9adfe99454feab743" }, + "nvim-treesitter": { "branch": "master", "commit": "7e0fcf0d456fc5818da1af35b1a3f5c784fce457" }, + "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, + "which-key.nvim": { "branch": "main", "commit": "8ab96b38a2530eacba5be717f52e04601eb59326" } +} diff --git a/lua/nyanko/init.lua b/lua/nyanko/init.lua new file mode 100644 index 0000000..9b229f0 --- /dev/null +++ b/lua/nyanko/init.lua @@ -0,0 +1,7 @@ +-- set leader key +-- this has to happen before plugins load or it won't work +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +require("nyanko.opt") +require("nyanko.lazy_init") diff --git a/lua/nyanko/lazy/catppuccin.lua b/lua/nyanko/lazy/catppuccin.lua new file mode 100644 index 0000000..d6b4f5d --- /dev/null +++ b/lua/nyanko/lazy/catppuccin.lua @@ -0,0 +1,8 @@ +return { + "catppuccin/nvim", + name = "catppuccin", + priority = 1000, + init = function() + vim.cmd.colorscheme("catppuccin-mocha") + end, +} diff --git a/lua/nyanko/lazy/cmp.lua b/lua/nyanko/lazy/cmp.lua new file mode 100644 index 0000000..d7690e6 --- /dev/null +++ b/lua/nyanko/lazy/cmp.lua @@ -0,0 +1,85 @@ +return { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + { + "L3MON4D3/LuaSnip", + build = (function() + -- build step is needed for regex support + -- this fails on windows a lot of the time + if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then + return + end + + return "make install_jsregexp" + end)(), + dependencies = { + { + "rafamadriz/friendly-snippets", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + }, + }, + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + }, + config = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + + luasnip.config.setup({}) + + cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + completion = { + completeopt = "menu,menuone,noinsert", + }, + + mapping = cmp.mapping.preset.insert({ + -- select the [n]ext item + [""] = cmp.mapping.select_next_item(), + -- select the [p]revious item + [""] = cmp.mapping.select_prev_item(), + + -- scroll the documentation window [b]ack or [f]orward + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + + -- accept ([y]es) the completion + [""] = cmp.mapping.confirm({ select = true }), + + -- manually trigger a completion from nvim-cmp + -- you shouldn't need this, nvim-cmp will display completions + -- whenever it has options available + [""] = cmp.mapping.complete({}), + + -- move forward or backward through the snippet expansion + [""] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { "i", "s" }), + [""] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { "i", "s" }), + }), + sources = { + { + name = "lazydev", + group_index = 0, + }, + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "path" }, + }, + }) + end, +} diff --git a/lua/nyanko/lazy/conform.lua b/lua/nyanko/lazy/conform.lua new file mode 100644 index 0000000..604261a --- /dev/null +++ b/lua/nyanko/lazy/conform.lua @@ -0,0 +1,47 @@ +return { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + "f", + function() + require("conform").format({ + async = true, + lsp_format = "fallback", + }) + end, + mode = "", + desc = "[F]ormat buffer", + }, + }, + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + local disable_filetypes = { + c = true, + cpp = true, + } + + local lsp_format_opt + if disable_filetypes[vim.bo[bufnr].filetype] then + lsp_format_opt = "never" + else + lsp_format_opt = "fallback" + end + + return { + timeout_ms = 500, + lsp_format = lsp_format_opt, + } + end, + formatters_by_ft = { + lua = { "stylua" }, + javascript = { "prettierd" }, + javascriptreact = { "prettierd" }, + typescript = { "prettierd" }, + typescriptreact = { "prettierd" }, + json = { "prettierd" }, + }, + }, +} diff --git a/lua/nyanko/lazy/lazydev.lua b/lua/nyanko/lazy/lazydev.lua new file mode 100644 index 0000000..5dde521 --- /dev/null +++ b/lua/nyanko/lazy/lazydev.lua @@ -0,0 +1,18 @@ +return { + { + "folke/lazydev.nvim", + ft = "lua", + opts = { + library = { + { + path = "luvit-meta/library", + words = { "vim%.uv" }, + }, + }, + }, + }, + { + "Bilal2453/luvit-meta", + lazy = true, + }, +} diff --git a/lua/nyanko/lazy/lspconfig.lua b/lua/nyanko/lazy/lspconfig.lua new file mode 100644 index 0000000..5c9ede4 --- /dev/null +++ b/lua/nyanko/lazy/lspconfig.lua @@ -0,0 +1,144 @@ +return { + "neovim/nvim-lspconfig", + dependencies = { + { "williamboman/mason.nvim", config = true }, + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + "hrsh7th/cmp-nvim-lsp", + + -- useful LSP status updates + { "j-hui/fidget.nvim", opts = {} }, + }, + config = function() + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("nyanko-lsp-attach", { clear = true }), + callback = function(event) + -- highlight references of the word under cursor + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then + local highlight_augroup = vim.api.nvim_create_augroup("nyanko-lsp-highlight", { clear = false }) + + vim.api.nvim_create_autocmd({ + "CursorHold", + "CursorHoldI", + }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ + "CursorMoved", + "CursorMovedI", + }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.clear_references, + }) + + vim.api.nvim_create_autocmd("LspDetach", { + group = vim.api.nvim_create_augroup("nyanko-lsp-detach", { clear = true }), + callback = function(detach_event) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds({ + group = "nyanko-lsp-highlight", + buffer = detach_event.buf, + }) + end, + }) + end + end, + }) + + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) + + local servers = { + lua_ls = { + settings = { + Lua = { + completion = { + callSnippet = "replace", + }, + }, + }, + }, + html = {}, + cssls = {}, + eslint = { + settings = { + workingDirectories = { mode = "auto" }, + }, + }, + jsonls = { + settings = { + json = { + schemas = { + { + fileMatch = { "package.json" }, + url = "https://json.schemastore.org/package.json", + }, + { + fileMatch = { "tsconfig*.json" }, + url = "https://json.schemastore.org/tsconfig.json", + }, + { + fileMatch = { ".prettierrc", ".prettierrc.json" }, + url = "https://json.schemastore.org/prettierrc.json", + }, + { + fileMatch = { ".eslintrc", ".eslintrc.json" }, + url = "https//json.schemastore.org/eslintrc.json", + }, + }, + }, + }, + }, + ts_ls = {}, + tailwindcss = { + settings = { + tailwindCSS = { + experimental = { + classRegex = { + "tw`([^`]*)", + 'tw="([^"]*)', + 'tw={"([^"}]*)', + "tw\\.\\w+`([^`]*)", + "tw\\(.*?\\)`([^`]*)", + { "clsx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)" }, + { "classnames\\(([^)]*)\\)", "'([^']*)'" }, + { "cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]" }, + { "cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)" }, + }, + }, + }, + }, + }, + } + + require("mason").setup() + + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + "stylua", -- used to format lua code + "prettierd", + }) + + require("mason-tool-installer").setup({ + ensure_installed = ensure_installed, + }) + + require("mason-lspconfig").setup({ + ensure_installed = {}, + automatic_installation = false, + handlers = { + function(server_name) + local server = servers[server_name] or {} + + server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) + require("lspconfig")[server_name].setup(server) + end, + }, + }) + end, +} diff --git a/lua/nyanko/lazy/lualine.lua b/lua/nyanko/lazy/lualine.lua new file mode 100644 index 0000000..cd745d0 --- /dev/null +++ b/lua/nyanko/lazy/lualine.lua @@ -0,0 +1,25 @@ +return { + "nvim-lualine/lualine.nvim", + config = function() + require("lualine").setup({ + options = { + icons_enabled = false, + component_separators = "|", + section_separators = "", + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { + "filename", + function() + return vim.fn["nvim_treesitter#statusline"](180) + end, + }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + }) + end, +} diff --git a/lua/nyanko/lazy/telescope.lua b/lua/nyanko/lazy/telescope.lua new file mode 100644 index 0000000..3731af8 --- /dev/null +++ b/lua/nyanko/lazy/telescope.lua @@ -0,0 +1,26 @@ +return { + "nvim-telescope/telescope.nvim", + event = "VimEnter", + branch = "0.1.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-ui-select.nvim", + }, + config = function() + require("telescope").setup({ + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown(), + }, + }, + }) + + pcall(require("telescope").load_extension, "ui-select") + + local builtin = require("telescope.builtin") + vim.keymap.set("n", "sf", builtin.find_files, { desc = "[S]earch [F]iles" }) + vim.keymap.set("n", "sg", builtin.live_grep, { desc = "[S]earch by [G]rep" }) + vim.keymap.set("n", "sw", builtin.grep_string, { desc = "[S]earch by current [W]ord" }) + vim.keymap.set("n", "sr", builtin.oldfiles, { desc = "[S]earch [R]ecent files" }) + end, +} diff --git a/lua/nyanko/lazy/todo-comments.lua b/lua/nyanko/lazy/todo-comments.lua new file mode 100644 index 0000000..1a2b3cc --- /dev/null +++ b/lua/nyanko/lazy/todo-comments.lua @@ -0,0 +1,10 @@ +return { + "folke/todo-comments.nvim", + event = "VimEnter", + dependencies = { + "nvim-lua/plenary.nvim", + }, + opts = { + signs = false, + }, +} diff --git a/lua/nyanko/lazy/treesitter.lua b/lua/nyanko/lazy/treesitter.lua new file mode 100644 index 0000000..919bdf5 --- /dev/null +++ b/lua/nyanko/lazy/treesitter.lua @@ -0,0 +1,33 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + main = "nvim-treesitter.configs", + opts = { + ensure_installed = { + "bash", + "c", + "diff", + "html", + "lua", + "luadoc", + "markdown", + "markdown_inline", + "query", + "vim", + "vimdoc", + }, + auto_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = { + "ruby", + }, + }, + indent = { + enable = true, + disable = { + "ruby", + }, + }, + }, +} diff --git a/lua/nyanko/lazy/which-key.lua b/lua/nyanko/lazy/which-key.lua new file mode 100644 index 0000000..bd4cc1c --- /dev/null +++ b/lua/nyanko/lazy/which-key.lua @@ -0,0 +1,12 @@ +return { + "folke/which-key.nvim", + event = "VimEnter", + opts = { + icons = { + mappings = false, + }, + spec = { + { "s", group = "[S]earch" }, + }, + }, +} diff --git a/lua/nyanko/lazy_init.lua b/lua/nyanko/lazy_init.lua new file mode 100644 index 0000000..772fe0b --- /dev/null +++ b/lua/nyanko/lazy_init.lua @@ -0,0 +1,31 @@ +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 = "nyanko.lazy", + install = { colorscheme = { "catppuccin-mocha" } }, + checker = { enabled = true }, + change_detection = { enabled = true, notify = false }, +}) diff --git a/lua/nyanko/opt.lua b/lua/nyanko/opt.lua new file mode 100644 index 0000000..ecd840f --- /dev/null +++ b/lua/nyanko/opt.lua @@ -0,0 +1,37 @@ +-- for brevity +local o = vim.opt + +-- show line numbers +o.number = true + +-- enable mouse mode +o.mouse = "a" + +-- dont show the mode since it's in lualine +o.showmode = false + +-- faster updates +o.updatetime = 100 + +-- tabs +o.autoindent = true +o.smartindent = true +o.expandtab = false +o.tabstop = 4 +o.shiftwidth = 4 + +-- indent wrapped lines of text +o.breakindent = true + +-- save undo history +o.undofile = true + +-- make search case insensitive unless \C or mixed-case is in the search +o.ignorecase = true +o.smartcase = true + +-- keep sign column visible +o.signcolumn = "yes" + +-- show which line the cursor is on +o.cursorline = true