Browse Source

👌 IMPROVE: update

pull/174/head
Xin.Chen 3 years ago
parent
commit
db1fef8d07
  1. 32
      init.lua
  2. 52
      init.vim
  3. 12
      lua/basic.lua
  4. 12
      lua/colorscheme.lua
  5. 121
      lua/keybindings.lua
  6. 45
      lua/plugin-config/diffview.lua
  7. 88
      lua/plugins.lua
  8. 7
      lua/utils/fix-yank.lua
  9. 10
      lua/utils/im-select.lua
  10. 0
      lua/utils/utils.lua

32
init.lua

@ -0,0 +1,32 @@
-- 基础设置
require('basic')
-- Packer插件管理
require('plugins')
-- 快捷键映射
require('keybindings')
-- 主题设置
require('colorscheme')
-- 输入法自动切换
require('utils/im-select')
-- 复制到windows剪贴板
require('utils/fix-yank')
-- 插件配置
require('plugin-config/nvim-tree')
require('plugin-config/bufferline')
require('plugin-config/nvim-treesitter')
require('plugin-config/telescope')
require('plugin-config/nvim-autopairs')
require('plugin-config/comment')
require('plugin-config/surround')
require('plugin-config/nvim-colorizer')
require('plugin-config/diffview')
-- lua require('plugin-config/which-key')
-- 内置LSP
require('lsp/setup')
require('lsp/nvim-cmp')
require('lsp/ui')
-- lua require('plugin-config/rust-tools')

52
init.vim

@ -1,52 +0,0 @@
" 基础设置
lua require('basic')
" Packer插件管理
lua require('plugins')
" 快捷键映射
lua require('keybindings')
" 皮肤设置
" https://github.com/ellisonleao/gruvbox.nvim
set background=dark " or light if you want light mode
colorscheme onedark
" 插件配置
lua require('plugin-config/nvim-tree')
lua require('plugin-config/bufferline')
lua require('plugin-config/nvim-treesitter')
lua require('plugin-config/telescope')
lua require('plugin-config/nvim-autopairs')
" lua require('plugin-config/surround')
lua require('plugin-config/comment')
" lua require('plugin-config/nvim-colorizer')
" lua require('plugin-config/rust-tools')
" lua require('plugin-config/which-key')
" lsp
lua require('lsp/setup')
lua require('lsp/nvim-cmp')
lua require('lsp/ui')
" windows problems
" 复制到windows剪贴板
" https://stackoverflow.com/questions/44480829/how-to-copy-to-clipboard-in-vim-of-bash-on-windows
autocmd TextYankPost * if v:event.operator ==# 'y' | call system('/mnt/c/Windows/System32/clip.exe', @0) | endif
" 1033 中文语言
" 2052 英文语言
augroup im_select
autocmd!
autocmd InsertLeave * silent ! ~/.config/nvim/im-select.exe 1033
autocmd InsertEnter * silent !~/.config/nvim/im-select.exe 2052
autocmd BufRead * silent !~/.config/nvim/im-select.exe 1033
" autocmd CmdlineLeave * silent !./im-select.exe 1033
" autocmd CmdlineEnter * silent !./im-select.exe 2052
augroup END
" let g:vimspector_enable_mappings = 'HUMAN'
" nmap <leader>dd :call vimspector#Launch()<CR>
" nmap <leader>dx :call vimspectorReset<CR>
" nmap <leader>de :call vimspectorEval
" nmap <leader>dw :call vimspectorWatch

12
lua/basic.lua

@ -34,8 +34,6 @@ vim.o.smartcase = true
vim.o.hlsearch = false
-- 边输入边搜索
vim.o.incsearch = true
-- 使用增强状态栏后不再需要 vim 的模式提示
vim.o.showmode = false
-- 命令行高为2,提供足够的显示空间
vim.o.cmdheight = 2
-- 当文件被外部程序修改时,自动加载
@ -56,9 +54,9 @@ vim.o.writebackup = false
vim.o.swapfile = false
-- smaller updatetime
vim.o.updatetime = 300
-- 设置 timeoutlen 为等待键盘快捷键连击时间300毫秒,可根据需要设置
-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒,可根据需要设置
-- 遇到问题详见:https://github.com/nshen/learn-neovim-lua/issues/1
vim.o.timeoutlen = 300
vim.o.timeoutlen = 500
-- split window 从下边和右边出现
vim.o.splitbelow = true
vim.o.splitright = true
@ -75,7 +73,9 @@ vim.o.listchars = "space:·"
vim.o.wildmenu = true
-- Dont' pass messages to |ins-completin menu|
vim.o.shortmess = vim.o.shortmess .. 'c'
-- 补全最多显示10行
vim.o.pumheight = 10
-- always show tabline
-- 永远显示 tabline
vim.o.showtabline = 2
-- 使用增强状态栏后不再需要 vim 的模式提示
vim.o.showmode = true

