From bb242e11c87ccc8165fedb2f3ecd18b5e4b822c9 Mon Sep 17 00:00:00 2001 From: Sakooooo <78461130+Sakooooo@users.noreply.github.com> Date: Mon, 3 Jul 2023 02:27:02 +0400 Subject: [PATCH] we import neovim config from there yea yea --- config/neovim/README.md | 3 + config/neovim/init.lua | 3 + config/neovim/lua/core/keymaps.lua | 54 +++++++++++++ .../lua/core/plugin_config/autopairs.lua | 17 ++++ .../lua/core/plugin_config/cmp_config.lua | 27 +++++++ .../lua/core/plugin_config/gitsigns.lua | 3 + config/neovim/lua/core/plugin_config/init.lua | 12 +++ .../lua/core/plugin_config/kanagawa.lua | 30 +++++++ .../lua/core/plugin_config/liveserver.lua | 12 +++ .../lua/core/plugin_config/lsp_config.lua | 79 ++++++++++++++++++ .../neovim/lua/core/plugin_config/lualine.lua | 14 ++++ .../neovim/lua/core/plugin_config/null_ls.lua | 28 +++++++ .../lua/core/plugin_config/nvim-tree.lua | 4 + .../lua/core/plugin_config/precense.lua | 22 +++++ .../lua/core/plugin_config/telescope.lua | 6 ++ .../lua/core/plugin_config/treesitter.lua | 18 +++++ config/neovim/lua/core/plugins.lua | 81 +++++++++++++++++++ configuration.nix | 13 ++- 18 files changed, 422 insertions(+), 4 deletions(-) create mode 100644 config/neovim/README.md create mode 100644 config/neovim/lua/core/keymaps.lua create mode 100644 config/neovim/lua/core/plugin_config/autopairs.lua create mode 100644 config/neovim/lua/core/plugin_config/cmp_config.lua create mode 100644 config/neovim/lua/core/plugin_config/gitsigns.lua create mode 100644 config/neovim/lua/core/plugin_config/init.lua create mode 100644 config/neovim/lua/core/plugin_config/kanagawa.lua create mode 100644 config/neovim/lua/core/plugin_config/liveserver.lua create mode 100644 config/neovim/lua/core/plugin_config/lsp_config.lua create mode 100644 config/neovim/lua/core/plugin_config/lualine.lua create mode 100644 config/neovim/lua/core/plugin_config/null_ls.lua create mode 100644 config/neovim/lua/core/plugin_config/nvim-tree.lua create mode 100644 config/neovim/lua/core/plugin_config/precense.lua create mode 100644 config/neovim/lua/core/plugin_config/telescope.lua create mode 100644 config/neovim/lua/core/plugin_config/treesitter.lua create mode 100644 config/neovim/lua/core/plugins.lua diff --git a/config/neovim/README.md b/config/neovim/README.md new file mode 100644 index 00000000..eb12d042 --- /dev/null +++ b/config/neovim/README.md @@ -0,0 +1,3 @@ +# Neovim Config +## This used to be Sakooooo/nvimconf +but now its in Sakooooo/nixos diff --git a/config/neovim/init.lua b/config/neovim/init.lua index e69de29b..819f7ab2 100644 --- a/config/neovim/init.lua +++ b/config/neovim/init.lua @@ -0,0 +1,3 @@ +require("core.keymaps") +require("core.plugins") +require("core.plugin_config") diff --git a/config/neovim/lua/core/keymaps.lua b/config/neovim/lua/core/keymaps.lua new file mode 100644 index 00000000..d6533a16 --- /dev/null +++ b/config/neovim/lua/core/keymaps.lua @@ -0,0 +1,54 @@ +local opts = { noremap = true, silent = true } + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +vim.opt.backspace = "2" +vim.opt.showcmd = true +vim.opt.laststatus = 2 +vim.opt.autowrite = true +vim.opt.cursorline = true +vim.opt.autoread = true + +-- spaces for tabs +vim.opt.tabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.shiftround = true +vim.opt.expandtab = true + +-- split position +vim.opt.splitbelow = true +vim.opt.splitright = true + +-- :terminal shell +if (vim.loop.os_uname().sysname == "Linux") +then + vim.opt.shell = "bash" +else + vim.opt.shell = "pwsh" +end + +-- nvimtree +vim.keymap.set("n", "e", ":NvimTreeFindFileToggle", opts) + +-- splits +vim.keymap.set("n", "", ":wincmd k", opts) +vim.keymap.set("n", "", ":wincmd j", opts) +vim.keymap.set("n", "", ":wincmd h", opts) +vim.keymap.set("n", "", ":wincmd l", opts) + +-- resize split +vim.keymap.set("n", "", ":vertical resize +1", opts) +vim.keymap.set("n", "", ":vertical resize -1", opts) +vim.keymap.set("n", "", ":resize -1", opts) +vim.keymap.set("n", "", ":resize +1", opts) + +-- make split +vim.keymap.set("n", "nsv", ":vsplit", opts) +vim.keymap.set("n", "nsh", ":split", opts) + +-- terminal +vim.keymap.set("n", "t", ":split :terminal") + +-- exit terminal with esc +vim.keymap.set("t", "", "", opts) diff --git a/config/neovim/lua/core/plugin_config/autopairs.lua b/config/neovim/lua/core/plugin_config/autopairs.lua new file mode 100644 index 00000000..15d9698d --- /dev/null +++ b/config/neovim/lua/core/plugin_config/autopairs.lua @@ -0,0 +1,17 @@ +local autopairs_setup, autopairs = pcall(require, "nvim-autopairs") + +autopairs.setup({ + check_ts = true, + ts_config = { + lua = {'string'},-- it will not add a pair on that treesitter node + javascript = {'template_string'}, + java = false,-- don't check treesitter on java + } +}) + +local cmp_autopairs = require('nvim-autopairs.completion.cmp') +local cmp = require('cmp') +cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done() +) diff --git a/config/neovim/lua/core/plugin_config/cmp_config.lua b/config/neovim/lua/core/plugin_config/cmp_config.lua new file mode 100644 index 00000000..bc3e242f --- /dev/null +++ b/config/neovim/lua/core/plugin_config/cmp_config.lua @@ -0,0 +1,27 @@ +local cmp = require'cmp' + +cmp.setup({ + snippet= { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_prev_item(), -- previous suggestion + [""] = cmp.mapping.select_next_item(), -- next suggestion + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), -- show completion suggestions + [""] = cmp.mapping.abort(), -- close completion window + [""] = cmp.mapping.confirm({ select = false }), + }), + + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = 'luasnip' }, + { name = "buffer" }, + { name = "path" }, + }) +}) + + diff --git a/config/neovim/lua/core/plugin_config/gitsigns.lua b/config/neovim/lua/core/plugin_config/gitsigns.lua new file mode 100644 index 00000000..a238e525 --- /dev/null +++ b/config/neovim/lua/core/plugin_config/gitsigns.lua @@ -0,0 +1,3 @@ +local gitsigns = require("gitsigns") + +gitsigns.setup() diff --git a/config/neovim/lua/core/plugin_config/init.lua b/config/neovim/lua/core/plugin_config/init.lua new file mode 100644 index 00000000..7e536de2 --- /dev/null +++ b/config/neovim/lua/core/plugin_config/init.lua @@ -0,0 +1,12 @@ +require("core.plugin_config.lualine") +require("core.plugin_config.nvim-tree") +require("core.plugin_config.telescope") +require("core.plugin_config.treesitter") +require("core.plugin_config.lsp_config") +require("core.plugin_config.cmp_config") +require("core.plugin_config.autopairs") +require("core.plugin_config.gitsigns") +require("core.plugin_config.precense") +require("core.plugin_config.null_ls") +require("core.plugin_config.kanagawa") +require("core.plugin_config.liveserver") diff --git a/config/neovim/lua/core/plugin_config/kanagawa.lua b/config/neovim/lua/core/plugin_config/kanagawa.lua new file mode 100644 index 00000000..33b27d3b --- /dev/null +++ b/config/neovim/lua/core/plugin_config/kanagawa.lua @@ -0,0 +1,30 @@ +-- Default options: +require("kanagawa").setup({ + compile = false, -- enable compiling the colorscheme + undercurl = true, -- enable undercurls + commentStyle = { italic = true }, + functionStyle = {}, + keywordStyle = { italic = true }, + statementStyle = { bold = true }, + typeStyle = {}, + transparent = false, -- do not set background color + dimInactive = false, -- dim inactive window `:h hl-NormalNC` + terminalColors = true, -- define vim.g.terminal_color_{0,17} + colors = { + -- add/modify theme and palette colors + palette = {}, + theme = { wave = {}, lotus = {}, dragon = {}, all = {} }, + }, + overrides = function(colors) -- add/modify highlights + return {} + end, + theme = "dragon", -- Load "wave" theme when 'background' option is not set + background = { + -- map the value of 'background' option to a theme + dark = "dragon", -- try "dragon" ! + light = "lotus", + }, +}) + +-- setup must be called before loading +vim.cmd("colorscheme kanagawa") diff --git a/config/neovim/lua/core/plugin_config/liveserver.lua b/config/neovim/lua/core/plugin_config/liveserver.lua new file mode 100644 index 00000000..e1902701 --- /dev/null +++ b/config/neovim/lua/core/plugin_config/liveserver.lua @@ -0,0 +1,12 @@ +local status_ok, live_server = pcall(require, "live_server") +if not status_ok then + return +end + +live_server.setup({ + port = 8080, + browser_command = "", -- Empty string starts up with default browser + quiet = false, + no_css_inject = false, -- Disables css injection if true, might be useful when testing out tailwindcss + install_path = vim.fn.stdpath("config") .. "/live-server/", +}) diff --git a/config/neovim/lua/core/plugin_config/lsp_config.lua b/config/neovim/lua/core/plugin_config/lsp_config.lua new file mode 100644 index 00000000..0903b9cf --- /dev/null +++ b/config/neovim/lua/core/plugin_config/lsp_config.lua @@ -0,0 +1,79 @@ +require("cmp") +require("mason").setup() +require("mason-lspconfig").setup({ + ensure_installed = { "lua_ls", "omnisharp", "pyright", "clangd" }, +}) +local mason_null_ls = require("mason-null-ls") + +-- vscode +local on_attach = function(client, bufnr) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, {}) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, {}) + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, {}) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {}) + vim.keymap.set("n", "gr", require("telescope.builtin").lsp_references, {}) + vim.keymap.set("n", "K", vim.lsp.buf.hover, {}) +end + +-- enable autocomplete +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +--format thing +mason_null_ls.setup({ + ensure_installed = { + "stylua", + "csharpier", + "prettier", + }, +}) + +-- funny lsp config stuff +require("lspconfig").lua_ls.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").omnisharp.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").cmake.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").clangd.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").tsserver.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").html.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").eslint.setup({ + on_attach = function(client, bufnr) + vim.api.nvim_create_autocmd("BufWritePre", { + buffer = bufnr, + command = "EslintFixAll", + }) + end, +}) + +require("lspconfig").pyright.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) + +require("lspconfig").cssls.setup({ + on_attach = on_attach, + capabilities = capabilities, +}) diff --git a/config/neovim/lua/core/plugin_config/lualine.lua b/config/neovim/lua/core/plugin_config/lualine.lua new file mode 100644 index 00000000..89f386f8 --- /dev/null +++ b/config/neovim/lua/core/plugin_config/lualine.lua @@ -0,0 +1,14 @@ +require("lualine").setup({ + options = { + icons_enabled = true, + theme = "kanagawa", + }, + sections = { + lualine_a = { + { + "filename", + path = 1, + }, + }, + }, +}) diff --git a/config/neovim/lua/core/plugin_config/null_ls.lua b/config/neovim/lua/core/plugin_config/null_ls.lua new file mode 100644 index 00000000..1335db9d --- /dev/null +++ b/config/neovim/lua/core/plugin_config/null_ls.lua @@ -0,0 +1,28 @@ +local null_ls = require("null-ls") + +local formatting = null_ls.builtins.formatting +local diagnostics = null_ls.builtins.diagnostics + +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +null_ls.setup({ + sources = { + formatting.prettier, + formatting.stylua, + formatting.csharpier, + formatting.clang_format, + diagnostics.cpplint, + }, + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ buffer }) + end, + }) + end + end, +}) diff --git a/config/neovim/lua/core/plugin_config/nvim-tree.lua b/config/neovim/lua/core/plugin_config/nvim-tree.lua new file mode 100644 index 00000000..d5350e5f --- /dev/null +++ b/config/neovim/lua/core/plugin_config/nvim-tree.lua @@ -0,0 +1,4 @@ +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +require("nvim-tree").setup() diff --git a/config/neovim/lua/core/plugin_config/precense.lua b/config/neovim/lua/core/plugin_config/precense.lua new file mode 100644 index 00000000..a528e2f6 --- /dev/null +++ b/config/neovim/lua/core/plugin_config/precense.lua @@ -0,0 +1,22 @@ +require("presence").setup({ + -- options + auto_update = true, + neovim_image_text = "mama mia", + main_image = "neovim", + client_id = "793271441293967371", + log_level = nil, + debounce_timeout = 10, + enable_line_number = false, + blacklist = {}, + file_assets = {}, + show_time = true, + + -- the text + editing_text = "editing %s", + file_explorer_text = "file explorer", + git_commit_text = "git comit", + plugin_manager_text = "adding bloatware", + reading_text = "reading %s", + workspace_text = "workspace: %s", + line_number_text = "line %s out of %s", +}) diff --git a/config/neovim/lua/core/plugin_config/telescope.lua b/config/neovim/lua/core/plugin_config/telescope.lua new file mode 100644 index 00000000..383fb15a --- /dev/null +++ b/config/neovim/lua/core/plugin_config/telescope.lua @@ -0,0 +1,6 @@ +local builtin = require('telescope.builtin') + +vim.keymap.set('n', '', builtin.find_files, {}) +vim.keymap.set('n', '', builtin.oldfiles, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'fh', builtin.help_tags, {}) diff --git a/config/neovim/lua/core/plugin_config/treesitter.lua b/config/neovim/lua/core/plugin_config/treesitter.lua new file mode 100644 index 00000000..79b4871c --- /dev/null +++ b/config/neovim/lua/core/plugin_config/treesitter.lua @@ -0,0 +1,18 @@ +require'nvim-treesitter.configs'.setup{ + -- A list of parser names, or "all" + -- TODO: figure this out + ensure_installed = {"c", + "cpp", + "c_sharp", + "lua", + "python", + "vim"}, + + -- Install parsers synchronously (only applied to 'ensure_installed) + sync_install = false, + auto_install = true, + highlight = { + enable = true, + }, + indent = { enable = true } +} diff --git a/config/neovim/lua/core/plugins.lua b/config/neovim/lua/core/plugins.lua new file mode 100644 index 00000000..b80a292b --- /dev/null +++ b/config/neovim/lua/core/plugins.lua @@ -0,0 +1,81 @@ +local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }) + vim.cmd([[packadd packer.nvim]]) + return true + end + return false +end + +local packer_bootstrap = ensure_packer() + +-- plugins go here +return require("packer").startup(function(use) + -- the package manager + use("wbthomason/packer.nvim") + + -- whats an ide without a file explorer + use("nvim-tree/nvim-tree.lua") + use("nvim-tree/nvim-web-devicons") + + -- default bar only looks good on linux + use("nvim-lualine/lualine.nvim") + + -- colorschemes + use("rebelot/kanagawa.nvim") + + -- syntax highlighting apparently + use("nvim-treesitter/nvim-treesitter") + + -- like fzf but goofier + use({ + "nvim-telescope/telescope.nvim", + tag = "0.1.1", + requires = { { "nvim-lua/plenary.nvim" } }, + }) + -- lsp stuff + use({ + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "neovim/nvim-lspconfig", + }) + -- le completion + use("hrsh7th/nvim-cmp") + use("hrsh7th/cmp-buffer") + use("hrsh7th/cmp-path") + use("hrsh7th/cmp-nvim-lsp") + use("onsails/lspkind.nvim") + + -- snippet + use("L3MON4D3/LuaSnip") + use("saadparwaiz1/cmp_luasnip") + + -- auto close to prevent carpal tunnel :) + use("windwp/nvim-autopairs") + + -- git stuff lol + use("lewis6991/gitsigns.nvim") + + -- linting + use("jose-elias-alvarez/null-ls.nvim") + use("jayp0521/mason-null-ls.nvim") + + -- flex + use("andweeb/presence.nvim") + + -- live server + use({ + "aurum77/live-server.nvim", + run = function() + require("live_server.util").install() + end, + cmd = { "LiveServer", "LiveServerStart", "LiveServerStop" }, + }) + + -- auto update just like vscode + if packer_bootstrap then + require("packer").sync() + end +end) diff --git a/configuration.nix b/configuration.nix index 45d15dd6..087a9967 100644 --- a/configuration.nix +++ b/configuration.nix @@ -140,6 +140,8 @@ lutris discord networkmanagerapplet + gcc + python3 ]; }; @@ -158,10 +160,13 @@ userName = "Sakooooo"; userEmail = "78461130+Sakooooo@users.noreply.github.com"; }; - programs.neovim = { - enable = true; - extraConfig = builtins.readFile config/neovim/init.lua; - }; + xdg.configFile = { + nvim = { + source = config/neovim; + recursive = true; + }; + + }; };