From 3516e2ed0ee32a3e9287e34ed1dbb4064ee1f34b Mon Sep 17 00:00:00 2001 From: leafee98 Date: Sun, 21 May 2023 22:02:07 +0800 Subject: [PATCH] switch to lazy.nvim, refactor plugins, to pure lua --- .gitignore | 1 + init.lua | 40 +++++++++++++ init.vim | 102 -------------------------------- lua/plugins/10-editor.lua | 80 +++++++++++++++++++++++++ lua/plugins/50-lsp.lua | 100 +++++++++++++++++++++++++++++++ lua/plugins/50-treesitter.lua | 49 +++++++++++++++ plugins.d/github-nvim-theme.vim | 3 - plugins.d/indent-blankline.vim | 9 --- plugins.d/jupyter-vim.vim | 37 ------------ plugins.d/lualine.vim | 3 - plugins.d/nvim-lspconfig.vim | 59 ------------------ plugins.d/nvim-tree.vim | 27 --------- plugins.d/toggleterm.vim | 13 ---- plugins.d/vim-buftabline.vim | 3 - 14 files changed, 270 insertions(+), 256 deletions(-) create mode 100644 .gitignore create mode 100644 init.lua delete mode 100644 init.vim create mode 100644 lua/plugins/10-editor.lua create mode 100644 lua/plugins/50-lsp.lua create mode 100644 lua/plugins/50-treesitter.lua delete mode 100644 plugins.d/github-nvim-theme.vim delete mode 100644 plugins.d/indent-blankline.vim delete mode 100644 plugins.d/jupyter-vim.vim delete mode 100644 plugins.d/lualine.vim delete mode 100644 plugins.d/nvim-lspconfig.vim delete mode 100644 plugins.d/nvim-tree.vim delete mode 100644 plugins.d/toggleterm.vim delete mode 100644 plugins.d/vim-buftabline.vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2ccb21 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/lazy-lock.json diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..515adf9 --- /dev/null +++ b/init.lua @@ -0,0 +1,40 @@ +vim.o.tabstop = 4 +vim.o.shiftwidth = 0 +vim.o.softtabstop = -1 +vim.o.shiftround = true + +vim.o.list = true +vim.o.relativenumber = true +vim.o.number = true + +vim.o.expandtab = true +vim.o.autoindent = true +vim.o.smartindent = true + +vim.keymap.set("n", "", "wincmd q", { silent = true }) +vim.keymap.set("n", "", "wincmd h", { silent = true }) +vim.keymap.set("n", "", "wincmd j", { silent = true }) +vim.keymap.set("n", "", "wincmd k", { silent = true }) +vim.keymap.set("n", "", "wincmd l", { silent = true }) + +vim.keymap.set("n", "", "bprevious", { silent = true }) +vim.keymap.set("n", "", "bnext", { silent = true }) +vim.keymap.set("n", "", "bdelete", { silent = true }) + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Use lazy.nvim as plugin manager, and load plugin's config +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("plugins") diff --git a/init.vim b/init.vim deleted file mode 100644 index 6e0665e..0000000 --- a/init.vim +++ /dev/null @@ -1,102 +0,0 @@ -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" my custom settings -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -" tabstop: length of an actual \t character: -" shiftwidth: length to use when shifting text (eg. <<, >> and == commands), (0 for ‘tabstop’): -" softtabstop: length to use when editing text (eg. TAB and BS keys), (0 for ‘tabstop’, -1 for ‘shiftwidth’): -" shiftround: round indentation to multiples of 'shiftwidth' when shifting text (so that it behaves like Ctrl-D / Ctrl-T): -set tabstop=4 -set shiftwidth=0 -set softtabstop=-1 -set shiftround - -set list -set relativenumber -set number - -set expandtab - -set autoindent -set smartindent - -let mapleader="\" -let maplocalleader="\" - -" plugin 'toogleterm' need this or it will initialze a new terminal each time foucus on terminal -set hidden - -nmap q - -nmap h -nmap j -nmap k -nmap l - -lua << EOF -vim.g.markdown_fenced_languages = { - "ts=typescript" -} -EOF - -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" config of vim-plug -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -let s:plugs = [] - -function! s:add_plug(name, setup = v:true) - call add(s:plugs, { 'setup': a:setup, 'name': a:name }) -endfunction - -function! s:plug_name(dict) - return get(a:dict, 'name') -endfunction - -function! s:plug_setup(dict) - return get(a:dict, 'setup') -endfunction - -" call add_plug('bling/vim-bufferline', v:false) - -call s:add_plug('neovim/nvim-lspconfig') -call s:add_plug('kyazdani42/nvim-tree.lua') -call s:add_plug('kyazdani42/nvim-web-devicons', v:false) -call s:add_plug('akinsho/toggleterm.nvim') -call s:add_plug('lukas-reineke/indent-blankline.nvim') -call s:add_plug('jupyter-vim/jupyter-vim') - -"call s:add_plug('nvim-lualine/lualine.nvim') -"call s:add_plug('ap/vim-buftabline') -"call s:add_plug('projekt0n/github-nvim-theme') - -call s:add_plug('morhetz/gruvbox', v:false) -call s:add_plug('vim-airline/vim-airline', v:false) -call s:add_plug('vim-airline/vim-airline-themes', v:false) -call s:add_plug('bling/vim-bufferline', v:false) - -let g:airline_theme='violet' -set background=dark - - -function! s:setup_file(plug_name) - let l:pos_dot = strridx(a:plug_name, '.') - let l:pos_slash = strridx(a:plug_name, '/') - - let l:pos_dot = l:pos_dot > 0 ? l:pos_dot - 1 : -1 - let l:pos_slash = l:pos_slash > 0 ? l:pos_slash + 1 : 0 - return a:plug_name[l:pos_slash : l:pos_dot] .. '.vim' -endfunction - - -call plug#begin(has('nvim') ? stdpath('data') .. '/plugged' : '~/.vim/plugged') -for p in s:plugs - Plug get(p, 'name') -endfor -call plug#end() - -for p in s:plugs - if s:plug_setup(p) - execute 'source' stdpath('config') .. '/plugins.d/' .. s:setup_file(s:plug_name(p)) - endif -endfor diff --git a/lua/plugins/10-editor.lua b/lua/plugins/10-editor.lua new file mode 100644 index 0000000..cbcc3c4 --- /dev/null +++ b/lua/plugins/10-editor.lua @@ -0,0 +1,80 @@ +return { + { + "sainnhe/gruvbox-material", + config = function(_, _) + vim.o.termguicolors = true + vim.g.background = "dark" + vim.cmd("colorscheme gruvbox-material") + end + }, + { + "karb94/neoscroll.nvim", + main = "neoscroll", + config = true, + opts = { }, + }, + { + "lukas-reineke/indent-blankline.nvim", + main = "indent_blankline", + config = true, + opts = { + show_current_context = true, + show_current_context_start = true, + }, + }, + { + "lewis6991/gitsigns.nvim", + main = "gitsigns", + opts = { }, + }, + { + "akinsho/bufferline.nvim", + main = "bufferline", + opts = { + options = { + numbers = "both", + diagnostics = "nvim_lsp", + separator_style = "slant", + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + text_align = "center", + separator = true, + }, + }, + hover = { + delay = 200, + reveal = { "close" }, + }, + } + }, + }, + { + "nvim-lualine/lualine.nvim", + dependencies = { + "nvim-tree/nvim-web-devicons" + }, + main = "lualine", + opts = { }, + init = function(_) + vim.o.mousemoveevent = true + end, + }, + { + "nvim-tree/nvim-tree.lua", + dependencies = { + "nvim-tree/nvim-web-devicons" + }, + main = "nvim-tree", + opts = { }, + lazy = false, + keys = { + { "t", "NvimTreeFocus", mode = "n" }, + }, + init = function(_) + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + end, + } +} diff --git a/lua/plugins/50-lsp.lua b/lua/plugins/50-lsp.lua new file mode 100644 index 0000000..963b2b6 --- /dev/null +++ b/lua/plugins/50-lsp.lua @@ -0,0 +1,100 @@ +function setup_keymap_lsp() + -- -- Global mappings. + -- -- See `:help vim.diagnostic.*` for documentation on any of the below functions + -- vim.keymap.set("n", "e", vim.diagnostic.open_float) + -- vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) + -- vim.keymap.set("n", "]d", vim.diagnostic.goto_next) + -- vim.keymap.set("n", "q", vim.diagnostic.setloclist) + + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set("n", "wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "f", function() + vim.lsp.buf.format { async = true } + end, opts) + end, + }) +end + +return { + { + "neovim/nvim-lspconfig", + dependencies = { + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "L3MON4D3/LuaSnip", + }, + lazy = false, + config = function (_, opts) + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + local servers = { "clangd", "rust_analyzer", "pyright", "gopls", "denols" } + for _, lsp in ipairs(servers) do + require("lspconfig")[lsp].setup{ + capabilities = capabilities, + } + end + + 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), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "buffer" }, + { name = "luasnip" }, + }), + }) + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" } + }, { + { name = "cmdline" } + }) + }) + + setup_keymap_lsp() + end, + keys = { + { "e", vim.diagnostic.open_float, mode = "n" }, + { "[d", vim.diagnostic.goto_prev, mode = "n" }, + { "]d", vim.diagnostic.goto_next, mode = "n" }, + { "q", vim.diagnostic.setloclist, mode = "n" } + }, + }, +} diff --git a/lua/plugins/50-treesitter.lua b/lua/plugins/50-treesitter.lua new file mode 100644 index 0000000..e23739e --- /dev/null +++ b/lua/plugins/50-treesitter.lua @@ -0,0 +1,49 @@ +return { + "nvim-treesitter/nvim-treesitter", + main = "nvim-treesitter.configs", + config = true, + build = ":TSUpdate", + opts = { + indent = { enable = true }, + highlight = { enable = true }, + ensure_installed = { + "bash", + "c", + "cmake", + "cpp", + "css", + "diff", + "dockerfile", + "git_config", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore", + "go", + "gomod", + "gosum", + "html", + "java", + "javascript", + "json", + "json5", + "jsonc", + "lua", + "luadoc", + "luau", + "make", + "markdown", + "markdown_inline", + "python", + "rust", + "scss", + "sql", + "toml", + "vim", + "vimdoc", + "yaml" + }, + auto_install = true, + sync_install = false, + }, +} diff --git a/plugins.d/github-nvim-theme.vim b/plugins.d/github-nvim-theme.vim deleted file mode 100644 index b161a37..0000000 --- a/plugins.d/github-nvim-theme.vim +++ /dev/null @@ -1,3 +0,0 @@ -lua << EOF -require('github-theme').setup() -EOF diff --git a/plugins.d/indent-blankline.vim b/plugins.d/indent-blankline.vim deleted file mode 100644 index ca13128..0000000 --- a/plugins.d/indent-blankline.vim +++ /dev/null @@ -1,9 +0,0 @@ -lua << EOF - -require("indent_blankline").setup { - -- for example, context is off by default, use this to turn it on - -- show_current_context = true, - -- show_current_context_start = true, - filetype = {} -} -EOF diff --git a/plugins.d/jupyter-vim.vim b/plugins.d/jupyter-vim.vim deleted file mode 100644 index 5c650b8..0000000 --- a/plugins.d/jupyter-vim.vim +++ /dev/null @@ -1,37 +0,0 @@ -if has('nvim') - "let g:python3_host_prog = '~/miniconda3/envs/torch/bin/python3' - let g:python3_host_prog = '/usr/bin/python3' -else - set pyxversion=3 -endif - -" Always use the same virtualenv for vim, regardless of what Python -" environment is loaded in the shell from which vim is launched -" -" let g:vim_virtualenv_path = '~/miniconda3/envs/torch' -" if exists('g:vim_virtualenv_path') -" pythonx import os; import vim -" pythonx activate_this = os.path.join(vim.eval('g:vim_virtualenv_path'), 'bin/activate_this.py') -" pythonx with open(activate_this) as f: exec(f.read(), {'__file__': activate_this}) -" endif - - -""""""""""""""""""""""""" -" Key mapping -""""""""""""""""""""""""" - -" Run current file -nnoremap R :JupyterRunFile -nnoremap I :PythonImportThisFile - -" Change to directory of current file -nnoremap d :JupyterCd %:p:h - -" Send a selection of lines -nnoremap X :JupyterSendCell -nnoremap E :JupyterSendRange -nmap e JupyterRunTextObj -vmap e JupyterRunVisual - -" Debugging maps -nnoremap b :PythonSetBreak diff --git a/plugins.d/lualine.vim b/plugins.d/lualine.vim deleted file mode 100644 index 93d98ff..0000000 --- a/plugins.d/lualine.vim +++ /dev/null @@ -1,3 +0,0 @@ -lua << END -require('lualine').setup() -END diff --git a/plugins.d/nvim-lspconfig.vim b/plugins.d/nvim-lspconfig.vim deleted file mode 100644 index 3068f2c..0000000 --- a/plugins.d/nvim-lspconfig.vim +++ /dev/null @@ -1,59 +0,0 @@ -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" config of LSP -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -lua << EOF - -local nvim_lsp = require('lspconfig') --- local util = require('lsputil') - --- Use an on_attach function to only map the following keys --- after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - - -- Enable completion triggered by - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') - - -- Mappings. - local opts = { noremap=true, silent=true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) - buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - buf_set_keymap('n', 'e', 'lua vim.diagnostic.open_float()', opts) - buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) - buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) - buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) - -end - --- Use a loop to conveniently call 'setup' on multiple servers and --- map buffer local keybindings when the language server attaches -local servers = { 'pyright', 'html', 'gopls' } -for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - }, - root_dir = nvim_lsp.util.find_git_ancestor - } -end - -require'lspconfig'.quick_lint_js.setup{} -require'lspconfig'.denols.setup{} - -EOF diff --git a/plugins.d/nvim-tree.vim b/plugins.d/nvim-tree.vim deleted file mode 100644 index 7ea840b..0000000 --- a/plugins.d/nvim-tree.vim +++ /dev/null @@ -1,27 +0,0 @@ -lua << EOF --- following options are the default --- each of these are documented in `:help nvim-tree.OPTION_NAME` -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - -require("nvim-tree").setup({ - sort_by = "case_sensitive", - view = { - adaptive_size = true, - mappings = { - list = { - { key = "u", action = "dir_up" }, - }, - }, - }, - renderer = { - group_empty = true, - }, - filters = { - dotfiles = true, - }, -}) -EOF - - -nnoremap t :NvimTreeFocus diff --git a/plugins.d/toggleterm.vim b/plugins.d/toggleterm.vim deleted file mode 100644 index aab00c0..0000000 --- a/plugins.d/toggleterm.vim +++ /dev/null @@ -1,13 +0,0 @@ -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" config of toggleterm -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - -lua << EOF -require("toggleterm").setup{ -} -EOF - -nnoremap ToggleTerm -" tnoremap ToggleTerm -tnoremap wincmd p -tnoremap diff --git a/plugins.d/vim-buftabline.vim b/plugins.d/vim-buftabline.vim deleted file mode 100644 index 54f26da..0000000 --- a/plugins.d/vim-buftabline.vim +++ /dev/null @@ -1,3 +0,0 @@ -let g:buftabline_numbers = 1 -let g:buftabline_indicators = 1 -let g:buftabline_separators = 1