12
lua/colorscheme.lua

@ -0,0 +1,12 @@
local colorscheme = "tokyonight"
-- gruvbox
-- zephyr
-- nord
-- onedark
-- tokyonight
local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
if not status_ok then
vim.notify("colorscheme " .. colorscheme .. " 没有找到!")
return
end

121
lua/keybindings.lua

@ -1,4 +1,4 @@
-- leader key 为空
-- leader key 为空
vim.g.mapleader = " "
vim.g.maplocalleader = " "
@ -9,6 +9,14 @@ local opt = {
silent = true
}
-- Modes
-- normal_mode = "n",
-- insert_mode = "i",
-- visual_mode = "v",
-- visual_block_mode = "x",
-- term_mode = "t",
-- command_mode = "c",
map("n", "<C-j>", "4j", opt)
map("n", "<C-k>", "4k", opt)
map("i", "<C-h>", "<ESC>I", opt)
@ -18,14 +26,19 @@ map("i", "<C-l>", "<ESC>A", opt)
map("n", "<C-u>", "9k", opt)
map("n", "<C-d>", "9j", opt)
-- visual模式下缩进代码
map("v", "<", "<gv", opt)
map("v", ">", ">gv", opt)
-- magic search
map("n", "/", "/\\v", { noremap = true , silent = false})
map("v", "/", "/\\v", { noremap = true , silent = false})
-- visual模式下缩进代码
map("v", "<", "<gv", opt)
map("v", ">", ">gv", opt)
-- 在visual mode 里粘贴不要复制
map("v", "p", '"_dP', opt)
-- 上下移动选中文本
map("v", "J", ":move '>+1<CR>gv-gv", opt)
map("v", "K", ":move '<-2<CR>gv-gv", opt)
------------------------------------------------------------------
-- windows 分屏快捷键
map("n", "sv", ":vsp<CR>", opt)
@ -36,12 +49,18 @@ map("n", "sc", "<C-w>c", opt)
-- 关闭其他
map("n", "so", "<C-w>o", opt) -- close others
-- 比例控制
map("n", "s.", ":vertical resize +20<CR>", opt)
-- 左右比例控制
map("n", "<C-Left>", ":vertical resize -2<CR>", opt)
map("n", "<C-Right>", ":vertical resize +2<CR>", opt)
map("n", "s,", ":vertical resize -20<CR>", opt)
map("n", "s=", "<C-w>=", opt)
map("n", "s.", ":vertical resize +20<CR>", opt)
-- 上下比例
map("n", "sj", ":resize +10<CR>", opt)
map("n", "sk", ":resize -10<CR>", opt)
map("n", "<C-Down>", ":resize +2<CR>", opt)
map("n", "<C-Up>", ":resize -2<CR>", opt)
-- 相等比例
map("n", "s=", "<C-w>=", opt)
-- alt + hjkl 窗口之间跳转
map("n", "<A-h>", "<C-w>h", opt)
@ -71,7 +90,7 @@ map("n", "<leader>i", "gg=G", opt)
-- Telescope
map("n", "<C-p>", ":Telescope find_files<CR>", opt)
-- map("n", "<leader>f", ":Telescope find_files<CR>", opt)
map("n", "<leader>g", ":Telescope live_grep<CR>", opt)
map("n", "<C-f>", ":Telescope live_grep<CR>", opt)
---
@ -89,18 +108,17 @@ pluginKeys.comment = {
bock = 'gb'
}
}
-- ctrl + /
map("n", "<C-_>", "gcc", {noremap = false})
map("v", "<C-_>", "gcc", {noremap = false})
-- lsp 回调函数快捷键设置
pluginKeys.maplsp = function(mapbuf)
-- rename
mapbuf('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opt)
-- code action
mapbuf('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opt)
mapbuf('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opt)
-- go xx
mapbuf('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
mapbuf('n', 'gh', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
@ -148,5 +166,84 @@ pluginKeys.cmp = function(cmp)
}
end
----- diffview ----
local status_ok, diffConfig = pcall(require, "diffview.config")
if status_ok then
map("n", "<leader>df", ":DiffviewOpen<CR>", opt)
map("n", "<leader>dfc", ":DiffviewClose<CR>", opt)
map("n", "<leader>fh", ":DiffviewFileHistory<CR>", opt)
map("n", "<leader>fhc", ":DiffviewClose<CR>", opt)
local cb = diffConfig.diffview_callback
pluginKeys.diffview = {
disable_defaults = false, -- Disable the default key bindings
-- The `view` bindings are active in the diff buffers, only when the current
-- tabpage is a Diffview.
view = {
-- ["<tab>"] = cb("select_next_entry"), -- Open the diff for the next file
-- ["<s-tab>"] = cb("select_prev_entry"), -- Open the diff for the previous file
-- ["gf"] = cb("goto_file"), -- Open the file in a new split in previous tabpage
-- ["<C-w><C-f>"] = cb("goto_file_split"), -- Open the file in a new split
-- ["<C-w>gf"] = cb("goto_file_tab"), -- Open the file in a new tabpage
-- ["<leader>e"] = cb("focus_files"), -- Bring focus to the files panel
["<leader>b"] = cb("toggle_files"), -- Toggle the files panel.
},
file_panel = {
["j"] = cb("next_entry"), -- Bring the cursor to the next file entry
["<down>"] = cb("next_entry"),
["k"] = cb("prev_entry"), -- Bring the cursor to the previous file entry.
["<up>"] = cb("prev_entry"),
["<cr>"] = cb("select_entry"), -- Open the diff for the selected entry.
["o"] = cb("select_entry"),
["<2-LeftMouse>"] = cb("select_entry"),
["-"] = cb("toggle_stage_entry"), -- Stage / unstage the selected entry.
["S"] = cb("stage_all"), -- Stage all entries.
["U"] = cb("unstage_all"), -- Unstage all entries.
["X"] = cb("restore_entry"), -- Restore entry to the state on the left side.
["R"] = cb("refresh_files"), -- Update stats and entries in the file list.
["<tab>"] = cb("select_next_entry"),
["<s-tab>"] = cb("select_prev_entry"),
["gf"] = cb("goto_file"),
["<C-w><C-f>"] = cb("goto_file_split"),
["<C-w>gf"] = cb("goto_file_tab"),
["i"] = cb("listing_style"), -- Toggle between 'list' and 'tree' views
["f"] = cb("toggle_flatten_dirs"), -- Flatten empty subdirectories in tree listing style.
["<leader>e"] = cb("focus_files"),
["<leader>b"] = cb("toggle_files"),
},
file_history_panel = {
["g!"] = cb("options"), -- Open the option panel
["<C-A-d>"] = cb("open_in_diffview"), -- Open the entry under the cursor in a diffview
["y"] = cb("copy_hash"), -- Copy the commit hash of the entry under the cursor
["zR"] = cb("open_all_folds"),
["zM"] = cb("close_all_folds"),
["j"] = cb("next_entry"),
["<down>"] = cb("next_entry"),
["k"] = cb("prev_entry"),
["<up>"] = cb("prev_entry"),
["<cr>"] = cb("select_entry"),
["o"] = cb("select_entry"),
["<2-LeftMouse>"] = cb("select_entry"),
["<tab>"] = cb("select_next_entry"),
["<s-tab>"] = cb("select_prev_entry"),
["gf"] = cb("goto_file"),
["<C-w><C-f>"] = cb("goto_file_split"),
["<C-w>gf"] = cb("goto_file_tab"),
["<leader>e"] = cb("focus_files"),
["<leader>b"] = cb("toggle_files"),
},
option_panel = {
["<tab>"] = cb("select"),
["q"] = cb("close"),
},
}
end
return pluginKeys
-- let g:vimspector_enable_mappings = 'HUMAN'
-- nmap <leader>dd :call vimspector#Launch()<CR>
-- nmap <leader>dx :call vimspectorReset<CR>
-- nmap <leader>de :call vimspectorEval
-- nmap <leader>dw :call vimspectorWatch

45
lua/plugin-config/diffview.lua

@ -0,0 +1,45 @@
-- https://github.com/sindrets/diffview.nvim
local cb = require'diffview.config'.diffview_callback
require'diffview'.setup {
diff_binaries = false, -- Show diffs for binaries
enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl'
use_icons = true, -- Requires nvim-web-devicons
icons = { -- Only applies when use_icons is true.
folder_closed = "",
folder_open = "",
},
signs = {
fold_closed = "",
fold_open = "",
},
file_panel = {
position = "left", -- One of 'left', 'right', 'top', 'bottom'
width = 35, -- Only applies when position is 'left' or 'right'
height = 10, -- Only applies when position is 'top' or 'bottom'
listing_style = "tree", -- One of 'list' or 'tree'
tree_options = { -- Only applies when listing_style is 'tree'
flatten_dirs = true, -- Flatten dirs that only contain one single dir
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
},
},
file_history_panel = {
position = "bottom",
width = 35,
height = 16,
log_options = {
max_count = 256, -- Limit the number of commits
follow = false, -- Follow renames (only for single file)
all = false, -- Include all refs under 'refs/' including HEAD
merges = false, -- List only merge commits
no_merges = false, -- List no merge commits
reverse = false, -- List commits in reverse order
},
},
default_args = { -- Default args prepended to the arg-list for the listed commands
DiffviewOpen = {},
DiffviewFileHistory = {},
},
hooks = {}, -- See ':h diffview-config-hooks'
key_bindings = require('keybindings').diffview,
}

88
lua/plugins.lua

@ -1,3 +1,24 @@
-- 插件安装目录
-- ~/.local/share/nvim/site/pack/packer/
-- 自动安装 Packer.nvim
local fn = vim.fn
local install_path = fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
local paccker_bootstrap
if fn.empty(fn.glob(install_path)) > 0 then
paccker_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
print '正在安装Pakcer.nvim...'
end
-- 每次保存 plugins.lua 自动安装插件
vim.cmd [[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerSync
augroup end
]]
return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
@ -22,9 +43,23 @@ return require('packer').startup(function(use)
-- Comment
use 'numToStr/Comment.nvim'
-- nvim-autopairs
use 'windwp/nvim-autopairs'
-- surround
use 'blackCauldron7/surround.nvim'
-- nvim-coloizer
use 'norcalli/nvim-colorizer.lua'
-- diffview.nvim
use { 'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim' }
-- telescope
use 'nvim-lua/popup.nvim'
use 'nvim-lua/plenary.nvim'
use {
'nvim-telescope/telescope.nvim',
requires = {{'nvim-lua/plenary.nvim'}}
}
-- which-key
-- use 'folke/which-key.nvim'
-------------------------- lsp -------------------------------------------
-- lspconfig
@ -53,8 +88,8 @@ return require('packer').startup(function(use)
-- gruvbox
use {
"ellisonleao/gruvbox.nvim",
requires = {"rktjmp/lush.nvim"}
'ellisonleao/gruvbox.nvim',
requires = {'rktjmp/lush.nvim'}
}
-- zephyr
use 'glepnir/zephyr-nvim'
@ -62,50 +97,13 @@ return require('packer').startup(function(use)
use 'shaunsingh/nord.nvim'
-- onedark
use 'ful1e5/onedark.nvim'
-- tokyonight
use 'folke/tokyonight.nvim'
------------------------------------
--
-- which-key
-- use 'folke/which-key.nvim'
-- telescope
use 'nvim-lua/popup.nvim'
use 'nvim-lua/plenary.nvim'
use {
'nvim-telescope/telescope.nvim',
requires = {{'nvim-lua/plenary.nvim'}}
}
-- use {
-- "folke/trouble.nvim",
-- requires = "kyazdani42/nvim-web-devicons",
-- config = function()
-- require("trouble").setup {
-- -- your configuration comes here
-- -- or leave it empty to use the default settings
-- -- refer to the configuration section below
-- }
-- end
-- }
if paccker_bootstrap then
require('packer').sync()
end
-- rust-tools
-- use 'simrat39/rust-tools.nvim'
-- nvim-cmp
-- use 'hrsh7th/cmp-nvim-lsp'
-- use 'hrsh7th/cmp-buffer'
-- use 'hrsh7th/cmp-path'
-- use 'hrsh7th/cmp-cmdline'
-- use 'hrsh7th/nvim-cmp'
-- use 'hrsh7th/cmp-vsnip'
-- vsnip
-- use 'hrsh7th/vim-vsnip'
-- use "rafamadriz/friendly-snippets"
-- use 'nvim-autopairs'
-- use "windwp/nvim-autopairs"
-- surround
-- use "blackCauldron7/surround.nvim"
-- nvim-coloizer
-- use 'norcalli/nvim-colorizer.lua'
end)

7
lua/utils/fix-yank.lua

@ -0,0 +1,7 @@
-- https://stackoverflow.com/questions/44480829/how-to-copy-to-clipboard-in-vim-of-bash-on-windows
vim.cmd([[
augroup fix_yank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system('/mnt/c/Windows/System32/clip.exe', @0) | endif
augroup END
]])

10
lua/utils/im-select.lua

@ -0,0 +1,10 @@
vim.cmd([[
" 1033 中文语言
" 2052 英文语言
augroup im_select
autocmd!
autocmd InsertLeave * silent ! ~/.config/nvim/im-select.exe 1033
autocmd InsertEnter * silent !~/.config/nvim/im-select.exe 2052
autocmd BufRead * silent !~/.config/nvim/im-select.exe 1033
augroup END
]])

0
lua/utils.lua → lua/utils/utils.lua

Loading…
Cancel
Save