From 2a3ee1c8f696e6f3a9972a05f8b5f8681c244a2e Mon Sep 17 00:00:00 2001 From: philw Date: Sat, 17 Feb 2024 12:42:20 +0100 Subject: Migrate to lazy and coq --- init.lua | 169 +++++++++++++++++++++++++++++++++++++++++++++++-- lua/config/editor.lua | 25 ++------ lua/config/lsp.lua | 114 ++++++++++++++++----------------- lua/config/packer.lua | 57 ----------------- lua/config/plugins.lua | 83 ++++++++++++++++++++++++ 5 files changed, 307 insertions(+), 141 deletions(-) delete mode 100644 lua/config/packer.lua create mode 100644 lua/config/plugins.lua diff --git a/init.lua b/init.lua index 45e6811..87a9b46 100644 --- a/init.lua +++ b/init.lua @@ -1,8 +1,165 @@ ---Open this file if you want to add new plugins -require("config.packer") +-- require("config.lsp") +local option = vim.opt +local keymap = vim.keymap --- Here you can find stuff related to lsp -require("config.lsp") +--Basic Editor Setup +option.nu = true +option.tabstop = 2 +option.softtabstop = 2 +option.shiftwidth = 2 +option.expandtab = true +option.smartindent = true +option.wrap = false +option.swapfile = false +option.hlsearch = false +option.incsearch = true +option.updatetime = 50 +option.laststatus = 0 +option.signcolumn = "number" +option.autoindent = true +option.clipboard = "unnamedplus" +option.termguicolors = true +option.fillchars = 'eob: ' +option.autoindent = true --- And there goes editor customization -require("config.editor") +-- Setup Editor Theme +vim.cmd([[ +highlight GitGutterAdd ctermbg=none +highlight GitGutterAdd guibg=none +highlight NonText guifg=none +highlight EndOfBuffer ctermfg=none ctermbg=none +highlight Normal ctermbg=none +highlight Normal guibg=none +highlight signcolumn ctermbg=none +highlight signcolumn guibg=none +highlight StatusLine ctermbg=none +highlight StatusLine guibg=none +highlight DiagnosticError ctermbg=none +highlight DiagnosticError guibg=none +highlight DiagnosticWarn ctermbg=none +highlight DiagnosticWarn guibg=none +highlight DiagnosticInfo ctermbg=none +highlight DiagnosticInfo guibg=none +highlight DiagnosticHint ctermbg=none +highlight DiagnosticHint guibg=none +highlight Pmenu ctermbg=none guibg=none + +highlight DiagnosticVirtualError ctermbg=none +highlight DiagnosticVirtualError guibg=none +highlight DiagnosticVirtualWarn ctermbg=none +highlight DiagnosticVirtualWarn guibg=none +highlight DiagnosticVirtualInfo ctermbg=none +highlight DiagnosticVirtualInfo guibg=none +highlight DiagnosticVirtualHint ctermbg=none +highlight DiagnosticVirtualHint guibg=none + +highlight DiagnosticVirtualTextError ctermbg=none +highlight DiagnosticVirtualTextError guibg=none +highlight DiagnosticVirtualTextWarn ctermbg=none +highlight DiagnosticVirtualTextWarn guibg=none +highlight DiagnosticVirtualTextInfo ctermbg=none +highlight DiagnosticVirtualTextInfo guibg=none +highlight DiagnosticVirtualTextHint ctermbg=none +highlight DiagnosticVirtualTextHint guibg=none +]]) + +-- run specific commands after different file extensions +vim.cmd([[ +augroup RunPfOnSave +autocmd! +autocmd BufWritePost *.js,*.ts,*.jsx,*json,*.tsx,*.css,*.html,*.yaml,*.md silent! !prettier --write % +autocmd BufWritePost *.tex silent! :VimtexCompile +autocmd BufWritePost *.md silent! :MarkdownPreview +autocmd BufWritePost *.php silent! !php-cs-fixer fix % +augroup END +]]) + +-- Gui options +vim.o.guifont = "Fira Code:h7" +vim.g.vimtex_view_method = "zathura" +vim.g.vimtex_compiler_method = "latexrun" +vim.g.gitgutter_set_sign_backgrounds = 1 + +--Keybinds +vim.g.mapleader = " " +keymap.set("n", "e", vim.cmd.Ex) +keymap.set("n", "s", [[:%s/\<\>//gI]]) +keymap.set("n", "a", "ggVG") +keymap.set("v", "J", ":m '>+1gv=gv") +keymap.set("v", "K", ":m '<-2gv=gv") +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("lazy").setup({ + "nvim-lua/plenary.nvim", + "airblade/vim-gitgutter", + "nvim-treesitter/nvim-treesitter", + "neovim/nvim-lspconfig", + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + 'nvim-telescope/telescope.nvim', + tag = '0.1.5', + dependencies = { 'nvim-lua/plenary.nvim' }, + "windwp/nvim-autopairs", + config = function() + require("nvim-autopairs").setup({}) + end, + { + 'nvim-telescope/telescope-fzf-native.nvim', + build = + 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build', + keys = { + { "/", false }, + { "f", "Telescope find_files", desc = "Find Files" }, + { "g", "Telescope live_grep", desc = "Grep" }, + { "b", "Telescope buffers", desc = "Grep" }, + } + }, + { + 'numToStr/Comment.nvim', + }, + + 'ms-jpq/coq_nvim', + { 'ms-jpq/coq.artifacts', branch = "artifacts" }, +}) + + +vim.api.nvim_create_autocmd('InsertEnter', { + command = 'COQnow --shut-up' +}) +local lsp_servers = { + clangd = {}, + lua_ls = {}, +} +require("mason").setup() +require("mason-lspconfig").setup { + ensure_installed = lsp_servers, + automatic_installation = true, +} + +local server_maps = function(opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) -- goto def + vim.keymap.set("n", "k", vim.lsp.buf.hover, opts) -- see docs + vim.keymap.set("n", "fo", function() -- format + vim.lsp.buf.format({ async = true }) + end, opts) +end + +for lsp, settings in pairs(lsp_servers) do + require("lspconfig")[lsp].setup(coq.lsp_ensure_capabilities({ + on_attach = function(_, buffer) + server_maps({ buffer = buffer }) + end, + settings = settings, + })) +end diff --git a/lua/config/editor.lua b/lua/config/editor.lua index eec0e08..a4ce545 100644 --- a/lua/config/editor.lua +++ b/lua/config/editor.lua @@ -1,10 +1,6 @@ -local js_based_languages = { "typescript", "javascript", "typescriptreact", "javascriptreact" } local option = vim.opt local keymap = vim.keymap -local telescope = require("telescope.builtin") -local autotag = require("nvim-ts-autotag").setup() - --Basic Editor Setup option.nu = true option.tabstop = 2 @@ -21,13 +17,15 @@ option.laststatus = 0 option.signcolumn = "number" option.autoindent = true option.clipboard = "unnamedplus" -option.termguicolors = true +option.termguicolors = false +option.fillchars='eob: ' -- Setup Editor Theme -vim.cmd.colorscheme("tokyonight") vim.cmd([[ highlight GitGutterAdd ctermbg=none highlight GitGutterAdd guibg=none +highlight NonText guifg=none +highlight EndOfBuffer ctermfg=none ctermbg=none highlight Normal ctermbg=none highlight Normal guibg=none highlight signcolumn ctermbg=none @@ -62,7 +60,6 @@ highlight DiagnosticVirtualTextHint ctermbg=none highlight DiagnosticVirtualTextHint guibg=none ]]) - -- run specific commands after different file extensions vim.cmd([[ augroup RunPfOnSave @@ -83,21 +80,7 @@ vim.g.gitgutter_set_sign_backgrounds = 1 --Keybinds vim.g.mapleader = " " keymap.set("n", "e", vim.cmd.Ex) -keymap.set("n", "f", telescope.find_files, {}) -keymap.set("n", "fg", telescope.live_grep, {}) -keymap.set("n", "fb", telescope.buffers, {}) -keymap.set("n", "fh", telescope.help_tags, {}) keymap.set("n", "s", [[:%s/\<\>//gI]]) keymap.set("n", "a", "ggVG") keymap.set("v", "J", ":m '>+1gv=gv") keymap.set("v", "K", ":m '<-2gv=gv") - ---Treesitter -require("nvim-treesitter.configs").setup({ - ensure_installed = { "javascript", "typescript", "rust", "c", "lua", "vim" }, - sync_install = false, - auto_install = true, - highlight = { - enable = true, - }, -}) diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index ca341d5..7fd0ddb 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua @@ -1,64 +1,64 @@ -- local lsp = require('lsp-zero') -local lsp_zero = require("lsp-zero") -local cmp = require("cmp") -require("luasnip.loaders.from_vscode").lazy_load() +--local lsp_zero = require("lsp-zero") +--local cmp = require("cmp") +--require("luasnip.loaders.from_vscode").lazy_load() -lsp_zero.preset("recommended") -lsp_zero.setup() -lsp_zero.on_attach(function(client_id, bufnr) - lsp_zero.default_keymaps({ buffer = bufnr }) -end) +--lsp_zero.preset("recommended") +--lsp_zero.setup() +--lsp_zero.on_attach(function(client_id, bufnr) +-- lsp_zero.default_keymaps({ buffer = bufnr }) +--end) -require("mason").setup({}) -require("mason-lspconfig").setup({ - ensure_installed = { "clangd", "rust_analyzer" }, - handlers = { - lsp_zero.default_setup, - }, -}) +--require("mason").setup({}) +--require("mason-lspconfig").setup({ +-- ensure_installed = { "clangd", "rust_analyzer" }, +-- handlers = { +-- lsp_zero.default_setup, +-- }, +--}) -cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - window = {}, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - }, { - { name = "buffer" }, - }), -}) +--cmp.setup({ +-- snippet = { +-- expand = function(args) +-- require("luasnip").lsp_expand(args.body) +-- end, +-- }, +-- window = {}, +-- mapping = cmp.mapping.preset.insert({ +-- [""] = cmp.mapping.scroll_docs(-4), +-- [""] = cmp.mapping.scroll_docs(4), +-- [""] = cmp.mapping.complete(), +-- [""] = cmp.mapping.abort(), +-- [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. +-- }), +-- sources = cmp.config.sources({ +-- { name = "nvim_lsp" }, +-- { name = "luasnip" }, +-- }, { +-- { name = "buffer" }, +-- }), +--}) -function PrintDiagnostics(opts, bufnr, line_nr, client_id) - bufnr = bufnr or 0 - line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) - opts = opts or { ["lnum"] = line_nr } +--function PrintDiagnostics(opts, bufnr, line_nr, client_id) +-- bufnr = bufnr or 0 +-- line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) +-- opts = opts or { ["lnum"] = line_nr } +-- +-- local line_diagnostics = vim.diagnostic.get(bufnr, opts) +-- if vim.tbl_isempty(line_diagnostics) then +-- return +-- end +-- +-- local diagnostic_message = "" +-- for i, diagnostic in ipairs(line_diagnostics) do +-- diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") +-- print(diagnostic_message) +-- if i ~= #line_diagnostics then +-- diagnostic_message = diagnostic_message .. "\n" +-- end +-- end +-- vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) +--end - local line_diagnostics = vim.diagnostic.get(bufnr, opts) - if vim.tbl_isempty(line_diagnostics) then - return - end - - local diagnostic_message = "" - for i, diagnostic in ipairs(line_diagnostics) do - diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") - print(diagnostic_message) - if i ~= #line_diagnostics then - diagnostic_message = diagnostic_message .. "\n" - end - end - vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) -end - -vim.cmd([[ autocmd! CursorHold * lua PrintDiagnostics() ]]) +--vim.cmd([[ autocmd! CursorHold * lua PrintDiagnostics() ]]) diff --git a/lua/config/packer.lua b/lua/config/packer.lua deleted file mode 100644 index 07a600a..0000000 --- a/lua/config/packer.lua +++ /dev/null @@ -1,57 +0,0 @@ -vim.cmd([[packadd packer.nvim]]) -return require("packer").startup(function(use) - use("wbthomason/packer.nvim") - use("nvim-treesitter/nvim-treesitter") - use("neovim/nvim-lspconfig") - use("lukas-reineke/indent-blankline.nvim") - use("lervag/vimtex") - use("folke/tokyonight.nvim") - use("airblade/vim-gitgutter") - use("jose-elias-alvarez/null-ls.nvim") - use("windwp/nvim-ts-autotag") - use({ - "nvim-telescope/telescope.nvim", - tag = "0.1.4", - requires = { { "nvim-lua/plenary.nvim" } }, - }) - use({ - "VonHeikemen/lsp-zero.nvim", - requires = { - { "neovim/nvim-lspconfig" }, - { "williamboman/mason.nvim" }, - { "williamboman/mason-lspconfig.nvim" }, - { "hrsh7th/nvim-cmp" }, - { "hrsh7th/cmp-buffer" }, - { "hrsh7th/cmp-path" }, - { "saadparwaiz1/cmp_luasnip" }, - { "hrsh7th/cmp-nvim-lsp" }, - { "hrsh7th/cmp-nvim-lua" }, - { "rafamadriz/friendly-snippets" }, - }, - }) - use({ - "L3MON4D3/LuaSnip", - tag = "v2.*", - run = "make install_jsregexp", - }) - use({ - "numToStr/Comment.nvim", - config = function() - require("Comment").setup() - end, - }) - use({ - "iamcco/markdown-preview.nvim", - run = "cd app && npm install", - setup = function() - vim.g.mkdp_filetypes = { "markdown" } - end, - ft = { "markdown" }, - }) - use({ - "windwp/nvim-autopairs", - config = function() - require("nvim-autopairs").setup({}) - end, - }) -end) diff --git a/lua/config/plugins.lua b/lua/config/plugins.lua new file mode 100644 index 0000000..dd09a4d --- /dev/null +++ b/lua/config/plugins.lua @@ -0,0 +1,83 @@ +-- vim.cmd([[packadd packer.nvim]]) +-- return require("packer").startup(function(use) +-- use("neovim/nvim-lspconfig") +-- use("lervag/vimtex") +-- use({ +-- "VonHeikemen/lsp-zero.nvim", +-- requires = { +-- { "neovim/nvim-lspconfig" }, +-- { "williamboman/mason.nvim" }, +-- { "williamboman/mason-lspconfig.nvim" }, +-- { "hrsh7th/nvim-cmp" }, +-- { "hrsh7th/cmp-buffer" }, +-- { "hrsh7th/cmp-path" }, +-- { "saadparwaiz1/cmp_luasnip" }, +-- { "hrsh7th/cmp-nvim-lsp" }, +-- { "hrsh7th/cmp-nvim-lua" }, +-- { "rafamadriz/friendly-snippets" }, +-- }, +-- }) +-- use({ +-- "L3MON4D3/LuaSnip", +-- tag = "v2.*", +-- run = "make install_jsregexp", +-- }) +-- use({ +-- "iamcco/markdown-preview.nvim", +-- run = "cd app && npm install", +-- setup = function() +-- vim.g.mkdp_filetypes = { "markdown" } +-- end, +-- ft = { "markdown" }, +-- }) +-- use({ +-- "windwp/nvim-autopairs", +-- config = function() +-- require("nvim-autopairs").setup({}) +-- end, +-- }) +-- end) + +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("lazy").setup({ + "nvim-lua/plenary.nvim", + "airblade/vim-gitgutter", + "nvim-treesitter/nvim-treesitter", + "neovim/nvim-lspconfig", + 'nvim-telescope/telescope.nvim', tag = '0.1.5', + dependencies = { 'nvim-lua/plenary.nvim' }, + "windwp/nvim-autopairs", + config = function() + require("nvim-autopairs").setup({}) + end, + { 'nvim-telescope/telescope-fzf-native.nvim', + build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build', + keys= { + {"/", false}, + { "f", "Telescope find_files", desc = "Find Files" }, + { "g", "Telescope live_grep", desc = "Grep" }, + { "b", "Telescope buffers", desc = "Grep" }, + } +}, +{ + 'numToStr/Comment.nvim', + lazy = false, +}, + +{ + "ms-jpq/coq_nvim", +}, +}) + -- cgit v1.2.3