commit 89421750821a853c71fe5591fe21208ce68e13cf Author: woon Date: Thu Nov 16 09:36:41 2023 +0800 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..47bd427 --- /dev/null +++ b/README.md @@ -0,0 +1,121 @@ +# My neovim config [![](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://img.shields.io/badge/build-passing-brightgreen.svg) + + +## Screenshot + +![screenshot1](screenshot.png) + +![screenshot2](screenshot2.png) + +![screenshot3](screenshot3.png) + +## Reason + +I used to develop with Vim, but installing the code completion plugin (YouCompleteMe) and CSTags was too much of a hassle (those who have installed them before should deeply understand). + +Therefore, I decided to switch to Neovim. There are several benefits: + +1. Easier configuration management. +2. In case of future computer environment migration, Neovim is more convenient. +3. Faster startup speed (not significantly different). + +## Requirements + +- neovim `>= 0.8.0` +- nodejs `>= v14` +- lua `>= 5.2.0` + +## Usage + +First back up your original configuration information. + +And then: + +```shell +rm -rf ~/.config/nvim/ +cd ~/.config +git clone git@github.com:here-Leslie-Lau/my-nvim.git +mv my-nvim nvim +cd nvim && nvim lua/plugins.lua +``` + +Run in Neovim `:w` and Wait for the plugin installation to finish. + +Run in command-line mode: + +```shell +:CocInstall coc-git coc-json coc-lua +``` + +Tips: I'm using coc.nvim.Currently, the installed code completion includes `coc-go, coc-json, coc-lua`.If the programming language you need is not available, you can refer to the [official website](https://github.com/neoclide/coc.nvim). + +## Keymaps + +First, let me explain that my \ key is set to `\` + +You can modify the keybindings to your preferences in file `lua/keymaps.lua`: + +```lua +vim.g.mapleader = "\\" +``` + +| Shortcut keys | Purpose | Remark | Mode | +| --- | --- | --- | --- | +| \ | Copy text | Press **Ctrl** and **c** to copy text | Visual | +| \ | Paste text | Press **Ctrl** and **v** to paste text | Normal | +| \ | Create a new tab window | Press **F5** key to create a new tab | Normal | +| \t | Open the file tree on the left side | Press **leader**,**t** | Normal | +| \tf | Open the file tree on the left side and navigate to the location of your current file | Press **leader**,**t**,**f** | Normal | +| \te | Open a floating terminal inside the file | Press **leader**,**t**,**e** | Normal | +| \g | View the git commit history for the current line where the cursor is located | Press **leader**,**g** | Normal | + +You can modify the shortcut keys in file `lua/keymaps.lua`. + +### Language-related-shortcut-keys + +| Shortcut keys | Purpose | Remark | Mode | +| --- | --- | --- | --- | +| \ | Go to the definition | Press **ctrl** and **]** | Normal | +| \ | Go to the type definition | Press **ctrl** and **t** | Normal | +| gi | Go to the type definition | Press **g** and **i** | Normal | +| gr | View variable or function references | Press **g** and **r** | Normal | +| \ | Scroll down the suggestions within the code completion box | Press **TAB** to scroll down | Insert | +| \ | Scroll up the suggestions within the code completion box | Press **Shift** and **TAB** to scroll up | Insert | +| \ | Display detailed information about the function or variable where the cursor is located | Press **Shift** and **k** show docs | Normal | + +You can modify the language-related shortcut keys in file `lua/options-plugins.lua`. + +## Included-Plugins + +- [Packer](https://github.com/wbthomason/packer.nvim): Plugins management +- [Gruvbox](https://github.com/ellisonleao/gruvbox.nvim): Neovim gruvbox colorscheme +- [Vim-airline](https://github.com/vim-airline/vim-airline): vim airline +- [vim-airline-themes](https://github.com/vim-airline/vim-airline-themes): vim airline themes +- [nvim-tree](https://github.com/nvim-tree/nvim-tree.lua): A File Explorer For Neovim Written In Lua +- [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter): provide some basic functionality such as highlighting +- [coc-nvim](https://github.com/neoclide/coc.nvim): Make your Vim/Neovim as smart as VS Code +- [vim-floaterm](https://github.com/voldikss/vim-floaterm): Use (neo)vim terminal in the floating/popup window +- [auto-pairs](https://github.com/jiangmiao/auto-pairs): Insert or delete brackets, parens, quotes in pair +- [markdown-preview](iamcco/markdown-preview.nvim): Preview markdown on your modern browser with synchronised scrolling and flexible configuration +- [vim-go](https://github.com/fatih/vim-go): This plugin adds Go language support for Vim/Neovim +- [vim-startify](https://github.com/mhinz/vim-startify): This plugin provides a start screen for Vim and Neovim. + +## Structure + +```shell +. +├── init.lua +├── lua +│   ├── colorscheme.lua (Color-related configurations) +│   ├── keymaps.lua (keybindings configurations) +│   ├── options.lua (General settings) +│   ├── options-plugins.lua (plugins settings) +│   └── plugins.lua (plugins management) +├── README.md +``` + +## Contributing + +Option 1: First, `fork` the code repository, then update the feature, and finally, initiate a `pull request`. + +Option 2: Directly open an issue. diff --git a/coc-settings.json b/coc-settings.json new file mode 100644 index 0000000..d7f6fb0 --- /dev/null +++ b/coc-settings.json @@ -0,0 +1,3 @@ +{ + "snippets.ultisnips.pythonPrompt": false +} \ No newline at end of file diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..c4178c4 --- /dev/null +++ b/init.lua @@ -0,0 +1,7 @@ +require('options') +require('keymaps') +require('plugins') +require('colorscheme') + +require("nvim-tree").setup() +require('options-plugins') diff --git a/lua/colorscheme.lua b/lua/colorscheme.lua new file mode 100644 index 0000000..7c78463 --- /dev/null +++ b/lua/colorscheme.lua @@ -0,0 +1,4 @@ +vim.o.background = "dark" -- or "light" for light mode +vim.cmd('colorscheme gruvbox') +vim.g.airline_theme = 'base16_gruvbox_dark_pale' +-- vim.base16colorspace = 256 diff --git a/lua/keymaps.lua b/lua/keymaps.lua new file mode 100644 index 0000000..c7f26e8 --- /dev/null +++ b/lua/keymaps.lua @@ -0,0 +1,100 @@ +-- define common options +local opt = { + noremap = true, -- non-recursive + silent = true, -- do not show message +} +local map = vim.api.nvim_set_keymap + +vim.g.mapleader = "z" +-- vim.g.maplocalleader = "\\" + +map('n', '', ':tabnew', opt) +map('n', 'ff', ':FloatermToggle', opt) +map('t', 'ff', ':FloatermToggle', opt) +map('n', 'g', ':CocCommand git.showBlameDoc', opt) +map('v', '', '"+y', opt) +map('n', '', '"*p', opt) + +map("t", "", "h", opt) +map("t", "", "j", opt) +map("t", "", "k", opt) +map("t", "", "l", opt) + +--tag +map("n", "wn", ":tabnew", opt) +map("n", "ww", ":tabclose", opt) +map("n", "wl", ":tabnext", opt) +map("n", "wh", ":tabprevious", opt) + +-- 取消 s 默认功能 +map("n", "s", "", opt) +-- windows 分屏快捷键 +map("n", "sv", ":vsp", opt) +map("n", "sh", ":sp", opt) +-- 关闭当前 +map("n", "sc", "c", opt) +-- 关闭其他 +map("n", "so", "o", opt) +-- Alt + hjkl 窗口之间跳转 +map("n", "", "h", opt) +map("n", "", "j", opt) +map("n", "", "k", opt) +map("n", "", "l", opt) + +-- 左右比例控制 +map("n", "", ":vertical resize -2", opt) +map("n", "", ":vertical resize +2", opt) +map("n", "s,", ":vertical resize -20", opt) +map("n", "s.", ":vertical resize +20", opt) +-- 上下比例 +map("n", "sj", ":resize +10", opt) +map("n", "sk", ":resize -10", opt) +map("n", "", ":resize +2", opt) +map("n", "", ":resize -2", opt) +-- 等比例 +map("n", "s=", "=", opt) + + +-- 上下滚动浏览 +map("n", "", "4j", opt) +map("n", "", "4k", opt) +-- ctrl u / ctrl + d 只移动9行,默认移动半屏 +map("n", "", "9k", opt) +map("n", "", "9j", opt) + +-- 退出 +map("n", "q", ":q", opt) +map("n", "qq", ":q!", opt) +map("n", "Q", ":qa!", opt) + +-- insert 模式下,跳到行首行尾 +map("i", "", "I", opt) +map("i", "", "A", opt) + +-- 插件快捷键 +local pluginKeys = {} + +-- nvim-tree +-- alt + m 键打开关闭tree +map("n", "", ":NvimTreeToggle", opt) +-- 列表快捷键 +pluginKeys.nvimTreeList = { + -- 打开文件或文件夹 + { key = {"", "o", "<2-LeftMouse>"}, action = "edit" }, + -- 分屏打开文件 + { key = "v", action = "vsplit" }, + { key = "h", action = "split" }, + -- 显示隐藏文件 + { key = "i", action = "toggle_custom" }, -- 对应 filters 中的 custom (node_modules) + { key = ".", action = "toggle_dotfiles" }, -- Hide (dotfiles) + -- 文件操作 + { key = "", action = "refresh" }, + { key = "a", action = "create" }, + { key = "d", action = "remove" }, + { key = "r", action = "rename" }, + { key = "x", action = "cut" }, + { key = "c", action = "copy" }, + { key = "p", action = "paste" }, + { key = "s", action = "system_open" }, +} +return pluginKeys diff --git a/lua/options-plugins.lua b/lua/options-plugins.lua new file mode 100644 index 0000000..36020ad --- /dev/null +++ b/lua/options-plugins.lua @@ -0,0 +1,81 @@ +require'nvim-treesitter.configs'.setup { + -- 安装 language parser + -- :TSInstallInfo 命令查看支持的语言 + ensure_installed = {"vim", "lua", "javascript", "go"}, + -- 启用代码高亮功能 + highlight = { + enable = true, + additional_vim_regex_highlighting = false + }, + -- 启用增量选择 + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + node_decremental = '', + scope_incremental = '', + } + }, + -- 启用基于Treesitter的代码格式化(=) . NOTE: This is an experimental feature. + indent = { + enable = true + } +} +-- 开启 Folding +vim.wo.foldmethod = 'expr' +vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' +-- 默认不要折叠 +-- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file +vim.wo.foldlevel = 99 + +-- Some servers have issues with backup files, see #649 +vim.opt.backup = false +vim.opt.writebackup = false + +-- 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_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} +keyset("i", "", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()', opts) +keyset("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts) + +-- GoTo code navigation +keyset("n", "", "(coc-definition)", {silent = true}) +keyset("n", "", "(coc-type-definition)", {silent = true}) +keyset("n", "gi", "(coc-implementation)", {silent = true}) +keyset("n", "gr", "(coc-references)", {silent = true}) + +-- Use K to show documentation in preview window +function _G.show_docs() + local cw = vim.fn.expand('') + if vim.fn.index({'vim', 'help'}, vim.bo.filetype) >= 0 then + vim.api.nvim_command('h ' .. cw) + elseif vim.api.nvim_eval('coc#rpc#ready()') then + vim.fn.CocActionAsync('doHover') + else + vim.api.nvim_command('!' .. vim.o.keywordprg .. ' ' .. cw) + end +end +keyset("n", "K", 'lua _G.show_docs()', {silent = true}) +-- Use to trigger snippets +keyset("i", "", "(coc-snippets-expand-jump)") +-- Use to trigger completion +keyset("i", "", "coc#refresh()", {silent = true, expr = true}) diff --git a/lua/options.lua b/lua/options.lua new file mode 100644 index 0000000..9f3d047 --- /dev/null +++ b/lua/options.lua @@ -0,0 +1,33 @@ +-- Hint: use `:h