This commit is contained in:
QQ 2023-01-22 17:20:38 +08:00
parent 20ab814b8d
commit 9cf805a96e
10 changed files with 199 additions and 184 deletions

View File

@ -1,73 +1 @@
# 打造自己nvim # 从零开始打造属于自己的nvim
## 文件夹结构
.
├── coc-settings.json -- coc的设置文件
├── init.lua -- nvim读取的配置文件
├── lazy-lock.json -- 插件管理工具的json包
├── lua
│   ├── coc.lua -- coc的配置
│   ├── keymap.lua -- 改建位的配置
│   ├── options.lua -- 设置
│   └── plug.lua -- 插件设置
└── README.md
leader键位的设置为空格
## coc的配置
```lua
vim.cmd([[
let g:coc_global_extensions = [
\ 'coc-clangd', -- clangd补全
\ 'coc-lua', -- lua补全
\ 'coc-python', -- python补全
\ 'coc-json', -- json补全
\
\ 'coc-translator', -- 翻译插件
\ 'coc-yank', -- 剪切板
\ 'coc-pairs', -- 括号补全
\ 'coc-explorer', -- 文件管理
\ 'coc-list', --
\ ]
]])
```
## 键位设置
**复制系列:**
```lua
-- 从系统寄存器
<leader>y = "+y
<leader>p = "+p
<leader>d = "+d
```
**搜索替换系列:**
```lua
? = :set hlsearch<CR>?
/ = :set hlsearch<CR>/
<c-n> = :nohlsearch<CR>
<leader>rp = :%s/
```

View File

@ -1,6 +1,5 @@
{ {
"snippets.ultisnips.pythonPrompt": false, "snippets.ultisnips.pythonPrompt": false,
"coc.preferences.extensionUpdateCheck": "daily", "explorer.icon.enableNerdfont": true,
"explorer.toggle": true, "explorer.toggle": true
"explorer.icon.enableNerdfont": true
} }

View File

@ -1,7 +1,8 @@
vim.g.mapleader = ' ' vim.g['mapleader'] = ' '
require('plug') require('core.plug')
require('options') require('core.options')
require('keymap') require('core.keymap')
require('coc') require('Plugin.coc')
require('Plugin.Im-auto-select')

View File

@ -1,18 +1,14 @@
{ {
"bullets.vim": { "branch": "master", "commit": "746f92ae05cdcc988857d8e76418326f07af9494" }, "coc.nvim": { "branch": "release", "commit": "e86b15bbcabc2cc1f20a40e7c127a424e7ad3850" },
"coc.nvim": { "branch": "release", "commit": "95b43f67147391cf2c69e550bd001b742781d226" },
"colorizer": { "branch": "master", "commit": "72790a003d5a706c287486a1a81e3a6b32158b54" }, "colorizer": { "branch": "master", "commit": "72790a003d5a706c287486a1a81e3a6b32158b54" },
"gitsigns.nvim": { "branch": "main", "commit": "addd6e174a85fc1c4007ab0b65d77e6555b417bf" },
"gruvbox": { "branch": "master", "commit": "bf2885a95efdad7bd5e4794dd0213917770d79b7" }, "gruvbox": { "branch": "master", "commit": "bf2885a95efdad7bd5e4794dd0213917770d79b7" },
"lazy.nvim": { "branch": "main", "commit": "4f60facf18b34ae06d164485aa2ce879e21e44fc" }, "lazy.nvim": { "branch": "main", "commit": "96d759d1cbd8b0bd0ea0a0c2987f99410272f348" },
"lazygit.nvim": { "branch": "main", "commit": "32bffdebe273e571588f25c8a708ca7297928617" }, "lazygit.nvim": { "branch": "main", "commit": "32bffdebe273e571588f25c8a708ca7297928617" },
"lualine.nvim": { "branch": "master", "commit": "0050b308552e45f7128f399886c86afefc3eb988" },
"nerdcommenter": { "branch": "master", "commit": "98cc4a2d64ca67cccbf5b5cf47c682ebadaaff58" }, "nerdcommenter": { "branch": "master", "commit": "98cc4a2d64ca67cccbf5b5cf47c682ebadaaff58" },
"vim-airline": { "branch": "master", "commit": "1d9ae3f972e76a1d36384da7a2890f6402d07d6c" }, "tabline.nvim": { "branch": "main", "commit": "5d76dc8616b4b7b892229cc05cd0f4cd0200077a" },
"vim-easy-align": { "branch": "master", "commit": "12dd6316974f71ce333e360c0260b4e1f81169c3" }, "vim-easy-align": { "branch": "master", "commit": "12dd6316974f71ce333e360c0260b4e1f81169c3" },
"vim-easymotion": { "branch": "master", "commit": "b3cfab2a6302b3b39f53d9fd2cd997e1127d7878" }, "vim-easymotion": { "branch": "master", "commit": "b3cfab2a6302b3b39f53d9fd2cd997e1127d7878" },
"vim-markdown-toc": { "branch": "master", "commit": "7ec05df27b4922830ace2246de36ac7e53bea1db" },
"vim-surround": { "branch": "master", "commit": "6c5e229e85e3248b9db27a2e6276583c586bf3dd" }, "vim-surround": { "branch": "master", "commit": "6c5e229e85e3248b9db27a2e6276583c586bf3dd" },
"vim-table-mode": { "branch": "master", "commit": "9555a3e6e5bcf285ec181b7fc983eea90500feb4" },
"vim-which-key": { "branch": "master", "commit": "c0eb7a63e80ed0dc2c91eb8c879b7396a795f775" },
"wildfire.vim": { "branch": "master", "commit": "b371e2b1d938ae0e164146136051de164ecb9aa5" } "wildfire.vim": { "branch": "master", "commit": "b371e2b1d938ae0e164146136051de164ecb9aa5" }
} }

