├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── autoload └── lv.vim ├── init.vim ├── lua └── lv.lua └── vim.lua /.gitignore: -------------------------------------------------------------------------------- 1 | plugged/* 2 | *~ 3 | autoload/plug.vim.old 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pack/vendor/start/mru"] 2 | path = pack/vendor/start/mru 3 | url = https://github.com/lvht/mru.git 4 | [submodule "pack/vendor/start/fzf"] 5 | path = pack/vendor/start/fzf 6 | url = https://github.com/lvht/fzf.git 7 | [submodule "pack/vendor/start/vimagit"] 8 | path = pack/vendor/start/vimagit 9 | url = https://github.com/jreybert/vimagit.git 10 | [submodule "pack/vendor/start/tagbar-proto"] 11 | path = pack/vendor/start/tagbar-proto 12 | url = https://github.com/tenfyzhong/tagbar-proto.vim 13 | [submodule "pack/vendor/start/treesitter"] 14 | path = pack/vendor/start/treesitter 15 | url = https://github.com/nvim-treesitter/nvim-treesitter 16 | [submodule "pack/vendor/start/lspconfig"] 17 | path = pack/vendor/start/lspconfig 18 | url = https://github.com/neovim/nvim-lspconfig.git 19 | [submodule "pack/vendor/start/ag"] 20 | path = pack/vendor/start/ag 21 | url = https://github.com/epii1/ag.vim 22 | [submodule "pack/vendor/start/gitsigns"] 23 | path = pack/vendor/start/gitsigns 24 | url = https://github.com/lewis6991/gitsigns.nvim 25 | [submodule "pack/vendor/start/tree"] 26 | path = pack/vendor/start/tree 27 | url = https://github.com/nvim-tree/nvim-tree.lua.git 28 | [submodule "pack/vendor/pretty-fold"] 29 | path = pack/vendor/start/pretty-fold 30 | url = https://github.com/bbjornstad/pretty-fold.nvim.git 31 | [submodule "pack/vendor/start/aerial"] 32 | path = pack/vendor/start/aerial 33 | url = https://github.com/stevearc/aerial.nvim 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2021 涛叔 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 涛叔的 Vim 配置 2 | 3 | 这是我的 Vim 配置,仅支持 NeoVim。我写的 Vim 相关文章可以到[博客](https://taoshu.in/vim/)阅读。 4 | 5 | ## 配置原则 6 | 7 | 尽量使用 NeoVim 的默认配置、默认功能和默认键位映射。只改必要的配置,只添加必要的插件。 8 | 9 | 拥抱现代化的 NeoVim,拥抱异步,拥抱 lua。使用24位真彩色主题。 10 | 11 | 还有一点,只加自己能看懂的配置!从网上无脑复制别人配置的行为很不 Vim。 12 | 13 | ## 插件管理 14 | 15 | 使用 Vim 内置的 packages 功能配合 git submodule 管理插件,可以参考我的[文章](https://taoshu.in/vim/plug-git.html)。 16 | 17 | 默认插件位置 `~/.config/nvim/pack/vendor/start`。其中的 vendor 可以根据个人喜好修改。 18 | 19 | ## 目录结构 20 | 21 | 配置目录结构如下: 22 | 23 | ``` 24 | ▸ autoload/ 25 | ▸ lua/ 26 | ▸ pack/vendor/start/ 27 | init.vim 28 | LICENSE 29 | README.md 30 | vim.lua 31 | ``` 32 | 33 | 所有的个人工具方法都组织到 `autoload/lv.vim` 中,使用 `lv#` 名称空间。 34 | 35 | 主配置文件为 `init.vim`,lua 的部分组织到 `vim.lua` 文件。 36 | 37 | ## 常用插件 38 | 39 | ### 主题 40 | 41 | 使用默认主题。 42 | 43 | ### 文件操作 44 | 45 | - [ag](https://github.com/taoso/ag.vim) 搜索文件内容 46 | - [fzf](https://github.com/taoso/fzf.vim) 搜索文件路径 47 | - [mru](https://github.com/taoso/mru.vim) 管理最近文件列表 48 | - [nvim-tree](https://github.com/nvim-tree/nvim-tree.lua) 查看目录结构 49 | 50 | 以上列出的 ag/fzf/mru 都是我自己定制的插件,代码最多也就一百多行,够用就好,方便定制。 51 | 这三个插件也是学习 vim/neovim 插件开发的好素材,不要错过。 52 | 53 | ### Git集成 54 | 55 | - [gitsigns](https://github.com/lewis6991/gitsigns.nvim) 显示修改状态、提前历史、内容变更等 56 | - [vimagit](https://github.com/jreybert/vimagit) magit 的 Vim 版本,交互式、分部提交,非常方便 57 | 58 | ### 编程相关 59 | 60 | - lsp 使用官方的 [lspconfig](https://github.com/neovim/nvim-lspconfig) 61 | - 代码高亮、缩进和语法检查使用 [treesitter](https://github.com/nvim-treesitter/nvim-treesitter) 62 | -------------------------------------------------------------------------------- /autoload/lv.vim: -------------------------------------------------------------------------------- 1 | function! lv#expandtab(len) 2 | if a:len 3 | setlocal expandtab 4 | execute 'setlocal shiftwidth='.a:len 5 | execute 'setlocal softtabstop='.a:len 6 | execute 'setlocal tabstop='.a:len 7 | else 8 | setlocal noexpandtab 9 | execute 'setlocal shiftwidth&vim' 10 | execute 'setlocal softtabstop&vim' 11 | execute 'setlocal tabstop&vim' 12 | endif 13 | endfunction 14 | 15 | function! lv#switchabc() 16 | let s = system('defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources') 17 | let is_abc = stridx(s, '"KeyboardLayout Name" = ABC') > 0 18 | 19 | if !is_abc 20 | silent !osascript /usr/local/opt/lv/ctrl+space.scpt 21 | end 22 | endfunction 23 | 24 | function! lv#copy() 25 | let c = join(v:event.regcontents,"\n") 26 | let c64 = system("base64", c) 27 | let s = "\e]52;c;" . trim(c64) . "\x07" 28 | call chansend(v:stderr, s) 29 | endfunction 30 | 31 | function! lv#vimjump() 32 | setlocal iskeyword+=: 33 | let cword = expand('') 34 | setlocal iskeyword-=: 35 | 36 | let flags = 'wes' 37 | if stridx(cword, '#') >= 0 && cword[len(cword)-1] != '#' 38 | let parts = split(cword, '#') 39 | 40 | call remove(parts, -1) 41 | let fpath = join(parts, '/').'.vim' 42 | 43 | let vim_jump_paths = get(g:, 'vim_jump_paths', '') 44 | let paths = split(vim_jump_paths, ',') + split(&runtimepath, ',') 45 | 46 | for root in paths 47 | let p = root . '/autoload/' . fpath 48 | 49 | if !filereadable(p) 50 | continue 51 | endif 52 | 53 | execute 'e ' . p 54 | let flags = 'we' 55 | endfor 56 | endif 57 | 58 | let pattern = "\\vfu(nction)?!? ".cword 59 | call search(pattern, flags) 60 | endfunction 61 | -------------------------------------------------------------------------------- /init.vim: -------------------------------------------------------------------------------- 1 | set mouse= 2 | set linebreak 3 | set cursorline 4 | set colorcolumn=80 5 | set smartcase 6 | set ignorecase 7 | set termguicolors 8 | set formatoptions+=ro 9 | set foldmethod=expr 10 | set foldexpr=v:lua.vim.treesitter.foldexpr() 11 | set completeopt+=fuzzy,noinsert,popup 12 | set laststatus=3 13 | set winborder=rounded 14 | 15 | highlight Normal guibg=none 16 | highlight StatusLine guibg=#303030 guifg=#adadad 17 | highlight SpellBad guibg=red 18 | 19 | nnoremap r :Mru 20 | nnoremap s :call fzf#Open() 21 | nnoremap e :NvimTreeToggle 22 | nnoremap f :NvimTreeFindFile 23 | 24 | autocmd BufReadPost * 25 | \ if line("'\"") >= 1 && line("'\"") <= line("$") 26 | \ | exe "normal! g`\"" 27 | \ | endif 28 | autocmd InsertLeave * call lv#switchabc() 29 | autocmd BufRead *.vim nnoremap :call lv#vimjump() 30 | autocmd BufRead *.lua,*.proto,*.css,*.html,*.js,*.json call lv#expandtab(2) 31 | 32 | command -nargs=1 Etab call lv#expandtab() 33 | 34 | runtime vim.lua 35 | -------------------------------------------------------------------------------- /lua/lv.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | -- https://github.com/neovim/nvim-lspconfig/issues/115#issuecomment-902680058 4 | function M.importing() 5 | local params = vim.lsp.util.make_range_params() 6 | params.context = { only = {"source.organizeImports"} } 7 | 8 | local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 5000) 9 | 10 | for _, res in pairs(result or {}) do 11 | for _, r in pairs(res.result or {}) do 12 | if next(r.edit) then 13 | vim.lsp.util.apply_workspace_edit(r.edit, "utf-8") 14 | elseif next(r.command) then 15 | vim.lsp.buf.execute_command(r.command) 16 | end 17 | end 18 | end 19 | end 20 | 21 | return M 22 | -------------------------------------------------------------------------------- /vim.lua: -------------------------------------------------------------------------------- 1 | require'gitsigns'.setup() 2 | 3 | vim.g.loaded_netrw = 1 4 | vim.g.loaded_netrwPlugin = 1 5 | 6 | require("nvim-tree").setup({ 7 | sort_by = "case_sensitive", 8 | hijack_cursor = true, 9 | update_focused_file = { 10 | update_root = true, 11 | }, 12 | view = { 13 | signcolumn = "auto", 14 | }, 15 | renderer = { 16 | group_empty = true, 17 | icons = { 18 | show = { 19 | file = false, 20 | folder = false, 21 | }, 22 | glyphs = { 23 | bookmark = "🔖", 24 | folder = { 25 | arrow_closed = "⏵", 26 | arrow_open = "⏷", 27 | }, 28 | symlink = "", 29 | git = { 30 | unstaged = "✗", 31 | staged = "✓", 32 | unmerged = "⌥", 33 | renamed = "➜", 34 | untracked = "☆", 35 | deleted = "⊖", 36 | ignored = "◌", 37 | }, 38 | }, 39 | }, 40 | }, 41 | filters = { 42 | dotfiles = true, 43 | }, 44 | }) 45 | 46 | require('pretty-fold').setup() 47 | 48 | vim.diagnostic.config({ 49 | -- Use the default configuration 50 | virtual_lines = true, 51 | 52 | -- Alternatively, customize specific options 53 | virtual_lines = { 54 | -- Only show virtual line diagnostics for the current cursor line 55 | current_line = true, 56 | }, 57 | }) 58 | 59 | require'nvim-treesitter.configs'.setup { 60 | highlight = { 61 | enable = true, 62 | additional_vim_regex_highlighting = false, 63 | }, 64 | indent = { 65 | enable = true, 66 | }, 67 | } 68 | 69 | vim.api.nvim_create_autocmd('LspAttach', { 70 | callback = function(ev) 71 | local client = vim.lsp.get_client_by_id(ev.data.client_id) 72 | if client:supports_method('textDocument/completion') then 73 | vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) 74 | end 75 | end, 76 | }) 77 | 78 | vim.api.nvim_create_autocmd("CompleteDone", { 79 | pattern = "*.go", 80 | callback = function(args) require'lv'.importing() end, 81 | }) 82 | 83 | vim.api.nvim_create_autocmd("BufWritePre", { 84 | pattern = "*.go", 85 | callback = function(args) 86 | require'lv'.importing() 87 | vim.lsp.buf.format { async = true } 88 | end, 89 | }) 90 | 91 | local lsp = require'lspconfig' 92 | lsp.gopls.setup({}) 93 | lsp.rust_analyzer.setup({}) 94 | 95 | require("aerial").setup({}) 96 | vim.keymap.set("n", "a", "AerialToggle!") 97 | --------------------------------------------------------------------------------