From 641621a88ae4aec9a3c4bf8943169490c375a914 Mon Sep 17 00:00:00 2001 From: sadanslargehole Date: Tue, 12 Mar 2024 01:28:22 -0400 Subject: [PATCH] theres still more to do --- init.lua | 17 ++++++++ lua/keymap.lua | 31 ++++++++++++++ lua/plugins.lua | 89 ++++++++++++++++++++++++++++++++++++++++ lua/sets.lua | 9 ++++ lua/setup.lua | 18 ++++++++ lua/setupcomment.lua | 8 ++++ lua/setupformat.lua | 66 ++++++++++++++++++++++++++++++ lua/setuplsp.lua | 91 +++++++++++++++++++++++++++++++++++++++++ lua/setuptabout.lua | 21 ++++++++++ lua/setuptree.lua | 21 ++++++++++ lua/setuptreesitter.lua | 25 +++++++++++ lua/setupufo.lua | 16 ++++++++ lua/themesetup.lua | 35 ++++++++++++++++ 13 files changed, 447 insertions(+) create mode 100644 init.lua create mode 100644 lua/keymap.lua create mode 100644 lua/plugins.lua create mode 100644 lua/sets.lua create mode 100644 lua/setup.lua create mode 100644 lua/setupcomment.lua create mode 100644 lua/setupformat.lua create mode 100644 lua/setuplsp.lua create mode 100644 lua/setuptabout.lua create mode 100644 lua/setuptree.lua create mode 100644 lua/setuptreesitter.lua create mode 100644 lua/setupufo.lua create mode 100644 lua/themesetup.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..53c82a8 --- /dev/null +++ b/init.lua @@ -0,0 +1,17 @@ +vim.g.mapleader = " " +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"plugins" +require"setup" +require"keymap" +require"sets" diff --git a/lua/keymap.lua b/lua/keymap.lua new file mode 100644 index 0000000..5f9bad4 --- /dev/null +++ b/lua/keymap.lua @@ -0,0 +1,31 @@ +local tb = require("telescope.builtin") +-- find Files +vim.keymap.set("n", "f", tb.find_files, {}) +-- find Text +vim.keymap.set("n", "t", tb.live_grep, {}) +-- find Buffers +vim.keymap.set("n", "b", tb.buffers, {}) +-- find keyMaps +vim.keymap.set("n", "m", tb.keymaps, {}) +-- find Command +vim.keymap.set("n", "c", tb.commands, {}) +-- find Documentation +vim.keymap.set("n", "d", tb.man_pages, {}) +-- open tree +vim.keymap.set({ "i", "n" }, "", vim.cmd.NvimTreeFocus, {}) +-- move and copy lines +vim.keymap.set({ "i", "n" }, "", function()vim.api.nvim_feedkeys("ddkP", "x", false)end, {}) +vim.keymap.set({ "i", "n" }, "", function()vim.api.nvim_feedkeys("ddp", "x", false)end, {}) +vim.keymap.set({ "i", "n" }, "", function()vim.api.nvim_feedkeys("yyP", "x", false)end, {}) +vim.keymap.set({ "i", "n" }, "", function()vim.api.nvim_feedkeys("yyp", "x", false)end, {}) +-- on in normal, insert and start autoComp +vim.keymap.set("n", "", function() + vim.api.nvim_feedkeys("i", "m", false) + local key1 = vim.api.nvim_replace_termcodes("", true, false, true) + vim.api.nvim_feedkeys(key1, "m", false) +end, {}) +vim.keymap.set({ "n", "i" }, "", vim.cmd.Format, {}) +vim.keymap.set({ "i", "n" }, "", vim.cmd.vsplit, {}) +-- vscode fold and unfold +vim.keymap.set("n", "","zc", {}) +vim.keymap.set("n", "", "zo", {}) diff --git a/lua/plugins.lua b/lua/plugins.lua new file mode 100644 index 0000000..d3066e1 --- /dev/null +++ b/lua/plugins.lua @@ -0,0 +1,89 @@ +local plugins = { + { + "williamboman/mason.nvim", + }, + { + "williamboman/mason-lspconfig.nvim", + }, + { + "neovim/nvim-lspconfig", + }, + { + "folke/trouble.nvim", + dependencies = { "nvim-tree/nvim-web-devicons" }, + opts = {}, + }, + { + "abecodes/tabout.nvim", + lazy = false, + requires = { + "nvim-treesitter/nvim-treesitter", + "L3MON4D3/LuaSnip", + "hrsh7th/nvim-cmp", + }, + event = "InsertCharPre", -- Set the event to 'InsertCharPre' for better compatibility + priority = 1000, + }, + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + }, + { + "numToStr/Comment.nvim", + opts = { + -- add any options here + }, + lazy = false, + }, + + { + "windwp/nvim-autopairs", + event = "InsertEnter", + config = true, + -- use opts = {} for passing setup options + -- this is equalent to setup({}) function + opts = {}, + }, + { + "folke/tokyonight.nvim", + lazy = false, + priority = 1000, + opts = {}, + }, + { + "mhartington/formatter.nvim", + }, + { + "nvim-telescope/telescope.nvim", + tag = "0.1.5", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + { + "hrsh7th/cmp-nvim-lsp", + }, + { + "hrsh7th/nvim-cmp", + }, + { + "L3MON4D3/LuaSnip", + -- follow latest release. + version = "v2.*", -- Replace by the latest released major (first number of latest release) + -- install jsregexp (optional!). + build = "make install_jsregexp", + }, + { + "saadparwaiz1/cmp_luasnip", + }, + { + "nvim-tree/nvim-tree.lua", + }, + { + "kevinhwang91/nvim-ufo", + dependencies = { "kevinhwang91/promise-async" }, + }, + --{ + -- 'mfussenegger/nvim-lint' + --}, +} +local opts = {} +require("lazy").setup(plugins, opts) diff --git a/lua/sets.lua b/lua/sets.lua new file mode 100644 index 0000000..bf1c00a --- /dev/null +++ b/lua/sets.lua @@ -0,0 +1,9 @@ +vim.opt.rnu = true +vim.opt.expandtab = true +vim.opt.tabstop = 4 +vim.opt.smarttab = true +vim.opt.shiftround = true +vim.opt.shiftwidth = 4 +vim.opt.smartcase = true +vim.opt.ignorecase = true +vim.opt.scrolloff = 4 diff --git a/lua/setup.lua b/lua/setup.lua new file mode 100644 index 0000000..f72e588 --- /dev/null +++ b/lua/setup.lua @@ -0,0 +1,18 @@ +require("themesetup") +vim.cmd([[colorscheme tokyonight]]) + +require("mason").setup() +require("mason-lspconfig").setup() + +require("setuplsp") + +require("setupformat") + +require("setuptree") +require("setuptreesitter") +-- Has to be setup after treesitter +require("setuptabout") + +require("setupufo") + +require("setupcomment") diff --git a/lua/setupcomment.lua b/lua/setupcomment.lua new file mode 100644 index 0000000..64f2a98 --- /dev/null +++ b/lua/setupcomment.lua @@ -0,0 +1,8 @@ +require("Comment").setup({ + toggler = { + line = "", + }, + opleader = { + line = "", + }, +}) diff --git a/lua/setupformat.lua b/lua/setupformat.lua new file mode 100644 index 0000000..495228b --- /dev/null +++ b/lua/setupformat.lua @@ -0,0 +1,66 @@ +-- BY LANG +-- https://github.com/mhartington/formatter.nvim/tree/master/lua/formatter/filetypes +-- Utilities for creating configurations +local util = require("formatter.util") + +-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands +require("formatter").setup({ + -- Enable or disable logging + logging = true, + -- Set the log level + log_level = vim.log.levels.WARN, + -- All formatter configurations are opt-in + filetype = { + -- Formatter configurations for filetype "lua" go here + -- and will be executed in order + kotlin = { + require("formatter.filetypes.kotlin").ktlint, + function() + return { + exe = "ktlint", + args = { + "--stdin", + "--format", + "--log-level=none", + }, + stdin = true, + } + end, + }, + lua = { + -- "formatter.filetypes.lua" defines default configurations for the + -- "lua" filetype + require("formatter.filetypes.lua").stylua, + + -- You can also define your own configuration + function() + -- Supports conditional formatting + if util.get_current_buffer_file_name() == "special.lua" then + return nil + end + + -- Full specification of configurations is down below and in Vim help + -- files + return { + exe = "stylua", + args = { + "--search-parent-directories", + "--stdin-filepath", + util.escape_path(util.get_current_buffer_file_path()), + "--", + "-", + }, + stdin = true, + } + end, + }, + + -- Use the special "*" filetype for defining formatter configurations on + -- any filetype + ["*"] = { + -- "formatter.filetypes.any" defines default configurations for any + -- filetype + require("formatter.filetypes.any").remove_trailing_whitespace, + }, + }, +}) diff --git a/lua/setuplsp.lua b/lua/setuplsp.lua new file mode 100644 index 0000000..941c39e --- /dev/null +++ b/lua/setuplsp.lua @@ -0,0 +1,91 @@ +-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +capabilities.textDocument.foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true, +} +-- +require("lspconfig").kotlin_language_server.setup({ + capabilities = capabilities, +}) +--Java +require("lspconfig").java_language_server.setup({ + capabilities = capabilities, +}) +--Lua +require("lspconfig").lua_ls.setup({ + capabilities = capabilities, + on_init = function(client) + local path = client.workspace_folders[1].name + if vim.loop.fs_stat(path .. "/.luarc.json") or vim.loop.fs_stat(path .. "/.luarc.jsonc") then + return + end + + client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + -- Make the server aware of Neovim runtime files + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME, + -- Depending on the usage, you might want to add additional paths here. + -- "${3rd}/luv/library" + -- "${3rd}/busted/library", + }, + -- or pull in all of 'runtimepath'. NOTE: this is a lot slower + -- library = vim.api.nvim_get_runtime_file("", true) + }, + }) + end, + settings = { + Lua = {}, + }, +}) + +local luasnip = require("luasnip") + +local cmp = require("cmp") +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + -- [''] = cmp.mapping.scroll_docs(-4), -- Up + -- [''] = cmp.mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = cmp.mapping.complete(), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = 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" }), + }), + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, +}) diff --git a/lua/setuptabout.lua b/lua/setuptabout.lua new file mode 100644 index 0000000..7003e9d --- /dev/null +++ b/lua/setuptabout.lua @@ -0,0 +1,21 @@ +require("tabout").setup({ + tabkey = "", -- key to trigger tabout, set to an empty string to disable + backwards_tabkey = "", -- key to trigger backwards tabout, set to an empty string to disable + act_as_tab = true, -- shift content if tab out is not possible + act_as_shift_tab = false, -- reverse shift content if tab out is not possible (if your keyboard/terminal supports ) + default_tab = "", -- shift default action (only at the beginning of a line, otherwise is used) + default_shift_tab = "", -- reverse shift default action, + enable_backwards = true, -- well ... + completion = false, -- if the tabkey is used in a completion pum + tabouts = { + { open = "'", close = "'" }, + { open = '"', close = '"' }, + { open = "`", close = "`" }, + { open = "(", close = ")" }, + { open = "[", close = "]" }, + { open = "{", close = "}" }, + { open = "{", close = "}" }, + }, + ignore_beginning = true, --[[ if the cursor is at the beginning of a filled element it will rather tab out than shift the content ]] + exclude = {}, -- tabout will ignore these filetypes +}) diff --git a/lua/setuptree.lua b/lua/setuptree.lua new file mode 100644 index 0000000..8221745 --- /dev/null +++ b/lua/setuptree.lua @@ -0,0 +1,21 @@ +-- disable netrw at the very start of your init.lua +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +-- optionally enable 24-bit colour +vim.opt.termguicolors = true + +local function myOnAttach(bufnr) + local api = require("nvim-tree.api") + + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + -- defaults + api.config.mappings.default_on_attach(bufnr) + vim.keymap.set("n", "", api.tree.close, opts("close tree with ctrl+t")) +end +-- OR setup with some options +require("nvim-tree").setup({ + on_attach = myOnAttach, +}) diff --git a/lua/setuptreesitter.lua b/lua/setuptreesitter.lua new file mode 100644 index 0000000..201bc1c --- /dev/null +++ b/lua/setuptreesitter.lua @@ -0,0 +1,25 @@ +require("nvim-treesitter.configs").setup({ + -- A list of parser names, or "all" + ensure_installed = "all", + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + + highlight = { + -- `false` will disable the whole extension + enable = true, + + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + indent = { + enable = true, + }, +}) diff --git a/lua/setupufo.lua b/lua/setupufo.lua new file mode 100644 index 0000000..c6a60be --- /dev/null +++ b/lua/setupufo.lua @@ -0,0 +1,16 @@ +vim.o.foldcolumn = "1" -- '0' is not bad +vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value +vim.o.foldlevelstart = 99 +vim.o.foldenable = true + +-- Using ufo provider need remap `zR` and `zM`. If Neovim is 0.6.1, remap yourself +vim.keymap.set("n", "zR", require("ufo").openAllFolds) +vim.keymap.set("n", "zM", require("ufo").closeAllFolds) + +-- Option 2: nvim lsp as LSP client +-- Tell the server the capability of foldingRange, +-- Neovim hasn't added foldingRange to default capabilities, users must add it manually +-- in setuplsp.lua +require("ufo").setup() +-- + diff --git a/lua/themesetup.lua b/lua/themesetup.lua new file mode 100644 index 0000000..de3a3c2 --- /dev/null +++ b/lua/themesetup.lua @@ -0,0 +1,35 @@ +require("tokyonight").setup({ + -- your configuration comes here + -- or leave it empty to use the default settings + style = "storm", -- The theme comes in three styles, `storm`, `moon`, a darker variant `night` and `day` + light_style = "day", -- The theme is used when the background is set to light + transparent = true, -- Enable this to disable setting the background color + terminal_colors = true, -- Configure the colors used when opening a `:terminal` in [Neovim](https://github.com/neovim/neovim) + styles = { + -- Style to be applied to different syntax groups + -- Value is any valid attr-list value for `:help nvim_set_hl` + comments = { italic = true }, + keywords = { italic = true }, + functions = {}, + variables = {}, + -- Background styles. Can be "dark", "transparent" or "normal" + sidebars = "dark", -- style for sidebars, see below + floats = "dark", -- style for floating windows + }, + sidebars = { "qf", "help" }, -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` + day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors + hide_inactive_statusline = false, -- Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**. + dim_inactive = false, -- dims inactive windows + lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold + + --- You can override specific color groups to use other groups or a hex color + --- function will be called with a ColorScheme table + ---@param colors ColorScheme + on_colors = function(colors) end, + + --- You can override specific highlights to use other groups or a hex color + --- function will be called with a Highlights and ColorScheme table + ---@param highlights Highlights + ---@param colors ColorScheme + on_highlights = function(highlights, colors) end, +})