feat: add neovim

This commit is contained in:
Klesh Wong 2022-07-06 22:50:45 +08:00
parent 8c1e44e4ca
commit 6bc8fc6104
13 changed files with 291 additions and 11 deletions

View File

@ -2,7 +2,8 @@
if status is-interactive if status is-interactive
# === default programs # === default programs
set -gx EDITOR vim set -gx EDITOR nvim
set -gx GOPROXY https://goproxy.io,direct
# === fzf configuration # === fzf configuration
set -gx FZF_DEFAULT_COMMAND 'ag -g ""' set -gx FZF_DEFAULT_COMMAND 'ag -g ""'

View File

@ -37,21 +37,24 @@ case "$PM" in
fi fi
;; ;;
pacman) 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 #if enhance_vim; then
#sudo pip install pyvim neovim #sudo pip install pyvim neovim
#fi #fi
sudo pacman -S --noconfirm --needed nodejs npm yarn vim sudo pacman -S --noconfirm --needed nodejs npm yarn vim
if enhance_vim; then #if enhance_vim; then
$PDIR/devel/nodejs.sh config #$PDIR/devel/nodejs.sh config
sudo pip install pyvim #sudo pip install pyvim
fi #fi
;; ;;
esac esac
# symlink configuration # symlink configuration
#sudo ln -sf "$(command -v vim)" /usr/bin/v #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" "$XDG_CONFIG_HOME/nvim/coc-settings.json"
lnsf "$DIR/vim/coc-settings.json" "$HOME/.vim/coc-settings.json" lnsf "$DIR/vim/coc-settings.json" "$HOME/.vim/coc-settings.json"
lnsf "$DIR/vim/init.vim" "$HOME/.vimrc"

View File

@ -1,3 +0,0 @@
Guifont 等距更纱黑体 T SC:h12
source $VIMRUNTIME/mswin.vim
set mouse=a

39
cli/vim/neovim/init.lua Normal file
View File

@ -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

View File

@ -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, '<c-pagedown>', ':bnext<cr>', { noremap = true })
keymap(NORMAL, '<c-pageup>', ':bprev<cr>', { noremap = true })
keymap(INSERT, '<c-pagedown>', '<esc>:bnext<cr>', { noremap = true })
keymap(INSERT, '<c-pageup>', '<esc>:bprev<cr>', { noremap = true })
keymap(NORMAL, '<leader>ss', ':source ~/.config/nvim/init.lua<cr>', { noremap = true })
keymap(NORMAL, '<leader>sc', ':source %<cr>', { noremap = true })
keymap(NORMAL, '<leader>w', ':w<cr>', { noremap = true })
keymap(VISUAL, '<leader>y', '"+y<cr>', { noremap = true })
keymap(NORMAL, '<leader>q', ':bd<cr>', { noremap = true })
keymap(NORMAL, '<leader>qq', ':qall<cr>', { noremap = true })
keymap(NORMAL, '<leader>ne', ':e %:h<cr>', { noremap = true })
keymap(NORMAL, '<c-s>', ':w<cr>', { noremap = true })
keymap(INSERT, '<c-s>', '<esc>:w<cr>a', { noremap = true })
keymap(NORMAL, '<leader>h', '<c-w>h', { noremap = true })
keymap(NORMAL, '<leader>j', '<c-w>j', { noremap = true })
keymap(NORMAL, '<leader>k', '<c-w>k', { noremap = true })
keymap(NORMAL, '<leader>l', '<c-w>l', { noremap = true })
keymap(NORMAL, '<leader>oo', '<c-w>o', { noremap = true })
keymap(NORMAL, '<leader><esc>', ':noh<cr>', { noremap = true })
keymap(NORMAL, '<c-p>', ':Telescope find_files follow=true<cr>', { noremap = true })
keymap(NORMAL, '<leader>ts', ':Telescope live_grep<cr>', { noremap = true })
keymap(NORMAL, '<leader>tt', ':Telescope file_browser path=%:p:h<cr>', { noremap = true })
keymap(NORMAL, '<leader>tb', ':Telescope buffers', { noremap = true })
keymap(NORMAL, '<leader>gc', ':Telescope git_branches<cr>', { noremap = true })
keymap(NORMAL, '<leader>gr', ':Telescope lsp_references<cr>', { noremap = true })
keymap(NORMAL, '<leader>gds', ':Telescope lsp_document_symbols<cr>', { noremap = true })
keymap(NORMAL, '<leader>gs', ':Git<cr>', { noremap = true })
keymap(NORMAL, '<leader>gp', ':Git push<cr>', { noremap = true })
keymap(NORMAL, '<leader>gg', ':Git pull<cr>', { noremap = true })
keymap(NORMAL, '<leader>gb', ':Git blame<cr>', { noremap = true })
keymap(NORMAL, '<leader>gl', ':Git log<cr>', { noremap = true })
keymap(NORMAL, '<leader>gpr', ':!gpr<cr>', { noremap = true })
keymap(NORMAL, '<leader>cn', ':cnext<cr>', { noremap = true })
keymap(NORMAL, '<leader>cp', ':cprev<cr>', { noremap = true })
-- command mode
keymap(COMMAND, '<C-a>', '<Home>', { noremap = true })
keymap(COMMAND, '<C-e>', '<End>', { noremap = true })
keymap(COMMAND, '<C-f>', '<Right>', { noremap = true })
keymap(COMMAND, '<C-b>', '<Left>', { noremap = true })
keymap(COMMAND, '<C-d>', '<Delete>', { noremap = true })
keymap(COMMAND, '<C-n>', '<Down>', { noremap = true })
keymap(COMMAND, '<C-p>', '<Up>', { noremap = true })

View File

@ -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")

View File

@ -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{}

View File

@ -0,0 +1,7 @@
local comment_ok, comment = pcall(require, "Comment")
if not comment_ok then
return
end
require("Comment").setup{}

View File

@ -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 <c-x><c-o>
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', '<C-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, bufopts)
vim.keymap.set('n', '<leader>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({
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = 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' }),
['<S-Tab>'] = 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' },
},
}

View File

@ -0,0 +1,6 @@
local hardline_ok, hardline = pcall(require, "hardline")
if not hardline_ok then
return
end
require("hardline").setup{}

View File

@ -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 = {
}
}
})