From 6bc8fc6104fc7618688b7f8e5d453fb6f9700ec6 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Wed, 6 Jul 2022 22:50:45 +0800 Subject: [PATCH] feat: add neovim --- cli/fish/config.fish | 3 +- cli/vim.sh | 17 ++-- cli/vim/ginit.vim | 3 - cli/vim/neovim/init.lua | 39 +++++++++ cli/vim/neovim/lua/keybindings.lua | 51 ++++++++++++ cli/vim/neovim/lua/plugins.lua | 58 +++++++++++++ cli/vim/neovim/lua/plugins/bufferline.lua | 7 ++ cli/vim/neovim/lua/plugins/comment.lua | 7 ++ cli/vim/neovim/lua/plugins/lsp.lua | 99 +++++++++++++++++++++++ cli/vim/neovim/lua/plugins/statusline.lua | 6 ++ cli/vim/neovim/lua/plugins/telescope.lua | 12 +++ cli/vim/{ => vim}/tex.vim | 0 cli/vim/{init.vim => vim/vimrc} | 0 13 files changed, 291 insertions(+), 11 deletions(-) delete mode 100644 cli/vim/ginit.vim create mode 100644 cli/vim/neovim/init.lua create mode 100644 cli/vim/neovim/lua/keybindings.lua create mode 100644 cli/vim/neovim/lua/plugins.lua create mode 100644 cli/vim/neovim/lua/plugins/bufferline.lua create mode 100644 cli/vim/neovim/lua/plugins/comment.lua create mode 100644 cli/vim/neovim/lua/plugins/lsp.lua create mode 100644 cli/vim/neovim/lua/plugins/statusline.lua create mode 100644 cli/vim/neovim/lua/plugins/telescope.lua rename cli/vim/{ => vim}/tex.vim (100%) rename cli/vim/{init.vim => vim/vimrc} (100%) diff --git a/cli/fish/config.fish b/cli/fish/config.fish index a13f7ad..5d96c16 100644 --- a/cli/fish/config.fish +++ b/cli/fish/config.fish @@ -2,7 +2,8 @@ if status is-interactive # === default programs - set -gx EDITOR vim + set -gx EDITOR nvim + set -gx GOPROXY https://goproxy.io,direct # === fzf configuration set -gx FZF_DEFAULT_COMMAND 'ag -g ""' diff --git a/cli/vim.sh b/cli/vim.sh index b7b770a..e8cbe24 100755 --- a/cli/vim.sh +++ b/cli/vim.sh @@ -37,21 +37,24 @@ case "$PM" in fi ;; pacman) - #sudo pacman -S --noconfirm --needed neovim + #sudo pacman -S --noconfirm --needed neovim ripgrep + #git clone --depth 1 https://github.com/wbthomason/packer.nvim \ + #~/.local/share/nvim/site/pack/packer/start/packer.nvim #if enhance_vim; then #sudo pip install pyvim neovim #fi sudo pacman -S --noconfirm --needed nodejs npm yarn vim - if enhance_vim; then - $PDIR/devel/nodejs.sh config - sudo pip install pyvim - fi + #if enhance_vim; then + #$PDIR/devel/nodejs.sh config + #sudo pip install pyvim + #fi ;; esac # symlink configuration #sudo ln -sf "$(command -v vim)" /usr/bin/v -lnsf "$DIR/vim/init.vim" "$XDG_CONFIG_HOME/nvim/init.vim" +lnsf "$DIR/vim/neovim/init.lua" "$XDG_CONFIG_HOME/nvim/init.lua" +lnsf "$DIR/vim/neovim/lua" "$XDG_CONFIG_HOME/nvim/lua" +lnsf "$DIR/vim/vim/vimrc" "$HOME/.vimrc" lnsf "$DIR/vim/coc-settings.json" "$XDG_CONFIG_HOME/nvim/coc-settings.json" lnsf "$DIR/vim/coc-settings.json" "$HOME/.vim/coc-settings.json" -lnsf "$DIR/vim/init.vim" "$HOME/.vimrc" diff --git a/cli/vim/ginit.vim b/cli/vim/ginit.vim deleted file mode 100644 index b19319e..0000000 --- a/cli/vim/ginit.vim +++ /dev/null @@ -1,3 +0,0 @@ -Guifont 等距更纱黑体 T SC:h12 -source $VIMRUNTIME/mswin.vim -set mouse=a diff --git a/cli/vim/neovim/init.lua b/cli/vim/neovim/init.lua new file mode 100644 index 0000000..ed09a52 --- /dev/null +++ b/cli/vim/neovim/init.lua @@ -0,0 +1,39 @@ +-- global options +vim.g.mapleader = ";" +vim.g.clipboard = { + name = "sysclip", + copy = { + ["+"] = {"xsel", "-b"}, + ["*"] = {"xsel", "-b"}, + }, + paste = { + ["+"] = {"xsel", "-b"}, + ["*"] = {"xsel", "-b"}, + }, +} + +-- general options +vim.o.cursorline = true +vim.o.colorcolumn = 120 +vim.o.scrolloff = 8 +--vim.o.clipboard = "unnamedplus" +vim.o.expandtab = true +vim.o.list = true +vim.o.mouse = "a" + +-- window options +vim.wo.number = true + +-- more +require("keybindings") +require("plugins") + +gruvbox_ok, gruvbox = pcall(require, "gruvbox") +if gruvbox_ok then + vim.o.background = "dark" + vim.cmd [[ + colorscheme gruvbox + highlight Normal ctermbg=None guibg=none + highlight CursorLine ctermbg=240 + ]] +end diff --git a/cli/vim/neovim/lua/keybindings.lua b/cli/vim/neovim/lua/keybindings.lua new file mode 100644 index 0000000..9a9dc91 --- /dev/null +++ b/cli/vim/neovim/lua/keybindings.lua @@ -0,0 +1,51 @@ +local keymap = vim.api.nvim_set_keymap +local NORMAL = 'n' +local INSERT = 'i' +local VISUAL = 'v' +local COMMAND = 'c' + + +keymap(NORMAL, '', ':bnext', { noremap = true }) +keymap(NORMAL, '', ':bprev', { noremap = true }) +keymap(INSERT, '', ':bnext', { noremap = true }) +keymap(INSERT, '', ':bprev', { noremap = true }) +keymap(NORMAL, 'ss', ':source ~/.config/nvim/init.lua', { noremap = true }) +keymap(NORMAL, 'sc', ':source %', { noremap = true }) +keymap(NORMAL, 'w', ':w', { noremap = true }) +keymap(VISUAL, 'y', '"+y', { noremap = true }) +keymap(NORMAL, 'q', ':bd', { noremap = true }) +keymap(NORMAL, 'qq', ':qall', { noremap = true }) +keymap(NORMAL, 'ne', ':e %:h', { noremap = true }) +keymap(NORMAL, '', ':w', { noremap = true }) +keymap(INSERT, '', ':wa', { noremap = true }) +keymap(NORMAL, 'h', 'h', { noremap = true }) +keymap(NORMAL, 'j', 'j', { noremap = true }) +keymap(NORMAL, 'k', 'k', { noremap = true }) +keymap(NORMAL, 'l', 'l', { noremap = true }) +keymap(NORMAL, 'oo', 'o', { noremap = true }) +keymap(NORMAL, '', ':noh', { noremap = true }) +keymap(NORMAL, '', ':Telescope find_files follow=true', { noremap = true }) +keymap(NORMAL, 'ts', ':Telescope live_grep', { noremap = true }) +keymap(NORMAL, 'tt', ':Telescope file_browser path=%:p:h', { noremap = true }) +keymap(NORMAL, 'tb', ':Telescope buffers', { noremap = true }) +keymap(NORMAL, 'gc', ':Telescope git_branches', { noremap = true }) +keymap(NORMAL, 'gr', ':Telescope lsp_references', { noremap = true }) +keymap(NORMAL, 'gds', ':Telescope lsp_document_symbols', { noremap = true }) +keymap(NORMAL, 'gs', ':Git', { noremap = true }) +keymap(NORMAL, 'gp', ':Git push', { noremap = true }) +keymap(NORMAL, 'gg', ':Git pull', { noremap = true }) +keymap(NORMAL, 'gb', ':Git blame', { noremap = true }) +keymap(NORMAL, 'gl', ':Git log', { noremap = true }) +keymap(NORMAL, 'gpr', ':!gpr', { noremap = true }) +keymap(NORMAL, 'cn', ':cnext', { noremap = true }) +keymap(NORMAL, 'cp', ':cprev', { noremap = true }) + + +-- command mode +keymap(COMMAND, '', '', { noremap = true }) +keymap(COMMAND, '', '', { noremap = true }) +keymap(COMMAND, '', '', { noremap = true }) +keymap(COMMAND, '', '', { noremap = true }) +keymap(COMMAND, '', '', { noremap = true }) +keymap(COMMAND, '', '', { noremap = true }) +keymap(COMMAND, '', '', { noremap = true }) diff --git a/cli/vim/neovim/lua/plugins.lua b/cli/vim/neovim/lua/plugins.lua new file mode 100644 index 0000000..08e4228 --- /dev/null +++ b/cli/vim/neovim/lua/plugins.lua @@ -0,0 +1,58 @@ + + +require("packer").startup(function(use) + use "wbthomason/packer.nvim" -- this is essential. + + use "jiangmiao/auto-pairs" + use "tpope/vim-fugitive" + use "ellisonleao/gruvbox.nvim" + + -- nvim-surround + use({ + "kylechui/nvim-surround", + config = function() require("nvim-surround").setup({}) end + }) + + -- telescope + use { + "nvim-telescope/telescope.nvim", + requires = { {"nvim-lua/plenary.nvim"} }, + } + use "nvim-telescope/telescope-file-browser.nvim" + + -- bufferline + use { + "akinsho/bufferline.nvim", + tag = "v2.*", + requires = "kyazdani42/nvim-web-devicons", + } + + -- lsp + use "neovim/nvim-lspconfig" + + -- nvim-cmp + use "hrsh7th/nvim-cmp" -- The completion plugin + use "hrsh7th/cmp-nvim-lsp" -- LSP source for nvim-cmp + use "hrsh7th/cmp-buffer" -- buffer completions + use "hrsh7th/cmp-path" -- path completions + -- use "hrsh7th/cmp-cmdline" -- cmdline completions + use "saadparwaiz1/cmp_luasnip" -- snippet completions + + -- snippets + use "L3MON4D3/LuaSnip" --snippet engine + use "rafamadriz/friendly-snippets" -- a bunch of snippets to use + + + -- statusline + use "ojroques/nvim-hardline" + + -- comment + use "numToStr/Comment.nvim" +end) + + +require("plugins/telescope") +require("plugins/lsp") +require("plugins/bufferline") +require("plugins/statusline") +require("plugins/comment") diff --git a/cli/vim/neovim/lua/plugins/bufferline.lua b/cli/vim/neovim/lua/plugins/bufferline.lua new file mode 100644 index 0000000..f46c44a --- /dev/null +++ b/cli/vim/neovim/lua/plugins/bufferline.lua @@ -0,0 +1,7 @@ +local bufferline_ok, bufferline = pcall(require, "bufferline") +if not bufferline_ok then + return +end + +vim.o.termguicolors = true +require("bufferline").setup{} diff --git a/cli/vim/neovim/lua/plugins/comment.lua b/cli/vim/neovim/lua/plugins/comment.lua new file mode 100644 index 0000000..89f2132 --- /dev/null +++ b/cli/vim/neovim/lua/plugins/comment.lua @@ -0,0 +1,7 @@ +local comment_ok, comment = pcall(require, "Comment") +if not comment_ok then + return +end + +require("Comment").setup{} + diff --git a/cli/vim/neovim/lua/plugins/lsp.lua b/cli/vim/neovim/lua/plugins/lsp.lua new file mode 100644 index 0000000..10b901a --- /dev/null +++ b/cli/vim/neovim/lua/plugins/lsp.lua @@ -0,0 +1,99 @@ +local lspconfig_ok, lspconfig = pcall(require, "lspconfig") +if not lspconfig_ok then + return +end + +local language_servers = { 'gopls' } + +-- 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) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'od', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'fd', vim.lsp.buf.formatting, bufopts) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() + + +local cmp_status_ok, cmp = pcall(require, "cmp") +if cmp_status_ok then + local cmp_nvim_lsp_status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + if cmp_nvim_lsp_status_ok then + capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + end +end + +for _, langsvr in ipairs(language_servers) do + lspconfig[langsvr].setup({ + on_attach = on_attach, + capabilities = capabilities, + }) +end + + +if not cmp_status_ok then + return +end + +cmp.setup { + snippet = { + expand = function(args) + local luasnip_status_ok, luasnip = pcall(require, "luasnip") + if luasnip_status_ok then + luasnip.lsp_expand(args.body) + end + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = 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' }, + { name = 'buffer' }, + { name = 'path' }, + }, +} diff --git a/cli/vim/neovim/lua/plugins/statusline.lua b/cli/vim/neovim/lua/plugins/statusline.lua new file mode 100644 index 0000000..431d42d --- /dev/null +++ b/cli/vim/neovim/lua/plugins/statusline.lua @@ -0,0 +1,6 @@ +local hardline_ok, hardline = pcall(require, "hardline") +if not hardline_ok then + return +end + +require("hardline").setup{} diff --git a/cli/vim/neovim/lua/plugins/telescope.lua b/cli/vim/neovim/lua/plugins/telescope.lua new file mode 100644 index 0000000..a35add5 --- /dev/null +++ b/cli/vim/neovim/lua/plugins/telescope.lua @@ -0,0 +1,12 @@ +local telescope_ok, telescope = pcall(require, "telescope") +if not telescope_ok then + return +end + +telescope.load_extension "file_browser" +telescope.setup({ + extensions = { + file_browser = { + } + } +}) diff --git a/cli/vim/tex.vim b/cli/vim/vim/tex.vim similarity index 100% rename from cli/vim/tex.vim rename to cli/vim/vim/tex.vim diff --git a/cli/vim/init.vim b/cli/vim/vim/vimrc similarity index 100% rename from cli/vim/init.vim rename to cli/vim/vim/vimrc