diff --git a/README.md b/README.md index 8bb3c16..de76011 100644 --- a/README.md +++ b/README.md @@ -1,73 +1 @@ -# 打造自己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 --- 从系统寄存器 -y = "+y -p = "+p -d = "+d -``` -**搜索替换系列:** -```lua -? = :set hlsearch? -/ = :set hlsearch/ - = :nohlsearch - -rp = :%s/ -``` - - - - - - - - - - - - - - - - - - - - - - - - - +# 从零开始打造属于自己的nvim diff --git a/coc-settings.json b/coc-settings.json index 0a22cd3..1648d6b 100644 --- a/coc-settings.json +++ b/coc-settings.json @@ -1,6 +1,5 @@ { "snippets.ultisnips.pythonPrompt": false, - "coc.preferences.extensionUpdateCheck": "daily", - "explorer.toggle": true, - "explorer.icon.enableNerdfont": true + "explorer.icon.enableNerdfont": true, + "explorer.toggle": true } diff --git a/init.lua b/init.lua index defb0b3..b0a5fba 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,8 @@ -vim.g.mapleader = ' ' +vim.g['mapleader'] = ' ' -require('plug') -require('options') -require('keymap') -require('coc') +require('core.plug') +require('core.options') +require('core.keymap') +require('Plugin.coc') +require('Plugin.Im-auto-select') diff --git a/lazy-lock.json b/lazy-lock.json index ced0d47..ed26176 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,18 +1,14 @@ { - "bullets.vim": { "branch": "master", "commit": "746f92ae05cdcc988857d8e76418326f07af9494" }, - "coc.nvim": { "branch": "release", "commit": "95b43f67147391cf2c69e550bd001b742781d226" }, + "coc.nvim": { "branch": "release", "commit": "e86b15bbcabc2cc1f20a40e7c127a424e7ad3850" }, "colorizer": { "branch": "master", "commit": "72790a003d5a706c287486a1a81e3a6b32158b54" }, - "gitsigns.nvim": { "branch": "main", "commit": "addd6e174a85fc1c4007ab0b65d77e6555b417bf" }, "gruvbox": { "branch": "master", "commit": "bf2885a95efdad7bd5e4794dd0213917770d79b7" }, - "lazy.nvim": { "branch": "main", "commit": "4f60facf18b34ae06d164485aa2ce879e21e44fc" }, + "lazy.nvim": { "branch": "main", "commit": "96d759d1cbd8b0bd0ea0a0c2987f99410272f348" }, "lazygit.nvim": { "branch": "main", "commit": "32bffdebe273e571588f25c8a708ca7297928617" }, + "lualine.nvim": { "branch": "master", "commit": "0050b308552e45f7128f399886c86afefc3eb988" }, "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-easymotion": { "branch": "master", "commit": "b3cfab2a6302b3b39f53d9fd2cd997e1127d7878" }, - "vim-markdown-toc": { "branch": "master", "commit": "7ec05df27b4922830ace2246de36ac7e53bea1db" }, "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" } } \ No newline at end of file diff --git a/lua/Plugin/coc.lua b/lua/Plugin/coc.lua new file mode 100644 index 0000000..b1fcc25 --- /dev/null +++ b/lua/Plugin/coc.lua @@ -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 ' 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", "", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_leader() ? "" : coc#refresh()', opts) +keyset("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts) + +-- Make to accept selected completion item or notify coc.nvim to format +-- u breaks current undo, please make your own choice +keyset("i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], opts) + +-- Use `[g` and `]g` to navigate diagnostics +-- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list +keyset("n", "[g", "(coc-diagnostic-prev)", {silent = true}) +keyset("n", "]g", "(coc-diagnostic-next)", {silent = true}) + +-- GoTo code navigation +keyset("n", "gd", "(coc-definition)", {silent = true}) +keyset("n", "gy", "(coc-type-definition)", {silent = true}) +keyset("n", "gi", "(coc-implementation)", {silent = true}) +keyset("n", "gr", "(coc-references)", {silent = true}) + +-- Symbol renaming +keyset("n", "rn", "(coc-rename)", {silent = true}) + +-- Formatting selected code +keyset("x", "i", "(coc-format-selected)", {silent = true}) +keyset("n", "i", "(coc-format-selected)", {silent = true}) + +-- Apply codeAction to the selected region +-- Example: `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", "(coc-funcobj-i)", opts) +keyset("o", "if", "(coc-funcobj-i)", opts) +keyset("x", "af", "(coc-funcobj-a)", opts) +keyset("o", "af", "(coc-funcobj-a)", opts) +keyset("x", "ic", "(coc-classobj-i)", opts) +keyset("o", "ic", "(coc-classobj-i)", opts) +keyset("x", "ac", "(coc-classobj-a)", opts) +keyset("o", "ac", "(coc-classobj-a)", opts) + +local opts = {silent = true, nowait = true} +-- Show all diagnostics +keyset("n", "a", ":CocList diagnostics", opts) +-- Manage extensions +keyset("n", "e", ":CocList extensions", opts) +-- Show commands +keyset("n", "c", ":CocList commands", opts) +-- Find symbol of current document +keyset("n", "o", ":CocList outline", opts) +-- Search workleader symbols +keyset("n", "s", ":CocList -I symbols", opts) +-- Do default action for next item +keyset("n", "j", ":CocNext", opts) +-- Do default action for previous item +keyset("n", "k", ":CocPrev", opts) +-- Resume latest coc list +keyset("n", "p", ":CocListResume", opts) + +-- explorer +keyset("n", "", ":CocCommand explorer") +-- translator +keyset("n", "tt", "(coc-translator-p)") +keyset("v", "tt", "(coc-translator-pv)") +-- translator-releader +keyset("n", "tr", "(coc-translator-r)") +keyset("v", "tr", "(coc-translator-rv)") + + diff --git a/lua/coc.lua b/lua/coc.lua deleted file mode 100644 index c16d661..0000000 --- a/lua/coc.lua +++ /dev/null @@ -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 ' 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", "", [[ coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh() ]] , opts) -map("i", "", [[ coc#pum#visible() ? coc#pum#prev(1) : "\" ]], opts) --- Make to accept selected completion item or notify coc.nvim to format --- u breaks current undo, please make your own choice -map("i", "", [[ coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\" ]], opts) - - diff --git a/lua/keymap.lua b/lua/core/keymap.lua similarity index 72% rename from lua/keymap.lua rename to lua/core/keymap.lua index 3ecbd0d..5b75fba 100644 --- a/lua/keymap.lua +++ b/lua/core/keymap.lua @@ -3,9 +3,12 @@ local map = vim.api.nvim_set_keymap map('n', 'y', '"+y', {noremap = true}) map('n', 'p', '"+p', {noremap = true}) map('n', 'd', '"+d', {noremap = true}) + map('v', 'y', '"+y', {noremap = true}) map('v', 'p', '"+p', {noremap = true}) map('v', 'd', '"+d', {noremap = true}) + +map('n', 'nh', ':nohlsearch', {noremap = true}) map('n', 'rp',':%s/',{noremap = true}) map('n', 'L', '$', {noremap = true}) @@ -25,7 +28,6 @@ map('n', '', 'h', {noremap = true}) map('n', '', 'k', {noremap = true}) map('n', '', 'l', {noremap = true}) map('n', '', ':wq', {noremap = true}) -map('n', '', ':nohlsearch', {noremap = true}) map('n', 'y', 'ggyG', {noremap = true}) @@ -48,17 +50,6 @@ map('n', 's', '(easymotion-overwin-f2)',{}) -- lazygit map('n', 'g', ':w:LazyGit', {}) --- coc.nvim -map("n", "[g", "(coc-diagnostic-prev)", {silent = true}) -map("n", "]g", "(coc-diagnostic-next)", {silent = true}) -map("n", "gd", "(coc-definition)", {silent = true}) -map("n", "gy", "(coc-type-definition)", {silent = true}) -map("n", "gi", "(coc-implementation)", {silent = true}) -map("n", "gr", "(coc-references)", {silent = true}) -map("n", "rn", "(coc-rename)", {silent = true}) -map("x", "i", "(coc-format-selected)", {silent = true}) -map("n", "i", "(coc-format-selected)", {silent = true}) -map("n", "", ":CocCommand explorer", {silent = true}) --EasyAlign map("v", "ga", ":EasyAlign", {silent = true}) diff --git a/lua/core/options.lua b/lua/core/options.lua new file mode 100644 index 0000000..b82f4dc --- /dev/null +++ b/lua/core/options.lua @@ -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, +}) + + + + + + + + + + + + + + + + + + + + + + diff --git a/lua/plug.lua b/lua/core/plug.lua similarity index 88% rename from lua/plug.lua rename to lua/core/plug.lua index e3c21ce..b5d7bc7 100644 --- a/lua/plug.lua +++ b/lua/core/plug.lua @@ -4,18 +4,21 @@ if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", + "--depth=1", "--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({ -- 主题插件 - 'vim-airline/vim-airline', + 'nvim-lualine/lualine.nvim', 'morhetz/gruvbox', + 'kdheepak/tabline.nvim', -- lsp 补全 {'neoclide/coc.nvim', branch = 'release'}, @@ -38,10 +41,6 @@ require("lazy").setup({ -- git 'kdheepak/lazygit.nvim', - 'lewis6991/gitsigns.nvim', - - -- which key - 'liuchengxu/vim-which-key', }) diff --git a/lua/options.lua b/lua/options.lua deleted file mode 100644 index 3f92832..0000000 --- a/lua/options.lua +++ /dev/null @@ -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 ]])