first commit
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
# My neovim config [](https://img.shields.io/badge/build-passing-brightgreen.svg)
|
||||
|
||||
|
||||
## Screenshot
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 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 <your code language...>
|
||||
```
|
||||
|
||||
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 \<leader\> 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 |
|
||||
| --- | --- | --- | --- |
|
||||
| \<C-c\> | Copy text | Press **Ctrl** and **c** to copy text | Visual |
|
||||
| \<C-v\> | Paste text | Press **Ctrl** and **v** to paste text | Normal |
|
||||
| \<F5\> | Create a new tab window | Press **F5** key to create a new tab | Normal |
|
||||
| \<leader\>t | Open the file tree on the left side | Press **leader**,**t** | Normal |
|
||||
| \<leader\>tf | Open the file tree on the left side and navigate to the location of your current file | Press **leader**,**t**,**f** | Normal |
|
||||
| \<leader\>te | Open a floating terminal inside the file | Press **leader**,**t**,**e** | Normal |
|
||||
| \<leader\>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 |
|
||||
| --- | --- | --- | --- |
|
||||
| \<c-]\> | Go to the definition | Press **ctrl** and **]** | Normal |
|
||||
| \<c-t\> | 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 |
|
||||
| \<Tab\> | Scroll down the suggestions within the code completion box | Press **TAB** to scroll down | Insert |
|
||||
| \<S-Tab\> | Scroll up the suggestions within the code completion box | Press **Shift** and **TAB** to scroll up | Insert |
|
||||
| \<S-k\> | 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.
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"snippets.ultisnips.pythonPrompt": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
require('options')
|
||||
require('keymaps')
|
||||
require('plugins')
|
||||
require('colorscheme')
|
||||
|
||||
require("nvim-tree").setup()
|
||||
require('options-plugins')
|
||||
@@ -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
|
||||
+100
@@ -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', '<F5>', '<Esc>:tabnew<CR>', opt)
|
||||
map('n', 'ff', '<Esc>:FloatermToggle<CR>', opt)
|
||||
map('t', 'ff', ':FloatermToggle<CR>', opt)
|
||||
map('n', '<leader>g', '<Esc>:CocCommand git.showBlameDoc<CR>', opt)
|
||||
map('v', '<C-S-c>', '"+y', opt)
|
||||
map('n', '<C-S-v>', '"*p', opt)
|
||||
|
||||
map("t", "<A-h>", "<C-w>h", opt)
|
||||
map("t", "<A-j>", "<C-w>j", opt)
|
||||
map("t", "<A-k>", "<C-w>k", opt)
|
||||
map("t", "<A-l>", "<C-w>l", opt)
|
||||
|
||||
--tag
|
||||
map("n", "wn", ":tabnew<CR>", opt)
|
||||
map("n", "ww", ":tabclose<CR>", opt)
|
||||
map("n", "wl", ":tabnext<CR>", opt)
|
||||
map("n", "wh", ":tabprevious<CR>", opt)
|
||||
|
||||
-- 取消 s 默认功能
|
||||
map("n", "s", "", opt)
|
||||
-- windows 分屏快捷键
|
||||
map("n", "sv", ":vsp<CR>", opt)
|
||||
map("n", "sh", ":sp<CR>", opt)
|
||||
-- 关闭当前
|
||||
map("n", "sc", "<C-w>c", opt)
|
||||
-- 关闭其他
|
||||
map("n", "so", "<C-w>o", opt)
|
||||
-- Alt + hjkl 窗口之间跳转
|
||||
map("n", "<A-h>", "<C-w>h", opt)
|
||||
map("n", "<A-j>", "<C-w>j", opt)
|
||||
map("n", "<A-k>", "<C-w>k", opt)
|
||||
map("n", "<A-l>", "<C-w>l", 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.", ":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)
|
||||
|
||||
|
||||
-- 上下滚动浏览
|
||||
map("n", "<C-j>", "4j", opt)
|
||||
map("n", "<C-k>", "4k", opt)
|
||||
-- ctrl u / ctrl + d 只移动9行,默认移动半屏
|
||||
map("n", "<C-u>", "9k", opt)
|
||||
map("n", "<C-d>", "9j", opt)
|
||||
|
||||
-- 退出
|
||||
map("n", "q", ":q<CR>", opt)
|
||||
map("n", "qq", ":q!<CR>", opt)
|
||||
map("n", "Q", ":qa!<CR>", opt)
|
||||
|
||||
-- insert 模式下,跳到行首行尾
|
||||
map("i", "<C-h>", "<ESC>I", opt)
|
||||
map("i", "<C-l>", "<ESC>A", opt)
|
||||
|
||||
-- 插件快捷键
|
||||
local pluginKeys = {}
|
||||
|
||||
-- nvim-tree
|
||||
-- alt + m 键打开关闭tree
|
||||
map("n", "<A-m>", ":NvimTreeToggle<CR>", opt)
|
||||
-- 列表快捷键
|
||||
pluginKeys.nvimTreeList = {
|
||||
-- 打开文件或文件夹
|
||||
{ key = {"<CR>", "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 = "<F5>", 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
|
||||
@@ -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 = '<CR>',
|
||||
node_incremental = '<CR>',
|
||||
node_decremental = '<BS>',
|
||||
scope_incremental = '<TAB>',
|
||||
}
|
||||
},
|
||||
-- 启用基于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 <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_space() ? "<TAB>" : coc#refresh()', opts)
|
||||
keyset("i", "<S-TAB>", [[coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"]], opts)
|
||||
|
||||
-- GoTo code navigation
|
||||
keyset("n", "<c-]>", "<Plug>(coc-definition)", {silent = true})
|
||||
keyset("n", "<c-t>", "<Plug>(coc-type-definition)", {silent = true})
|
||||
keyset("n", "gi", "<Plug>(coc-implementation)", {silent = true})
|
||||
keyset("n", "gr", "<Plug>(coc-references)", {silent = true})
|
||||
|
||||
-- Use K to show documentation in preview window
|
||||
function _G.show_docs()
|
||||
local cw = vim.fn.expand('<cword>')
|
||||
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", '<CMD>lua _G.show_docs()<CR>', {silent = true})
|
||||
-- Use <c-j> to trigger snippets
|
||||
keyset("i", "<c-j>", "<Plug>(coc-snippets-expand-jump)")
|
||||
-- Use <c-space> to trigger completion
|
||||
keyset("i", "<c-space>", "coc#refresh()", {silent = true, expr = true})
|
||||
@@ -0,0 +1,33 @@
|
||||
-- Hint: use `:h <option>` to figure out the meaning if needed
|
||||
vim.opt.clipboard = 'unnamedplus' -- use system clipboard
|
||||
vim.opt.completeopt = { 'menu', 'menuone', 'noselect' }
|
||||
vim.opt.mouse = 'a' -- allow the mouse to be used in Nvim
|
||||
|
||||
-- Tab
|
||||
vim.opt.tabstop = 4 -- number of visual spaces per TAB
|
||||
vim.opt.softtabstop = 4 -- number of spacesin tab when editing
|
||||
vim.opt.shiftwidth = 4 -- insert 4 spaces on a tab
|
||||
vim.opt.expandtab = true -- tabs are spaces, mainly because of python
|
||||
|
||||
-- UI config
|
||||
vim.opt.number = true -- show absolute number
|
||||
vim.opt.cursorline = true -- highlight cursor line underneath the cursor horizontally
|
||||
vim.opt.splitbelow = true -- open new vertical split bottom
|
||||
vim.opt.splitright = true -- open new horizontal splits right
|
||||
vim.opt.termguicolors = true -- enabl 24-bit RGB color in the TUI
|
||||
vim.opt.showmode = false -- we are experienced, wo don't need the "-- INSERT --" mode hint
|
||||
|
||||
-- Searching
|
||||
vim.opt.incsearch = true -- search as characters are entered
|
||||
vim.opt.ignorecase = true -- ignore case in searches by default
|
||||
vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered
|
||||
|
||||
-- disable netrw at the very start of your init.lua
|
||||
vim.g.loaded_netrw = 1
|
||||
vim.g.loaded_netrwPlugin = 1
|
||||
|
||||
vim.cmd([[
|
||||
if has("autocmd")
|
||||
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
|
||||
endif
|
||||
]])
|
||||
@@ -0,0 +1,72 @@
|
||||
-- Install Packer automatically if it's not installed(Bootstraping)
|
||||
-- Hint: string concatenation is done by `..`
|
||||
local ensure_packer = function()
|
||||
local fn = vim.fn
|
||||
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
|
||||
if fn.empty(fn.glob(install_path)) > 0 then
|
||||
fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path })
|
||||
vim.cmd [[packadd packer.nvim]]
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
local packer_bootstrap = ensure_packer()
|
||||
|
||||
|
||||
-- Reload configurations if we modify plugins.lua
|
||||
-- Hint
|
||||
-- <afile> - replaced with the filename of the buffer being manipulated
|
||||
vim.cmd([[
|
||||
augroup packer_user_config
|
||||
autocmd!
|
||||
autocmd BufWritePost plugins.lua source <afile> | PackerSync
|
||||
augroup end
|
||||
]])
|
||||
|
||||
|
||||
-- Install plugins here - `use ...`
|
||||
-- Packer.nvim hints
|
||||
-- after = string or list, -- Specifies plugins to load before this plugin. See "sequencing" below
|
||||
-- config = string or function, -- Specifies code to run after this plugin is loaded
|
||||
-- requires = string or list, -- Specifies plugin dependencies. See "dependencies".
|
||||
-- ft = string or list, -- Specifies filetypes which load this plugin.
|
||||
-- run = string, function, or table, -- Specify operations to be run after successful installs/updates of a plugin
|
||||
return require('packer').startup(function(use)
|
||||
-- Packer can manage itself
|
||||
use 'wbthomason/packer.nvim'
|
||||
|
||||
---------------------------------------
|
||||
-- NOTE: PUT YOUR THIRD PLUGIN HERE --
|
||||
---------------------------------------
|
||||
use { "ellisonleao/gruvbox.nvim" }
|
||||
use 'vim-airline/vim-airline'
|
||||
use 'vim-airline/vim-airline-themes'
|
||||
use {
|
||||
'nvim-tree/nvim-tree.lua',
|
||||
requires = {
|
||||
'nvim-tree/nvim-web-devicons', -- optional
|
||||
},
|
||||
}
|
||||
use {
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
run = function()
|
||||
local ts_update = require('nvim-treesitter.install').update({ with_sync = true })
|
||||
ts_update()
|
||||
end,
|
||||
}
|
||||
use {'neoclide/coc.nvim', branch = 'release'}
|
||||
--use 'voldikss/vim-floaterm'
|
||||
use 'jiangmiao/auto-pairs'
|
||||
use({
|
||||
"iamcco/markdown-preview.nvim",
|
||||
run = function() vim.fn["mkdp#util#install"]() end,
|
||||
})
|
||||
use 'fatih/vim-go'
|
||||
use 'mhinz/vim-startify'
|
||||
|
||||
-- Automatically set up your configuration after cloning packer.nvim
|
||||
-- Put this at the end after all plugins
|
||||
if packer_bootstrap then
|
||||
require('packer').sync()
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user