102
lua/Plugin/coc.lua Normal file
View File

@ -0,0 +1,102 @@
vim.g['coc_global_extensions'] = {
"coc-clangd",
"coc-python",
"coc-json",
"coc-lua",
"coc-translator",
"coc-yank",
"coc-pairs",
"coc-explorer",
"coc-lists",
}
-- Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
-- delays and poor user experience
vim.opt.updatetime = 300
-- Always show the signcolumn, otherwise it would shift the text each time
-- diagnostics appeared/became resolved
vim.opt.signcolumn = "yes"
local keyset = vim.keymap.set
-- Autocomplete
function _G.check_back_leader()
local col = vim.fn.col('.') - 1
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
end
-- Use Tab for trigger completion with characters ahead and navigate
-- NOTE: There's always a completion item selected by default, you may want to enable
-- no select by setting `"suggest.noselect": true` in your configuration file
-- NOTE: Use command ':verbose imap <tab>' to make sure Tab is not mapped by
-- other plugins before putting this into your config
local opts = {silent = true, noremap = true, expr = true, replace_keycodes = false}
keyset("i", "<TAB>", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_leader() ? "<TAB>" : coc#refresh()', opts)
keyset("i", "<S-TAB>", [[coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"]], opts)
-- Make <CR> to accept selected completion item or notify coc.nvim to format
-- <C-g>u breaks current undo, please make your own choice
keyset("i", "<cr>", [[coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"]], opts)
-- Use `[g` and `]g` to navigate diagnostics
-- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
keyset("n", "[g", "<Plug>(coc-diagnostic-prev)", {silent = true})
keyset("n", "]g", "<Plug>(coc-diagnostic-next)", {silent = true})
-- GoTo code navigation
keyset("n", "gd", "<Plug>(coc-definition)", {silent = true})
keyset("n", "gy", "<Plug>(coc-type-definition)", {silent = true})
keyset("n", "gi", "<Plug>(coc-implementation)", {silent = true})
keyset("n", "gr", "<Plug>(coc-references)", {silent = true})
-- Symbol renaming
keyset("n", "<leader>rn", "<Plug>(coc-rename)", {silent = true})
-- Formatting selected code
keyset("x", "<leader>i", "<Plug>(coc-format-selected)", {silent = true})
keyset("n", "<leader>i", "<Plug>(coc-format-selected)", {silent = true})
-- Apply codeAction to the selected region
-- Example: `<leader>aap` for current paragraph
local opts = {silent = true, nowait = true}
-- Map function and class text objects
-- NOTE: Requires 'textDocument.documentSymbol' support from the language server
keyset("x", "if", "<Plug>(coc-funcobj-i)", opts)
keyset("o", "if", "<Plug>(coc-funcobj-i)", opts)
keyset("x", "af", "<Plug>(coc-funcobj-a)", opts)
keyset("o", "af", "<Plug>(coc-funcobj-a)", opts)
keyset("x", "ic", "<Plug>(coc-classobj-i)", opts)
keyset("o", "ic", "<Plug>(coc-classobj-i)", opts)
keyset("x", "ac", "<Plug>(coc-classobj-a)", opts)
keyset("o", "ac", "<Plug>(coc-classobj-a)", opts)
local opts = {silent = true, nowait = true}
-- Show all diagnostics
keyset("n", "<leader>a", ":<C-u>CocList diagnostics<cr>", opts)
-- Manage extensions
keyset("n", "<leader>e", ":<C-u>CocList extensions<cr>", opts)
-- Show commands
keyset("n", "<leader>c", ":<C-u>CocList commands<cr>", opts)
-- Find symbol of current document
keyset("n", "<leader>o", ":<C-u>CocList outline<cr>", opts)
-- Search workleader symbols
keyset("n", "<leader>s", ":<C-u>CocList -I symbols<cr>", opts)
-- Do default action for next item
keyset("n", "<leader>j", ":<C-u>CocNext<cr>", opts)
-- Do default action for previous item
keyset("n", "<leader>k", ":<C-u>CocPrev<cr>", opts)
-- Resume latest coc list
keyset("n", "<leader>p", ":<C-u>CocListResume<cr>", opts)
-- explorer
keyset("n", "<c-n>", ":CocCommand explorer<CR>")
-- translator
keyset("n", "<leader>tt", "<Plug>(coc-translator-p)")
keyset("v", "<leader>tt", "<Plug>(coc-translator-pv)")
-- translator-releader
keyset("n", "<leader>tr", "<Plug>(coc-translator-r)")
keyset("v", "<leader>tr", "<Plug>(coc-translator-rv)")

View File

@ -1,37 +0,0 @@
vim.cmd([[
let g:coc_global_extensions = [
\ 'coc-clangd',
\ 'coc-lua',
\ 'coc-python',
\ 'coc-json',
\
\ 'coc-translator',
\ 'coc-yank',
\ 'coc-pairs',
\ 'coc-explorer',
\ 'coc-lists',
\ ]
]])
local map = vim.api.nvim_set_keymap
-- coc 设置
-- Autocomplete
function _G.check_back_space()
local col = vim.fn.col('.') - 1
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
end
-- Use Tab for trigger completion with characters ahead and navigate
-- NOTE: There's always a completion item selected by default, you may want to enable
-- no select by setting `"suggest.noselect": true` in your configuration file
-- NOTE: Use command ':verbose imap <tab>' to make sure Tab is not mapped by
-- other plugins before putting this into your config
local opts = {silent = true, noremap = true, expr = true, replace_keycodes = false}
map("i", "<TAB>", [[ coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "<TAB>" : coc#refresh() ]] , opts)
map("i", "<S-TAB>", [[ coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>" ]], opts)
-- Make <CR> to accept selected completion item or notify coc.nvim to format
-- <C-g>u breaks current undo, please make your own choice
map("i", "<cr>", [[ coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" ]], opts)

View File

@ -3,9 +3,12 @@ local map = vim.api.nvim_set_keymap
map('n', '<leader>y', '"+y', {noremap = true}) map('n', '<leader>y', '"+y', {noremap = true})
map('n', '<leader>p', '"+p', {noremap = true}) map('n', '<leader>p', '"+p', {noremap = true})
map('n', '<leader>d', '"+d', {noremap = true}) map('n', '<leader>d', '"+d', {noremap = true})
map('v', '<leader>y', '"+y', {noremap = true}) map('v', '<leader>y', '"+y', {noremap = true})
map('v', '<leader>p', '"+p', {noremap = true}) map('v', '<leader>p', '"+p', {noremap = true})
map('v', '<leader>d', '"+d', {noremap = true}) map('v', '<leader>d', '"+d', {noremap = true})
map('n', '<leader>nh', ':nohlsearch<CR>', {noremap = true})
map('n', '<leader>rp',':%s/',{noremap = true}) map('n', '<leader>rp',':%s/',{noremap = true})
map('n', 'L', '$', {noremap = true}) map('n', 'L', '$', {noremap = true})
@ -25,7 +28,6 @@ map('n', '<c-h>', '<c-w>h', {noremap = true})
map('n', '<c-k>', '<c-w>k', {noremap = true}) map('n', '<c-k>', '<c-w>k', {noremap = true})
map('n', '<c-l>', '<c-w>l', {noremap = true}) map('n', '<c-l>', '<c-w>l', {noremap = true})
map('n', '<c-c>', ':wq<CR>', {noremap = true}) map('n', '<c-c>', ':wq<CR>', {noremap = true})
map('n', '<c-n>', ':nohlsearch<CR>', {noremap = true})
map('n', '<leader><leader>y', 'ggyG', {noremap = true}) map('n', '<leader><leader>y', 'ggyG', {noremap = true})
@ -48,17 +50,6 @@ map('n', 's', '<Plug>(easymotion-overwin-f2)',{})
-- lazygit -- lazygit
map('n', '<leader>g', ':w<CR>:LazyGit<CR>', {}) map('n', '<leader>g', ':w<CR>:LazyGit<CR>', {})
-- coc.nvim
map("n", "[g", "<Plug>(coc-diagnostic-prev)", {silent = true})
map("n", "]g", "<Plug>(coc-diagnostic-next)", {silent = true})
map("n", "gd", "<Plug>(coc-definition)", {silent = true})
map("n", "gy", "<Plug>(coc-type-definition)", {silent = true})
map("n", "gi", "<Plug>(coc-implementation)", {silent = true})
map("n", "gr", "<Plug>(coc-references)", {silent = true})
map("n", "<leader>rn", "<Plug>(coc-rename)", {silent = true})
map("x", "<leader>i", "<Plug>(coc-format-selected)", {silent = true})
map("n", "<leader>i", "<Plug>(coc-format-selected)", {silent = true})
map("n", "<c-n>", ":CocCommand explorer<CR>", {silent = true})
--EasyAlign --EasyAlign
map("v", "ga", ":EasyAlign<CR>", {silent = true}) map("v", "ga", ":EasyAlign<CR>", {silent = true})

77
lua/core/options.lua Normal file
View File

@ -0,0 +1,77 @@
local set= vim.opt
-- 行号
set.nu = true
set.rnu = true
set.scrolloff = 999
-- 自动保存
set.autowrite = true
set.autowriteall = true
-- tab键
set.sw = 2
set.ts = 2
set.softtabstop = 2
set.smarttab = true
set.expandtab = true
set.autoindent = true
-- 光标
set.cursorline = true
-- 分屏
set.splitright = true
set.splitbelow = true
-- 搜索
set.ignorecase = true
set.incsearch = true
-- 不换行
set.textwidth = 999
set.wrap = false
-- 背景
set.background = 'dark'
-- 主题
vim.cmd("colorscheme gruvbox")
-- 输入法自动根据模式自动切换
vim.cmd([[ au InsertLeave * :silent !fcitx5-remote -c ]])
-- 文件判断
vim.cmd([[ filetype plugin on ]])
-- 取消换行注释
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = { "*" },
callback = function()
-- vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" }
vim.opt.formatoptions = vim.opt.formatoptions
- "o" -- O and o, don't continue comments
+ "r" -- But do continue when pressing enter.
end,
})

View File

@ -4,18 +4,21 @@ if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ vim.fn.system({
"git", "git",
"clone", "clone",
"--depth=1",
"--filter=blob:none", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git", "https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release "--branch=stable", -- latest stable release
lazypath, lazypath,
}) })
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
require("lazy").setup({ require("lazy").setup({
-- 主题插件 -- 主题插件
'vim-airline/vim-airline', 'nvim-lualine/lualine.nvim',
'morhetz/gruvbox', 'morhetz/gruvbox',
'kdheepak/tabline.nvim',
-- lsp 补全 -- lsp 补全
{'neoclide/coc.nvim', branch = 'release'}, {'neoclide/coc.nvim', branch = 'release'},
@ -38,10 +41,6 @@ require("lazy").setup({
-- git -- git
'kdheepak/lazygit.nvim', 'kdheepak/lazygit.nvim',
'lewis6991/gitsigns.nvim',
-- which key
'liuchengxu/vim-which-key',
}) })

View File

@ -1,41 +0,0 @@
-- 行号
vim.o.nu = true
vim.o.rnu = true
vim.o.scrolloff = 999
-- 自动保存
vim.o.autowrite = true
vim.o.autowriteall = true
-- tab键
vim.o.sw = 2
vim.o.ts = 2
vim.o.softtabstop = 2
vim.o.smarttab = true
vim.o.expandtab = true
vim.o.autoindent = true
-- 光标
vim.o.cursorline = true
-- 分屏
vim.o.splitright = true
vim.o.splitbelow = true
-- 搜索
vim.o.ignorecase = true
vim.o.incsearch = true
-- 不换行
vim.o.textwidth = 999
vim.o.wrap = false
-- 背景
vim.g.bg = dark
vim.cmd([[colorscheme gruvbox]])
-- 输入法自动根据模式自动切换
vim.cmd([[ au InsertLeave * :silent !fcitx5-remote -c ]])
-- 文件判断
vim.cmd([[ filetype plugin on ]])