1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Compare commits

...

105 Commits

Author SHA1 Message Date
jdhao
b4c3b7eba0
Merge pull request #109 from jdhao/spell
update spell
2022-09-20 01:20:19 +08:00
jdhao
4203410878 update spell 2022-09-20 01:19:44 +08:00
jdhao
9f58c3b7a5
Merge pull request #108 from jdhao/gitsign
update gitsigns conf
2022-09-20 01:18:00 +08:00
jdhao
45d0d68b9e update gitsigns conf 2022-09-20 01:15:16 +08:00
jdhao
74a9767018
Merge pull request #107 from jdhao/option
noruler
2022-09-15 12:19:31 +08:00
jdhao
ab25bfc9c4 noruler 2022-09-15 12:18:26 +08:00
jdhao
ebbdb27d01
Merge pull request #106 from chaoqunya/chaoqunya-fix-typo-in-mappings
typo fixed
2022-09-13 14:27:15 +08:00
chaoqunya
1b1f0199da
typo fixed 2022-09-13 14:22:46 +08:00
jdhao
40fa9aab1c
Merge pull request #104 from jdhao/global
global.vim --> global.lua
2022-09-11 18:24:10 +08:00
jdhao
6e8e61e53a global.vim --> global.lua
fix 2

fix 3
2022-09-11 18:21:56 +08:00
jdhao
89effe8b17
Merge pull request #103 from jdhao/format
format with stylua
2022-09-10 23:56:04 +08:00
jdhao
aaeb6a813a format with stylua 2022-09-10 23:55:22 +08:00
jdhao
9ba728e201
Merge pull request #102 from jdhao/lualine
use gitsigns for diff
2022-09-10 22:57:06 +08:00
jdhao
e5f1b4d224 use gitsigns for diff
Lualine's builtin diff often disappears and is not reliable, which is really frustrating for me.
2022-09-10 22:55:22 +08:00
jdhao
eaddee0c5c
Merge pull request #101 from jdhao/lsp-map
refactor: lsp mapping
2022-09-09 19:42:42 +08:00
jdhao
0582f26abe refactor: lsp mapping 2022-09-09 19:42:01 +08:00
jdhao
e209ef686a
Merge pull request #100 from jdhao/hlslens
update hlslens conf
2022-09-09 19:22:18 +08:00
jdhao
8b3610ed3d update hlslens conf 2022-09-09 19:21:25 +08:00
jdhao
bde6083f22
Merge pull request #99 from jonghoonseo/master
Use node dir when already installed
2022-09-09 19:15:02 +08:00
Jonghoon Seo
c1f139108a Use node dir when already installed 2022-09-09 05:30:41 +09:00
jdhao
3bb8b224e7
Merge pull request #98 from jdhao/clean-plug
remove unused plugins
2022-09-08 20:36:19 +08:00
jdhao
b69320b4e2 remove unused plugins 2022-09-08 20:35:34 +08:00
jdhao
5c63ade4a0
Merge pull request #97 from jdhao/gitsigns
use gitsigns instead of signify
2022-09-08 20:33:06 +08:00
jdhao
b504c932e6 use gitsigns instead of signify 2022-09-08 20:31:33 +08:00
jdhao
a39befff93
Merge pull request #96 from jdhao/map
update mapping
2022-09-08 13:20:45 +08:00
jdhao
309c8ad636 update mapping 2022-09-08 13:19:34 +08:00
jdhao
954a4a1cad
Merge pull request #95 from jdhao/error-msg
refactor: use nvim_err_writeln for error msg
2022-09-07 23:36:49 +08:00
jdhao
67a322c26c refactor: use nvim_err_writeln for error msg 2022-09-07 23:35:18 +08:00
jdhao
91c9dbe40d
Merge pull request #94 from jdhao/neovide
add neovide conf
2022-09-07 23:31:57 +08:00
jdhao
6a5f1d24a7 add neovide conf 2022-09-07 23:30:52 +08:00
jdhao
4dcafbe2bc
Merge pull request #93 from jdhao/local-keymap
use local keymap
2022-09-06 21:54:18 +08:00
jdhao
14860072d0 use local keymap 2022-09-06 21:53:44 +08:00
jdhao
5a69d43cab
Merge pull request #92 from jdhao/lua-map
refactor: convert mapping from viml to lua
2022-09-06 21:26:12 +08:00
jdhao
11e6797cb5 refactor: convert mapping from viml to lua 2022-09-06 21:22:45 +08:00
jdhao
858848128f
Merge pull request #91 from jdhao/spell
update spell
2022-09-06 13:25:44 +08:00
jdhao
d436227f65 update spell 2022-09-06 13:24:44 +08:00
jdhao
acb8b7fcf8
Merge pull request #90 from jdhao/reorg
better-escape.vim is now under nvim-zh org
2022-09-05 01:02:06 +08:00
jdhao
46cbdc2d7f better-escape.vim is now under nvim-zh org 2022-09-05 01:00:42 +08:00
jdhao
c71ad44cd3
Merge pull request #89 from jdhao/hop
update hop.nvim conf
2022-09-05 00:54:05 +08:00
jdhao
db378b858b update hop.nvim conf 2022-09-05 00:53:23 +08:00
jdhao
ee45f1f5a1
Merge pull request #88 from jdhao/gitlinker
add plugin gitlinkder.nvim
2022-09-05 00:48:57 +08:00
jdhao
43660dd540 add plugin gitlinkder.nvim 2022-09-05 00:48:10 +08:00
jdhao
17acda10a0 fix 2022-09-01 13:24:52 +08:00
jdhao
eb87c5b0c3
Merge pull request #87 from jdhao/autocmd
simplify and add new autocmd
2022-09-01 13:24:05 +08:00
jdhao
b35956e6cd simplify and add new autocmd 2022-09-01 13:22:49 +08:00
jdhao
82f4c0e399
Merge pull request #86 from jdhao/hop
update hop.nvim conf
2022-08-31 23:57:49 +08:00
jdhao
16be5e0499 update hop.nvim conf 2022-08-31 23:56:52 +08:00
jdhao
a39b53b7c1
Merge pull request #85 from jdhao/packer
update packer conf
2022-08-31 00:02:32 +08:00
jdhao
b9616aeab0 update packer conf 2022-08-31 00:01:38 +08:00
jdhao
208b190a65
Merge pull request #84 from jdhao/indentline
update indent-blankline conf
2022-08-28 14:56:35 +08:00
jdhao
602254a881 update indent-blankline conf 2022-08-28 14:55:42 +08:00
jdhao
7022eefe22
Merge pull request #83 from jdhao/colorscheme
use colorscheme instead of theme
2022-08-28 13:09:17 +08:00
jdhao
dee7768162 use colorscheme instead of theme 2022-08-28 13:08:22 +08:00
jdhao
22b33871ef
Merge pull request #82 from jdhao/linux-setup
update linux setup
2022-08-28 12:47:30 +08:00
jdhao
aab74751f4 update linux setup 2022-08-28 12:47:01 +08:00
jdhao
5dbe643ea2
Merge pull request #81 from jdhao/reorg
refactor a bit
2022-08-28 12:46:15 +08:00
jdhao
b41998828d refactor a bit
1. change theme to colorscheme
2. update plugin load logic
2022-08-28 12:43:50 +08:00
jdhao
3670a19e51
Merge pull request #80 from jdhao/cmp-conf
update nvim-cmp conf
2022-08-28 11:13:32 +08:00
jdhao
545c6f4b92 update nvim-cmp conf 2022-08-28 11:02:01 +08:00
jdhao
86e3b29730
Merge pull request #79 from jdhao/fix-notify
fix parameter for vim.notify
2022-08-26 20:01:56 +08:00
jdhao
bc9b0a8cf8 fix parameter for vim.notify 2022-08-26 19:47:56 +08:00
jdhao
fb9a0bb2dd
Merge pull request #78 from jdhao/theme
refactor: theme.vim --> theme.lua
2022-08-26 18:44:11 +08:00
jdhao
59525c5577 refactor: theme.vim --> theme.lua 2022-08-26 18:42:30 +08:00
jdhao
6539e72a5d
Merge pull request #75 from jdhao/typo-fix
fix some typos
2022-08-23 21:12:50 +08:00
jdhao
b279c0cd95 fix some typos 2022-08-23 21:12:04 +08:00
jdhao
96129335ad
Merge pull request #74 from jdhao/delimitMate
update delimitMate conf for lua
2022-08-23 13:19:52 +08:00
jdhao
b6fa0b7aa5 update delimitMate conf for lua 2022-08-23 13:19:02 +08:00
jdhao
dff469ddc4 spell 2022-08-22 21:03:37 +08:00
jdhao
6d5cda0f97
Merge pull request #73 from jdhao/bufferline
update bufferline.nvim conf
2022-08-22 21:00:14 +08:00
jdhao
4d35362e83 update bufferline.nvim conf 2022-08-22 20:59:26 +08:00
jdhao
e57e747b26
Merge pull request #72 from jdhao/lua-au-ctx
refactor: use ctx table for lua autocmd callback
2022-08-21 18:21:22 +08:00
jdhao
c3f8d75ece refactor: use ctx table for lua autocmd callback 2022-08-21 18:20:21 +08:00
jdhao
78baf8d015
Merge pull request #71 from jdhao/snip
update markdown snippet
2022-08-21 11:48:15 +08:00
jdhao
9d8a58be17 update markdown snippet 2022-08-21 11:47:03 +08:00
jdhao
2372d9159f
Merge pull request #70 from jdhao/lua-autuocmd
refactor: move part of autocmd to lua script
2022-08-20 02:02:12 -05:00
jdhao
e9a3d16260 refactor: move part of autocmd to lua script 2022-08-20 15:00:10 +08:00
jdhao
fdf8236fc2
Merge pull request #69 from jdhao/fix-autocmd
update the autocmd for saving a file
2022-08-20 00:52:33 -05:00
jdhao
085c8017d8 update the autocmd for saving a file 2022-08-20 13:50:23 +08:00
jdhao
efa7b215e7
Merge pull request #68 from jdhao/install-win
update install script for Windows
2022-08-19 07:06:43 -05:00
jdhao
e68c687f23 update install script for Windows 2022-08-19 20:05:40 +08:00
jdhao
497f93d6c7
Merge pull request #67 from jdhao/packer-autoinstall
feat: auto-install plugins for fresh install
2022-08-18 11:43:49 -05:00
jdhao
cfe2e0611d feat: auto-install plugins for fresh install 2022-08-19 00:42:02 +08:00
jdhao
9de08d0afe
Merge pull request #66 from jdhao/lsp
add config dir to workspace.library for lua lsp
2022-08-18 13:16:51 +08:00
jdhao
d5b7584e68 add config dir to workspace.library for lua lsp 2022-08-18 13:15:20 +08:00
jdhao
64a7a23309
Merge pull request #64 from jdhao/fix-firenvim
update firenvim conf
2022-08-15 22:57:50 +08:00
jdhao
c1efc0bad6 update firenvim conf 2022-08-15 22:56:56 +08:00
jdhao
b3b69f21f4 update mapping 2022-08-15 00:22:24 +08:00
jdhao
f491e26676
Merge pull request #63 from jdhao/large-file
handle large file better
2022-08-15 00:08:16 +08:00
jdhao
e7e4892c22 handle large file better 2022-08-15 00:06:52 +08:00
jdhao
a52a362b02 update version check 2022-08-14 22:54:19 +08:00
jdhao
2880d7bce3 chore: renaming 2022-08-14 20:16:00 +08:00
jdhao
7e6dd23d37 add fidget-nvim for lsp-progress 2022-08-14 20:12:52 +08:00
jdhao
fcbd7d3a0d
Merge pull request #62 from jdhao/lua-lsp
update lua lsp conf
2022-08-14 18:11:41 +08:00
jdhao
97f302084f update sumneko lua settings
1. remove runtime.path settings. It seems that it is not necessary, 03a047ef52.
2. update workspace.library, ref plugin ii14/emmylua-nvim
2022-08-14 17:53:40 +08:00
jdhao
9d29544d72 update linux setup script
1. lua-language-server
2. format fix
2022-08-14 12:01:38 +08:00
jdhao
cad9f5a214 make inspect() global 2022-08-14 11:39:37 +08:00
jdhao
ecde08941b update lua-language-server conf
lua-language-server has changed its running method significantly, so we
need to change it in the nvim-lspconfig.
2022-08-13 23:08:25 +08:00
jdhao
ab88c112ff make dashboard-nvim an opt plugin 2022-08-13 23:03:42 +08:00
jdhao
4c96243a4c init.vim --> init.lua cleanup 2022-08-13 22:45:13 +08:00
jdhao
fdc158272b init.vim --> init.lua follow 2022-08-13 22:43:33 +08:00
jdhao
b331cddc73
Merge pull request #61 from jdhao/init.lua
Transition from init.vim to init.lua
2022-08-13 22:39:47 +08:00
jdhao
b11c57e36f Transition from init.vim to init.lua 2022-08-13 22:37:49 +08:00
jdhao
84d73660fa add stylua conf 2022-08-13 17:12:08 +08:00
jdhao
a9cc10b2ef
Merge pull request #60 from jdhao/doc
update setup doc
2022-08-12 20:32:48 +08:00
jdhao
cad6112cc2 update setup doc 2022-08-12 20:31:32 +08:00
48 changed files with 1279 additions and 925 deletions

6
.stylua.toml Normal file
View File

@ -0,0 +1,6 @@
# config for stylua, ref: https://github.com/JohnnyMorganz/StyLua
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
call_parentheses= "NoSingleTable"

View File

@ -36,7 +36,7 @@
# Introduction # Introduction
This repo hosts my Nvim configuration for Linux, macOS, and Windows. This repo hosts my Nvim configuration for Linux, macOS, and Windows.
`init.vim` is the config entry point for terminal Nvim, `init.lua` is the config entry point for terminal Nvim,
and `ginit.vim` is the additional config file for [GUI client of Nvim](https://github.com/neovim/neovim/wiki/Related-projects#gui). and `ginit.vim` is the additional config file for [GUI client of Nvim](https://github.com/neovim/neovim/wiki/Related-projects#gui).
My configurations are heavily documented to make it as clear as possible. My configurations are heavily documented to make it as clear as possible.
@ -74,7 +74,7 @@ and how to set up on different platforms (Linux, macOS, and Windows).
+ Asynchronous code execution via [asyncrun.vim](https://github.com/skywind3000/asyncrun.vim). + Asynchronous code execution via [asyncrun.vim](https://github.com/skywind3000/asyncrun.vim).
+ Code highlighting via [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter). + Code highlighting via [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter).
+ Code editing using true nvim inside browser via [firenvim](https://github.com/glacambre/firenvim). + Code editing using true nvim inside browser via [firenvim](https://github.com/glacambre/firenvim).
+ Color theme via [vim-gruvbox8](https://github.com/lifepillar/vim-gruvbox8) and other beautiful themes. + Beautiful colorscheme via [sainnhe/gruvbox-material](https://github.com/sainnhe/gruvbox-material) and other colorschemes.
+ Markdown writing and previewing via [vim-markdown](https://github.com/plasticboy/vim-markdown) and [markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim). + Markdown writing and previewing via [vim-markdown](https://github.com/plasticboy/vim-markdown) and [markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim).
+ LaTeX editing and previewing via [vimtex](https://github.com/lervag/vimtex) <sup id="a1">[1](#f1)</sup>. + LaTeX editing and previewing via [vimtex](https://github.com/lervag/vimtex) <sup id="a1">[1](#f1)</sup>.
+ Animated GUI style notification via [nvim-notify](https://github.com/rcarriga/nvim-notify). + Animated GUI style notification via [nvim-notify](https://github.com/rcarriga/nvim-notify).

View File

@ -8,3 +8,6 @@ set shiftwidth=2 " number of spaces to use for autoindent
set expandtab " expand tab to spaces so that tabs are spaces set expandtab " expand tab to spaces so that tabs are spaces
nnoremap <silent> <F9> :luafile %<CR> nnoremap <silent> <F9> :luafile %<CR>
" For delimitMate
let b:delimitMate_matchpairs = "(:),[:],{:}"

View File

@ -15,7 +15,7 @@ function! buf_utils#GoToBuffer(count, direction) abort
" we are essentially mixing Lua and vim script. We need to make sure that " we are essentially mixing Lua and vim script. We need to make sure that
" args inside vim.notify() are valid vim values. The conversion from vim " args inside vim.notify() are valid vim values. The conversion from vim
" value to lua value will be done by Nvim. See also https://github.com/neovim/neovim/pull/11338. " value to lua value will be done by Nvim. See also https://github.com/neovim/neovim/pull/11338.
call v:lua.vim.notify('Invalid bufnr: ' . a:count, 'error', {'title': 'nvim-config'}) call v:lua.vim.notify('Invalid bufnr: ' . a:count, 4, {'title': 'nvim-config'})
return return
endif endif

View File

@ -27,21 +27,6 @@ function! utils#HasColorscheme(name) abort
return !empty(globpath(&runtimepath, l:pat)) return !empty(globpath(&runtimepath, l:pat))
endfunction endfunction
" Generate random integers in the range [Low, High] in pure vim script,
" adapted from https://stackoverflow.com/a/12739441/6064933
function! utils#RandInt(Low, High) abort
" Use lua to generate random int. It is faster. Ref: https://stackoverflow.com/a/20157671/6064933
call v:lua.math.randomseed(localtime())
return v:lua.math.random(a:Low, a:High)
endfunction
" Selection a random element from a sequence/list
function! utils#RandElement(seq) abort
let l:idx = utils#RandInt(0, len(a:seq)-1)
return a:seq[l:idx]
endfunction
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292 " Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
function! utils#VimFolds(lnum) abort function! utils#VimFolds(lnum) abort
" get content of current line and the line below " get content of current line and the line below
@ -156,7 +141,7 @@ function! utils#Inside_git_repo() abort
if match(res, 'true') == -1 if match(res, 'true') == -1
return v:false return v:false
else else
" Manually trigger a specical user autocmd InGitRepo (to use it for " Manually trigger a special user autocmd InGitRepo (to use it for
" lazyloading of fugitive by packer.nvim). " lazyloading of fugitive by packer.nvim).
" See also https://github.com/wbthomason/packer.nvim/discussions/534. " See also https://github.com/wbthomason/packer.nvim/discussions/534.
doautocmd User InGitRepo doautocmd User InGitRepo
@ -198,14 +183,3 @@ function! utils#MultiEdit(patterns) abort
endfor endfor
endfor endfor
endfunction endfunction
function! utils#add_pack(name) abort
let l:status = v:true
try
execute printf("packadd! %s", a:name)
catch /^Vim\%((\a\+)\)\=:E919/
let l:status = v:false
endtry
return l:status
endfunction

View File

@ -41,26 +41,6 @@ function s:resume_cursor_position() abort
endif endif
endfunction endfunction
" Display a message when the current file is not in utf-8 format.
" Note that we need to use `unsilent` command here because of this issue:
" https://github.com/vim/vim/issues/4379
augroup non_utf8_file_warn
autocmd!
" we can not use `lua vim.notify()`: it will error out E5107 parsing lua.
autocmd BufRead * if &fileencoding != 'utf-8' | call v:lua.vim.notify('File not in UTF-8 format!', 'warn', {'title': 'nvim-config'}) | endif
augroup END
" Automatically reload the file if it is changed outside of Nvim, see
" https://unix.stackexchange.com/a/383044/221410. It seems that `checktime`
" command does not work in command line. We need to check if we are in command
" line before executing this command. See also
" https://vi.stackexchange.com/a/20397/15292.
augroup auto_read
autocmd!
autocmd FileChangedShellPost * call v:lua.vim.notify("File changed on disk. Buffer reloaded!", 'warn', {'title': 'nvim-config'})
autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
augroup END
augroup numbertoggle augroup numbertoggle
autocmd! autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
@ -88,12 +68,6 @@ function! s:custom_highlight() abort
highlight MatchParen cterm=bold,underline gui=bold,underline highlight MatchParen cterm=bold,underline gui=bold,underline
endfunction endfunction
" highlight yanked region, see `:h lua-highlight`
augroup highlight_yank
autocmd!
au TextYankPost * silent! lua vim.highlight.on_yank{higroup="YankColor", timeout=300, on_visual=false}
augroup END
augroup auto_close_win augroup auto_close_win
autocmd! autocmd!
autocmd BufEnter * call s:quit_current_win() autocmd BufEnter * call s:quit_current_win()
@ -125,13 +99,25 @@ augroup git_repo_check
autocmd VimEnter,DirChanged * call utils#Inside_git_repo() autocmd VimEnter,DirChanged * call utils#Inside_git_repo()
augroup END augroup END
" Auto-generate packer_compiled.lua file " ref: https://vi.stackexchange.com/a/169/15292
augroup packer_auto_compile function! s:handle_large_file() abort
let g:large_file = 10485760 " 10MB
let f = expand("<afile>")
if getfsize(f) > g:large_file || getfsize(f) == -2
set eventignore+=all
" turning off relative number helps a lot
set norelativenumber
setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1
else
set eventignore-=all relativenumber
endif
endfunction
augroup LargeFile
autocmd! autocmd!
autocmd BufWritePost */nvim/lua/plugins.lua source <afile> | PackerCompile autocmd BufReadPre * call s:handle_large_file()
augroup END augroup END
augroup auto_create_dir " Load auto-command defined in Lua
autocmd! lua require("custom-autocmd")
autocmd BufWritePre * lua require('utils').may_create_dir()
augroup END

123
core/colorschemes.lua Normal file
View File

@ -0,0 +1,123 @@
--- This module will load a random colorscheme on nvim startup process.
local utils = require("utils")
local M = {}
-- Colorscheme to its directory name mapping, because colorscheme repo name is not necessarily
-- the same as the colorscheme name itself.
M.colorscheme2dir = {
gruvbox8 = "vim-gruvbox8",
onedark = "onedark.nvim",
edge = "edge",
sonokai = "sonokai",
gruvbox_material = "gruvbox-material",
nord = "nord.nvim",
doom_one = "doom-one.nvim",
everforest = "everforest",
nightfox = "nightfox.nvim",
kanagawa = "kanagawa.nvim",
catppuccin = "catppuccin",
}
M.gruvbox8 = function()
-- Italic options should be put before colorscheme setting,
-- see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled
vim.g.gruvbox_italics = 1
vim.g.gruvbox_italicize_strings = 1
vim.g.gruvbox_filetype_hi_groups = 1
vim.g.gruvbox_plugin_hi_groups = 1
vim.cmd([[colorscheme gruvbox8_hard]])
end
M.onedark = function()
vim.cmd([[colorscheme onedark]])
end
M.edge = function()
vim.g.edge_enable_italic = 1
vim.g.edge_better_performance = 1
vim.cmd([[colorscheme edge]])
end
M.sonokai = function()
vim.g.sonokai_enable_italic = 1
vim.g.sonokai_better_performance = 1
vim.cmd([[colorscheme sonokai]])
end
M.gruvbox_material = function()
vim.g.gruvbox_material_enable_italic = 1
vim.g.gruvbox_material_better_performance = 1
vim.cmd([[colorscheme gruvbox-material]])
end
M.nord = function()
vim.cmd([[colorscheme nord]])
end
M.doom_one = function()
vim.cmd([[colorscheme doom-one]])
end
M.everforest = function()
vim.g.everforest_enable_italic = 1
vim.g.everforest_better_performance = 1
vim.cmd([[colorscheme everforest]])
end
M.nightfox = function()
vim.cmd([[colorscheme nordfox]])
end
M.kanagawa = function()
vim.cmd([[colorscheme kanagawa]])
end
M.catppuccin = function()
-- available option: latte, frappe, macchiato, mocha
vim.g.catppuccin_flavour = "frappe"
require("catppuccin").setup()
vim.cmd([[colorscheme catppuccin]])
end
--- Use a random colorscheme from the pre-defined list of colorschemes.
M.rand_colorscheme = function()
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme2dir))
if not vim.tbl_contains(vim.tbl_keys(M), colorscheme) then
local msg = "Invalid colorscheme: " .. colorscheme
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
return
end
-- Load the colorscheme, because all the colorschemes are declared as opt plugins, so the colorscheme isn't loaded yet.
local status = utils.add_pack(M.colorscheme2dir[colorscheme])
if not status then
local msg = string.format("Colorscheme %s is not installed. Run PackerSync to install.", colorscheme)
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
return
end
-- Load the colorscheme and its settings
M[colorscheme]()
if vim.g.logging_level == "debug" then
local msg = "Colorscheme: " .. colorscheme
vim.notify(msg, vim.log.levels.DEBUG, { title = "nvim-config" })
end
end
-- Load a random colorscheme
M.rand_colorscheme()

81
core/globals.lua Normal file
View File

@ -0,0 +1,81 @@
local fn = vim.fn
local api = vim.api
local utils = require('utils')
-- Inspect something
function _G.inspect(item)
vim.pretty_print(item)
end
------------------------------------------------------------------------
-- custom variables --
------------------------------------------------------------------------
vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false
vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false
vim.g.is_mac = utils.has("macunix") and true or false
vim.g.logging_level = "info"
------------------------------------------------------------------------
-- builtin variables --
------------------------------------------------------------------------
vim.g.loaded_perl_provider = 0 -- Disable perl provider
vim.g.loaded_ruby_provider = 0 -- Disable ruby provider
vim.g.loaded_node_provider = 0 -- Disable node provider
vim.g.did_install_default_menus = 1 -- do not load menu
if utils.executable('python3') then
if vim.g.is_win then
vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", '', 'g')
else
vim.g.python3_host_prog = fn.exepath("python3")
end
else
api.nvim_err_writeln("Python3 executable not found! You must install Python3 and set its PATH correctly!")
return
end
-- Custom mapping <leader> (see `:h mapleader` for more info)
vim.g.mapleader = ','
-- Enable highlighting for lua HERE doc inside vim script
vim.g.vimsyn_embed = 'l'
-- Use English as main language
if not vim.g.is_mac then
vim.cmd [[language en_US.utf-8]]
end
-- use filetype.lua instead of filetype.vim
vim.g.do_filetype_lua = 1
vim.g.did_load_filetypes = 0
-- Disable loading certain plugins
-- Whether to load netrw by default, see https://github.com/bling/dotvim/issues/4
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.g.netrw_liststyle = 3
if vim.g.is_win then
vim.g.netrw_http_cmd = "curl --ssl-no-revoke -Lo"
end
-- Do not load tohtml.vim
vim.g.loaded_2html_plugin = 1
-- Do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all these plugins are
-- related to checking files inside compressed files)
vim.g.loaded_zipPlugin = 1
vim.g.loaded_gzip = 1
vim.g.loaded_tarPlugin = 1
-- Do not load the tutor plugin
vim.g.loaded_tutor_mode_plugin = 1
-- Do not use builtin matchit.vim and matchparen.vim since we use vim-matchup
vim.g.loaded_matchit = 1
vim.g.loaded_matchparen = 1
-- Disable sql omni completion, it is broken.
vim.g.loaded_sql_completion = 1

View File

@ -1,77 +0,0 @@
"{ Global Variable
"{{ Custom variables
let g:is_win = (has('win32') || has('win64')) ? v:true : v:false
let g:is_linux = (has('unix') && !has('macunix')) ? v:true : v:false
let g:is_mac = has('macunix') ? v:true : v:false
let g:logging_level = 'info'
"}}
"{{ Builtin variables
" Disable perl provider
let g:loaded_perl_provider = 0
" Disable ruby provider
let g:loaded_ruby_provider = 0
" Disable node provider
let g:loaded_node_provider = 0
let g:did_install_default_menus = 1 " do not load menu
" Path to Python 3 interpreter (must be an absolute path), make startup
" faster. See https://neovim.io/doc/user/provider.html.
if executable('python')
if g:is_win
let g:python3_host_prog=substitute(exepath('python'), '.exe$', '', 'g')
elseif g:is_linux || g:is_mac
let g:python3_host_prog=exepath('python')
endif
else
echoerr 'Python 3 executable not found! You must install Python 3 and set its PATH correctly!'
endif
" Custom mapping <leader> (see `:h mapleader` for more info)
let g:mapleader = ','
" Enable highlighting for lua HERE doc inside vim script
let g:vimsyn_embed = 'l'
" Use English as main language
if !g:is_mac
language en_US.utf-8
endif
" use filetype.lua instead of filetype.vim
let g:do_filetype_lua = 1
let g:did_load_filetypes = 0
"}}
"{{ Disable loading certain plugins
" Whether to load netrw by default, see
" https://github.com/bling/dotvim/issues/4
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:netrw_liststyle = 3
if g:is_win
let g:netrw_http_cmd = 'curl --ssl-no-revoke -Lo'
endif
" Do not load tohtml.vim
let g:loaded_2html_plugin = 1
" Do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all these plugins are
" related to checking files inside compressed files)
let g:loaded_zipPlugin = 1
let loaded_gzip = 1
let g:loaded_tarPlugin = 1
let g:loaded_tutor_mode_plugin = 1 " do not load the tutor plugin
" Do not use builtin matchit.vim and matchparen.vim since we use vim-matchup
let g:loaded_matchit = 1
let g:loaded_matchparen = 1
"}}
" Disable sql omni completion, it is broken.
let g:loaded_sql_completion = 1
"}

228
core/mappings.lua Normal file
View File

@ -0,0 +1,228 @@
local keymap = vim.keymap
local api = vim.api
-- Save key strokes (now we do not need to press shift to enter command mode).
keymap.set({ "n", "x" }, ";", ":")
-- Turn the word under cursor to upper case
keymap.set("i", "<c-u>", "<Esc>viwUea")
-- Turn the current word into title case
keymap.set("i", "<c-t>", "<Esc>b~lea")
-- Paste non-linewise text above or below current line, see https://stackoverflow.com/a/1346777/6064933
keymap.set("n", "<leader>p", "m`o<ESC>p``", { desc = "paste below current line" })
keymap.set("n", "<leader>P", "m`O<ESC>p``", { desc = "paste above current line" })
-- Shortcut for faster save and quit
keymap.set("n", "<leader>w", "<cmd>update<cr>", { silent = true, desc = "save buffer" })
-- Saves the file if modified and quit
keymap.set("n", "<leader>q", "<cmd>x<cr>", { silent = true, desc = "quit current window" })
-- Quit all opened buffers
keymap.set("n", "<leader>Q", "<cmd>qa!<cr>", { silent = true, desc = "quit nvim" })
-- Navigation in the location and quickfix list
keymap.set("n", "[l", "<cmd>lprevious<cr>zv", { silent = true, desc = "previous location item" })
keymap.set("n", "]l", "<cmd>lnext<cr>zv", { silent = true, desc = "next location item" })
keymap.set("n", "[L", "<cmd>lfirst<cr>zv", { silent = true, desc = "first location item" })
keymap.set("n", "]L", "<cmd>llast<cr>zv", { silent = true, desc = "last location item" })
keymap.set("n", "[q", "<cmd>cprevious<cr>zv", { silent = true, desc = "previous qf item" })
keymap.set("n", "]q", "<cmd>cnext<cr>zv", { silent = true, desc = "next qf item" })
keymap.set("n", "[Q", "<cmd>cfirst<cr>zv", { silent = true, desc = "first qf item" })
keymap.set("n", "]Q", "<cmd>clast<cr>zv", { silent = true, desc = "last qf item" })
-- Close location list or quickfix list if they are present, see https://superuser.com/q/355325/736190
keymap.set("n", [[\x]], "<cmd>windo lclose <bar> cclose <cr>", {
silent = true,
desc = "close qf and location list",
})
-- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933
keymap.set("n", [[\d]], "<cmd>bprevious <bar> bdelete #<cr>", {
silent = true,
desc = "delete buffer",
})
-- Insert a blank line below or above current line (do not move the cursor),
-- see https://stackoverflow.com/a/16136133/6064933
keymap.set("n", "<space>o", "printf('m`%so<ESC>``', v:count1)", {
expr = true,
desc = "insert line below",
})
keymap.set("n", "<space>O", "printf('m`%sO<ESC>``', v:count1)", {
expr = true,
desc = "insert line above",
})
-- Move the cursor based on physical lines, not the actual lines.
keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true })
keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true })
keymap.set("n", "^", "g^")
keymap.set("n", "0", "g0")
-- Do not include white space characters when using $ in visual mode,
-- see https://vi.stackexchange.com/q/12607/15292
keymap.set("x", "$", "g_")
-- Go to start or end of line easier
keymap.set({ "n", "x" }, "H", "^")
keymap.set({ "n", "x" }, "L", "g_")
-- Continuous visual shifting (does not exit Visual mode), `gv` means
-- to reselect previous visual area, see https://superuser.com/q/310417/736190
keymap.set("x", "<", "<gv")
keymap.set("x", ">", ">gv")
-- Edit and reload nvim config file quickly
keymap.set("n", "<leader>ev", "<cmd>tabnew $MYVIMRC <bar> tcd %:h<cr>", {
silent = true,
desc = "open init.lua",
})
keymap.set("n", "<leader>sv", "", {
silent = true,
desc = "reload init.lua",
callback = function()
vim.cmd([[
update $MYVIMRC
source $MYVIMRC
]])
vim.notify("Nvim config successfully reloaded!", vim.log.levels.INFO, { title = "nvim-config" })
end,
})
-- Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933.
keymap.set("n", "<leader>v", "printf('`[%s`]', getregtype()[0])", {
expr = true,
desc = "reselect last pasted area",
})
-- Always use very magic mode for searching
keymap.set("n", "/", [[/\v]])
-- Search in selected region
-- xnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>
-- Change current working directory locally and print cwd after that,
-- see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file
keymap.set("n", "<leader>cd", "<cmd>lcd %:p:h<cr><cmd>pwd<cr>", { desc = "change cwd" })
-- Use Esc to quit builtin terminal
keymap.set("t", "<Esc>", [[<c-\><c-n>]])
-- Toggle spell checking
keymap.set("n", "<F11>", "<cmd>set spell!<cr>", { desc = "toggle spell" })
keymap.set("i", "<F11>", "<c-o><cmd>set spell!<cr>", { desc = "toggle spell" })
-- Change text without putting it into the vim register,
-- see https://stackoverflow.com/q/54255/6064933
keymap.set("n", "c", '"_c')
keymap.set("n", "C", '"_C')
keymap.set("n", "cc", '"_cc')
keymap.set("x", "c", '"_c')
-- Remove trailing whitespace characters
keymap.set("n", "<leader><space>", "<cmd>StripTrailingWhitespace<cr>", { desc = "remove trailing space" })
-- check the syntax group of current cursor position
keymap.set("n", "<leader>st", "<cmd>call utils#SynGroup()<cr>", { desc = "check syntax group" })
-- Copy entire buffer.
keymap.set("n", "<leader>y", "<cmd>%yank<cr>", { desc = "yank entire buffer" })
-- Toggle cursor column
keymap.set("n", "<leader>cl", "<cmd>call utils#ToggleCursorCol()<cr>", { desc = "toggle cursor column" })
-- Move current line up and down
keymap.set("n", "<A-k>", '<cmd>call utils#SwitchLine(line("."), "up")<cr>', { desc = "move line up" })
keymap.set("n", "<A-j>", '<cmd>call utils#SwitchLine(line("."), "down")<cr>', { desc = "move line down" })
-- Move current visual-line selection up and down
keymap.set("x", "<A-k>", '<cmd>call utils#MoveSelection("up")<cr>', { desc = "move selection up" })
keymap.set("x", "<A-j>", '<cmd>call utils#MoveSelection("down")<cr>', { desc = "move selection down" })
-- Replace visual selection with text in register, but not contaminate the register,
-- see also https://stackoverflow.com/q/10723700/6064933.
keymap.set("x", "p", '"_c<Esc>p')
-- Go to a certain buffer
keymap.set("n", "gb", '<cmd>call buf_utils#GoToBuffer(v:count, "forward")<cr>', {
desc = "go to buffer (forward)",
})
keymap.set("n", "gB", '<cmd>call buf_utils#GoToBuffer(v:count, "backward")<cr>', {
desc = "go to buffer (backward)",
})
-- Switch windows
keymap.set("n", "<left>", "<c-w>h")
keymap.set("n", "<Right>", "<C-W>l")
keymap.set("n", "<Up>", "<C-W>k")
keymap.set("n", "<Down>", "<C-W>j")
-- Text objects for URL
keymap.set({ "x", "o" }, "iu", "<cmd>call text_obj#URL()<cr>", { desc = "URL text object" })
-- Text objects for entire buffer
keymap.set({ "x", "o" }, "iB", "<cmd>call text_obj#Buffer()<cr>", { desc = "buffer text object" })
-- Do not move my cursor when joining lines.
keymap.set("n", "J", "", {
desc = "join line",
callback = function()
vim.cmd([[
normal! mzJ`z
delmarks z
]])
end,
})
keymap.set("n", "gJ", "mzgJ`z", {
desc = "join visual lines",
callback = function()
-- we must use `normal!`, otherwise it will trigger recursive mapping
vim.cmd([[
normal! zmgJ`z
delmarks z
]])
end,
})
-- Break inserted text into smaller undo units when we insert some punctuation chars.
local undo_ch = { ",", ".", "!", "?", ";", ":" }
for _, ch in ipairs(undo_ch) do
keymap.set("i", ch, ch .. "<c-g>u")
end
-- insert semicolon in the end
keymap.set("i", "<A-;>", "<Esc>miA;<Esc>`ii")
-- Keep cursor position after yanking
keymap.set("n", "y", "myy")
api.nvim_create_autocmd("TextYankPost", {
pattern = "*",
group = api.nvim_create_augroup("restore_after_yank", { clear = true }),
callback = function()
vim.cmd([[
silent! normal! `y
silent! delmarks y
]])
end,
})
-- Go to the beginning and end of current line in insert mode quickly
keymap.set("i", "<C-A>", "<HOME>")
keymap.set("i", "<C-E>", "<END>")
-- Go to beginning of command in command-line mode
keymap.set("c", "<C-A>", "<HOME>")
-- Delete the character to the right of the cursor
keymap.set("i", "<C-D>", "<DEL>")

View File

@ -1,195 +0,0 @@
" Save key strokes (now we do not need to press shift to enter command mode).
" Vim-sneak has also mapped `;`, so using the below mapping will break the map
" used by vim-sneak
nnoremap ; :
xnoremap ; :
" Quicker way to open command window
nnoremap q; q:
" Turn the word under cursor to upper case
inoremap <c-u> <Esc>viwUea
" Turn the current word into title case
inoremap <c-t> <Esc>b~lea
" Paste non-linewise text above or below current cursor,
" see https://stackoverflow.com/a/1346777/6064933
nnoremap <leader>p m`o<ESC>p``
nnoremap <leader>P m`O<ESC>p``
" Shortcut for faster save and quit
nnoremap <silent> <leader>w :<C-U>update<CR>
" Saves the file if modified and quit
nnoremap <silent> <leader>q :<C-U>x<CR>
" Quit all opened buffers
nnoremap <silent> <leader>Q :<C-U>qa!<CR>
" Navigation in the location and quickfix list
nnoremap <silent> [l :<C-U>lprevious<CR>zv
nnoremap <silent> ]l :<C-U>lnext<CR>zv
nnoremap <silent> [L :<C-U>lfirst<CR>zv
nnoremap <silent> ]L :<C-U>llast<CR>zv
nnoremap <silent> [q :<C-U>cprevious<CR>zv
nnoremap <silent> ]q :<C-U>cnext<CR>zv
nnoremap <silent> [Q :<C-U>cfirst<CR>zv
nnoremap <silent> ]Q :<C-U>clast<CR>zv
" Close location list or quickfix list if they are present,
" see https://superuser.com/q/355325/736190
nnoremap<silent> \x :<C-U>windo lclose <bar> cclose<CR>
" Close a buffer and switching to another buffer, do not close the
" window, see https://stackoverflow.com/q/4465095/6064933
nnoremap <silent> \d :<C-U>bprevious <bar> bdelete #<CR>
" Insert a blank line below or above current line (do not move the cursor),
" see https://stackoverflow.com/a/16136133/6064933
nnoremap <expr> <Space>o printf('m`%so<ESC>``', v:count1)
nnoremap <expr> <Space>O printf('m`%sO<ESC>``', v:count1)
" Insert a space after current character
nnoremap <Space><Space> a<Space><ESC>h
" Move the cursor based on physical lines, not the actual lines.
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap ^ g^
nnoremap 0 g0
" Do not include white space characters when using $ in visual mode,
" see https://vi.stackexchange.com/q/12607/15292
xnoremap $ g_
" Jump to matching pairs easily in normal mode
nnoremap <Tab> %
" Go to start or end of line easier
nnoremap H ^
xnoremap H ^
nnoremap L g_
xnoremap L g_
" Continuous visual shifting (does not exit Visual mode), `gv` means
" to reselect previous visual area, see https://superuser.com/q/310417/736190
xnoremap < <gv
xnoremap > >gv
" When completion menu is shown, use <cr> to select an item and do not add an
" annoying newline. Otherwise, <enter> is what it is. For more info , see
" https://superuser.com/a/941082/736190 and
" https://unix.stackexchange.com/q/162528/221410
" inoremap <expr> <cr> ((pumvisible())?("\<C-Y>"):("\<cr>"))
" Use <esc> to close auto-completion menu
" inoremap <expr> <esc> ((pumvisible())?("\<C-e>"):("\<esc>"))
" Tab-complete, see https://vi.stackexchange.com/q/19675/15292.
inoremap <expr> <tab> pumvisible() ? "\<c-n>" : "\<tab>"
inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
" Edit and reload init.vim quickly
nnoremap <silent> <leader>ev :<C-U>tabnew $MYVIMRC <bar> tcd %:h<cr>
nnoremap <silent> <leader>sv :<C-U>silent update $MYVIMRC <bar> source $MYVIMRC <bar>
\ call v:lua.vim.notify("Nvim config successfully reloaded!", 'info', {'title': 'nvim-config'})<cr>
" Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933.
nnoremap <expr> <leader>v printf('`[%s`]', getregtype()[0])
" Always use very magic mode for searching
nnoremap / /\v
" Search in selected region
xnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>
" Change current working directory locally and print cwd after that,
" see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file
nnoremap <silent> <leader>cd :<C-U>lcd %:p:h<CR>:pwd<CR>
" Use Esc to quit builtin terminal
tnoremap <ESC> <C-\><C-n>
" Toggle spell checking (autosave does not play well with z=, so we disable it
" when we are doing spell checking)
nnoremap <silent> <F11> :<C-U>set spell!<cr>
inoremap <silent> <F11> <C-O>:<C-U>set spell!<cr>
" Change text without putting it into the vim register,
" see https://stackoverflow.com/q/54255/6064933
nnoremap c "_c
nnoremap C "_C
nnoremap cc "_cc
xnoremap c "_c
" Remove trailing whitespace characters
nnoremap <silent> <leader><Space> :<C-U>StripTrailingWhitespace<CR>
" check the syntax group of current cursor position
nnoremap <silent> <leader>st :<C-U>call utils#SynGroup()<CR>
" Clear highlighting
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :<C-U>nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
" Copy entire buffer.
nnoremap <silent> <leader>y :<C-U>%y<CR>
" Toggle cursor column
nnoremap <silent> <leader>cl :<C-U>call utils#ToggleCursorCol()<CR>
" Move current line up and down
nnoremap <silent> <A-k> <Cmd>call utils#SwitchLine(line('.'), 'up')<CR>
nnoremap <silent> <A-j> <Cmd>call utils#SwitchLine(line('.'), 'down')<CR>
" Move current visual-line selection up and down
xnoremap <silent> <A-k> :<C-U>call utils#MoveSelection('up')<CR>
xnoremap <silent> <A-j> :<C-U>call utils#MoveSelection('down')<CR>
" Replace visual selection with text in register, but not contaminate the
" register, see also https://stackoverflow.com/q/10723700/6064933.
xnoremap p "_c<ESC>p
nnoremap <silent> gb :<C-U>call buf_utils#GoToBuffer(v:count, 'forward')<CR>
nnoremap <silent> gB :<C-U>call buf_utils#GoToBuffer(v:count, 'backward')<CR>
nnoremap <Left> <C-W>h
nnoremap <Right> <C-W>l
nnoremap <Up> <C-W>k
nnoremap <Down> <C-W>j
" Text objects for URL
xnoremap <silent> iu :<C-U>call text_obj#URL()<CR>
onoremap <silent> iu :<C-U>call text_obj#URL()<CR>
" Text objects for entire buffer
xnoremap <silent> iB :<C-U>call text_obj#Buffer()<CR>
onoremap <silent> iB :<C-U>call text_obj#Buffer()<CR>
" Do not move my cursor when joining lines.
nnoremap J mzJ`z
nnoremap gJ mzgJ`z
" Break inserted text into smaller undo units.
for ch in [',', '.', '!', '?', ';', ':']
execute printf('inoremap %s %s<C-g>u', ch, ch)
endfor
" insert semicolon in the end
inoremap <A-;> <ESC>miA;<ESC>`ii
" Keep cursor position after yanking
nnoremap y myy
xnoremap y myy
augroup restore_after_yank
autocmd!
autocmd TextYankPost * call s:restore_cursor()
augroup END
function! s:restore_cursor() abort
silent! normal `y
silent! delmarks y
endfunction
" for mappings defined in lua
lua require('custom-map')

View File

@ -177,3 +177,4 @@ set diffopt+=context:3 " context for diff
set diffopt+=internal,indent-heuristic,algorithm:histogram set diffopt+=internal,indent-heuristic,algorithm:histogram
set nowrap " do no wrap set nowrap " do no wrap
set noruler

View File

@ -1,7 +1,7 @@
scriptencoding utf-8 scriptencoding utf-8
" Plugin specification and lua stuff " Plugin specification and lua stuff
lua require('lua-init') lua require('plugins')
" Use short names for common plugin manager commands to simplify typing. " Use short names for common plugin manager commands to simplify typing.
" To use these shortcuts: first activate command line with `:`, then input the " To use these shortcuts: first activate command line with `:`, then input the
@ -189,15 +189,6 @@ let g:signify_vcs_list = [ 'git' ]
" Change the sign for certain operations " Change the sign for certain operations
let g:signify_sign_change = '~' let g:signify_sign_change = '~'
"""""""""""""""""""""""""vim-fugitive settings""""""""""""""""""""""""""""""
nnoremap <silent> <leader>gs :Git<CR>
nnoremap <silent> <leader>gw :Gwrite<CR>
nnoremap <silent> <leader>gc :Git commit<CR>
nnoremap <silent> <leader>gd :Gdiffsplit<CR>
nnoremap <silent> <leader>gpl :Git pull<CR>
" Note that to use bar literally, we need backslash it, see also `:h :bar`.
nnoremap <silent> <leader>gpu :15split \| term git push<CR>
"""""""""""""""""""""""""plasticboy/vim-markdown settings""""""""""""""""""" """""""""""""""""""""""""plasticboy/vim-markdown settings"""""""""""""""""""
" Disable header folding " Disable header folding
let g:vim_markdown_folding_disabled = 1 let g:vim_markdown_folding_disabled = 1
@ -260,7 +251,7 @@ omap s <Nop>
""""""""""""""""""""""""""""vimtex settings""""""""""""""""""""""""""""" """"""""""""""""""""""""""""vimtex settings"""""""""""""""""""""""""""""
if ( g:is_win || g:is_mac ) && executable('latex') if ( g:is_win || g:is_mac ) && executable('latex')
" Hacks for inverse serach to work semi-automatically, " Hacks for inverse search to work semi-automatically,
" see https://jdhao.github.io/2021/02/20/inverse_search_setup_neovim_vimtex/. " see https://jdhao.github.io/2021/02/20/inverse_search_setup_neovim_vimtex/.
function! s:write_server_name() abort function! s:write_server_name() abort
let nvim_server_file = (has('win32') ? $TEMP : '/tmp') . '/vimtexserver.txt' let nvim_server_file = (has('win32') ? $TEMP : '/tmp') . '/vimtexserver.txt'
@ -371,9 +362,16 @@ if exists('g:started_by_firenvim') && g:started_by_firenvim
\ } \ }
\ } \ }
function! s:setup_firenvim() abort
set noruler noshowcmd
set laststatus=0 showtabline=0
endfunction
augroup firenvim augroup firenvim
autocmd! autocmd!
autocmd BufEnter *.txt setlocal filetype=markdown laststatus=0 nonumber noshowcmd noruler showtabline=1 autocmd FileType text call s:setup_firenvim()
autocmd BufNewFile github.com_*.txt set filetype=markdown
autocmd BufNewFile stackoverflow.com_*.txt set filetype=markdown
augroup END augroup END
endif endif

View File

@ -1,99 +0,0 @@
let s:theme_setup_dict = {}
function! s:theme_setup_dict.gruvbox8() dict abort
" Italic options should be put before colorscheme setting,
" see https://github.com/morhetz/gruvbox/wiki/Terminal-specific#1-italics-is-disabled
let g:gruvbox_italics=1
let g:gruvbox_italicize_strings=1
let g:gruvbox_filetype_hi_groups = 1
let g:gruvbox_plugin_hi_groups = 1
colorscheme gruvbox8_hard
endfunction
function! s:theme_setup_dict.onedark() dict abort
colorscheme onedark
endfunction
function! s:theme_setup_dict.edge() dict abort
let g:edge_enable_italic = 1
let g:edge_better_performance = 1
colorscheme edge
endfunction
function! s:theme_setup_dict.sonokai() dict abort
let g:sonokai_enable_italic = 1
let g:sonokai_better_performance = 1
colorscheme sonokai
endfunction
function! s:theme_setup_dict.gruvbox_material() dict abort
let g:gruvbox_material_enable_italic = 1
let g:gruvbox_material_better_performance = 1
colorscheme gruvbox-material
endfunction
function! s:theme_setup_dict.nord() dict abort
colorscheme nord
endfunction
function! s:theme_setup_dict.doom_one() dict abort
colorscheme doom-one
endfunction
function! s:theme_setup_dict.everforest() dict abort
let g:everforest_enable_italic = 1
let g:everforest_better_performance = 1
colorscheme everforest
endfunction
function! s:theme_setup_dict.nightfox() dict abort
colorscheme nordfox
endfunction
function! s:theme_setup_dict.kanagawa() dict abort
colorscheme kanagawa
endfunction
function! s:theme_setup_dict.catppuccin() dict abort
let g:catppuccin_flavour = "frappe" " latte, frappe, macchiato, mocha
lua require("catppuccin").setup()
colorscheme catppuccin
endfunction
" Theme to directory name mapping, because theme repo name is not necessarily
" the same as the theme name itself.
let s:theme2dir = {
\ 'gruvbox8' : 'vim-gruvbox8',
\ 'onedark': 'onedark.nvim',
\ 'edge' : 'edge',
\ 'sonokai': 'sonokai',
\ 'gruvbox_material': 'gruvbox-material',
\ 'nord': 'nord.nvim',
\ 'doom_one': 'doom-one.nvim',
\ 'everforest' :'everforest',
\ 'nightfox': 'nightfox.nvim',
\ 'kanagawa': 'kanagawa.nvim',
\ 'catppuccin': 'catppuccin'
\ }
let s:theme = utils#RandElement(keys(s:theme2dir))
let s:colorscheme_func = printf('s:theme_setup_dict.%s()', s:theme)
if !has_key(s:theme_setup_dict, s:theme)
let s:msg = "Invalid colorscheme function: " . s:colorscheme_func
call v:lua.vim.notify(s:msg, 'error', {'title': 'nvim-config'})
finish
endif
let s:status = utils#add_pack(s:theme2dir[s:theme])
if !s:status
echomsg printf("Theme %s not installed. Run PackerSync to install.", s:theme)
finish
endif
execute 'call ' . s:colorscheme_func
if g:logging_level == 'debug'
let s:msg1 = "Colorscheme: " . s:theme
call v:lua.vim.notify(s:msg1, 'info', {'title': 'nvim-config'})
endif

View File

@ -2,9 +2,48 @@ This doc summarizes how to install and use this configuration in detail.
# Pre-requisite # Pre-requisite
## Terminal emulators
Which [terminal emulator](https://en.wikipedia.org/wiki/Terminal_emulator) we choose to use greatly affects the appearance and features of Nvim.
Since Nvim supports true colors, terminals that support true colors are preferred.
For a list of terminals that support true colors, see [here](https://github.com/termstandard/colors).
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
If you ssh to Linux server on Windows, I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).
## Patched Fonts
Since statusline or file explorer plugins often use Unicode symbols not available in normal font,
we need to install a patched font from the [nerd-fonts](https://github.com/ryanoasis/nerd-fonts) project.
# Automatic installation
## Automatic Installation for Linux
To set up a workable Nvim environment on Linux,
I use [a bash script](nvim_setup_linux.sh) to automatically install necessary dependencies, Nvim itself and configs.
Note that the variable `PYTHON_INSTALLED`, `SYSTEM_PYTHON` and `ADD_TO_SYSTEM_PATH` in the script
should be set properly based on your environment.
## Automatic installation for Windows
Run the script [nvim_setup_windows.ps1](nvim_setup_windows.ps1) in PowerShell **with Administrator rights**:
```
.\docs\nvim_setup_windows.ps1
```
# Manual install
There are a few dependencies if we want to use Nvim for efficient editing and development work. There are a few dependencies if we want to use Nvim for efficient editing and development work.
## Python ## Dependencies
### Python
A lot of Nvim plugins are mainly written in Python, so we must install Python 3. A lot of Nvim plugins are mainly written in Python, so we must install Python 3.
The easiest way to install is via [Anaconda](https://docs.anaconda.com/anaconda/install/index.html) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html). The easiest way to install is via [Anaconda](https://docs.anaconda.com/anaconda/install/index.html) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html).
@ -12,7 +51,7 @@ The easiest way to install is via [Anaconda](https://docs.anaconda.com/anaconda/
After installation, make sure that you can run `python --version`, After installation, make sure that you can run `python --version`,
and that the output should be Python 3.x. and that the output should be Python 3.x.
## Pynvim ### Pynvim
Nvim relies on [pynvim](https://github.com/neovim/pynvim) to communicate with plugins that utilize its Python binding. Nvim relies on [pynvim](https://github.com/neovim/pynvim) to communicate with plugins that utilize its Python binding.
Pynvim is required by plugins such as [wilder.nvim](https://github.com/gelguy/wilder.nvim). Pynvim is required by plugins such as [wilder.nvim](https://github.com/gelguy/wilder.nvim).
@ -21,7 +60,7 @@ Pynvim is required by plugins such as [wilder.nvim](https://github.com/gelguy/wi
pip install -U pynvim pip install -U pynvim
``` ```
## python-lsp-server ### python-lsp-server
[python-lsp-server (pylsp)](https://github.com/python-lsp/python-lsp-server) is a Python [Language Server](https://microsoft.github.io/language-server-protocol/) for completion, linting, go to definition, etc. [python-lsp-server (pylsp)](https://github.com/python-lsp/python-lsp-server) is a Python [Language Server](https://microsoft.github.io/language-server-protocol/) for completion, linting, go to definition, etc.
@ -33,7 +72,7 @@ Note the executable for pylsp is also named `pylsp`. You need to set its PATH co
If you use pip from Anaconda, the executable path may be something like `$CONDA_ROOT/bin/pylsp`. If you use pip from Anaconda, the executable path may be something like `$CONDA_ROOT/bin/pylsp`.
For native python, the path for pylsp may be like `$HOME/.local/bin/pylsp` For native python, the path for pylsp may be like `$HOME/.local/bin/pylsp`
## Node ### Node
We need to install node.js from [here](https://nodejs.org/en/download/). We need to install node.js from [here](https://nodejs.org/en/download/).
For Linux, you can use the following script: For Linux, you can use the following script:
@ -60,7 +99,7 @@ source ~/.bash_profile
# source ~/.zshrc # source ~/.zshrc
``` ```
## vim-language-server ### vim-language-server
[vim-language-server](https://github.com/iamcco/vim-language-server) provides completion for vim script. We can install vim-language-server globally: [vim-language-server](https://github.com/iamcco/vim-language-server) provides completion for vim script. We can install vim-language-server globally:
@ -70,7 +109,7 @@ npm install -g vim-language-server
vim-language-server is installed in the same directory as the node executable. vim-language-server is installed in the same directory as the node executable.
## Git ### Git
Git is required by plugin manager [packer.nvim](https://github.com/wbthomason/packer.nvim) and other git-related plugins. Git is required by plugin manager [packer.nvim](https://github.com/wbthomason/packer.nvim) and other git-related plugins.
@ -79,7 +118,7 @@ The version of Git on the Linux system may be too old so that plugins may break.
Check [here](https://jdhao.github.io/2021/03/27/upgrade_git_on_linux/) on how to install and set up the latest version of Git. Check [here](https://jdhao.github.io/2021/03/27/upgrade_git_on_linux/) on how to install and set up the latest version of Git.
For Windows, install [Git for Windows](https://git-scm.com/download/win) and make sure you can run `git` from command line. For Windows, install [Git for Windows](https://git-scm.com/download/win) and make sure you can run `git` from command line.
## ctags ### ctags
In order to use tags related plugins such as [vista.vim](https://github.com/liuchengxu/vista.vim), we need to install a ctags distribution. In order to use tags related plugins such as [vista.vim](https://github.com/liuchengxu/vista.vim), we need to install a ctags distribution.
Universal-ctags is preferred. Universal-ctags is preferred.
@ -102,7 +141,7 @@ choco install universal-ctags
Set its PATH properly and make sure you can run `ctags` from command line. Set its PATH properly and make sure you can run `ctags` from command line.
## Ripgrep ### Ripgrep
[Ripgrep](https://github.com/BurntSushi/ripgrep), aka, `rg`, is a fast grepping tool available for both Linux, Windows and macOS. [Ripgrep](https://github.com/BurntSushi/ripgrep), aka, `rg`, is a fast grepping tool available for both Linux, Windows and macOS.
It is used by several searching plugins. It is used by several searching plugins.
@ -112,7 +151,7 @@ For Linux, we can download the [binary release](https://github.com/BurntSushi/ri
Set its PATH properly and make sure you can run `rg` from command line. Set its PATH properly and make sure you can run `rg` from command line.
## Linters ### Linters
A linter is a tool to check the source code for possible style and syntax issues. A linter is a tool to check the source code for possible style and syntax issues.
Based on the programming languages we use, we may need to install various linters. Based on the programming languages we use, we may need to install various linters.
@ -122,35 +161,18 @@ Based on the programming languages we use, we may need to install various linter
Set their PATH properly and make sure you can run `pylint`, `flake8` and `vint` from command line. Set their PATH properly and make sure you can run `pylint`, `flake8` and `vint` from command line.
## Terminal emulators ## Install Nvim
Which [terminal emulator](https://en.wikipedia.org/wiki/Terminal_emulator) we choose to use greatly affects the appearance and features of Nvim.
Since Nvim supports true colors, terminals that support true colors are preferred.
For a list of terminals that support true colors, see [here](https://github.com/termstandard/colors).
For macOS, we can use [kitty](https://sw.kovidgoyal.net/kitty/), [iterm2](https://www.iterm2.com/), [wezterm](https://wezfurlong.org/wezterm/) or [Alacritty](https://github.com/jwilm/alacritty).
If you ssh to Linux server on Windows, I recommend [wsltty](https://github.com/mintty/wsltty) and [Cygwin](https://www.cygwin.com/),
both of them use [mintty](https://github.com/mintty/mintty) as the terminal emulator.
For the latest version of Windows 10, you can also try [Windows Terminal](https://github.com/microsoft/terminal).
## Patched Fonts
Since statusline or file explorer plugins often use Unicode symbols not available in normal font,
we need to install a patched font from the [nerd-fonts](https://github.com/ryanoasis/nerd-fonts) project.
# Install Nvim
There are various ways to install Nvim depending on your system. There are various ways to install Nvim depending on your system.
This config is only maintained for [the latest nvim stable release](https://github.com/neovim/neovim/releases/tag/stable). This config is only maintained for [the latest nvim stable release](https://github.com/neovim/neovim/releases/tag/stable).
## Linux ### Linux
You can directly download the binary release from [here](https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz). You can directly download the binary release from [here](https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz).
You can also use the system package manager to install nvim, You can also use the system package manager to install nvim,
but that is not reliable since the latest version may not be available. but that is not reliable since the latest version may not be available.
## Windows ### Windows
You may download from [nvim release](https://github.com/neovim/neovim/releases/download/stable/nvim-win64.zip) from GitHub and manually extract it. You may download from [nvim release](https://github.com/neovim/neovim/releases/download/stable/nvim-win64.zip) from GitHub and manually extract it.
@ -164,7 +186,7 @@ choco install neovim
# scoop install neovim # scoop install neovim
``` ```
## macOS ### macOS
It is recommended to install neovim via [Homebrew](https://brew.sh/) on macOS. Simply run the following command: It is recommended to install neovim via [Homebrew](https://brew.sh/) on macOS. Simply run the following command:
@ -175,9 +197,11 @@ brew install neovim
After installing Nvim, we need to set the path to nvim correctly. After installing Nvim, we need to set the path to nvim correctly.
**Make sure that you can run `nvim` from the command line after all these setups**. **Make sure that you can run `nvim` from the command line after all these setups**.
# Setting up Nvim ## Setting up Nvim
## Install plugin manager packer.nvim After installing nvim and all the dependencies, we will install plugin managers and set up this config.
### Install plugin manager packer.nvim
I use packer.nvim to manage my plugins. We need to install packer.nvim on our system first. I use packer.nvim to manage my plugins. We need to install packer.nvim on our system first.
@ -193,7 +217,7 @@ For macOS and Linux, run the following command:
git clone --depth=1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/opt/packer.nvim git clone --depth=1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/opt/packer.nvim
``` ```
## How to install this configuration ### How to install this configuration
On Linux and macOS, the directory is `~/.config/nvim`. On Linux and macOS, the directory is `~/.config/nvim`.
On Windows, the config directory is `$HOME/AppData/Local/nvim`[^1]. On Windows, the config directory is `$HOME/AppData/Local/nvim`[^1].
@ -207,18 +231,4 @@ git clone --depth=1 https://github.com/jdhao/nvim-config.git .
After that, when we first open nvim, run command `:PackerSync` to install all the plugins. After that, when we first open nvim, run command `:PackerSync` to install all the plugins.
Since I use quite a lot of plugins (more than 60), it may take some time to install all of them. Since I use quite a lot of plugins (more than 60), it may take some time to install all of them.
# Automatic installation
## Automatic Installation for Linux #
To set up a workable Nvim environment on Linux,
I use [a bash script](nvim_setup_linux.sh) to automatically install necessary dependencies, Nvim itself and configs.
Note that the variable `PYTHON_INSTALLED`, `SYSTEM_PYTHON` and `ADD_TO_SYSTEM_PATH` in the script
should be set properly based on your environment.
## Automatic installation for Windows
Run script [nvim_setup_windows.ps1](nvim_setup_windows.ps1) under PowerShell.
[^1]: Use `echo %userprofile%` to see where your `$HOME` is. [^1]: Use `echo %userprofile%` to see where your `$HOME` is.

View File

@ -112,6 +112,7 @@ if [[ -z "$(command -v node)" ]]; then
fi fi
else else
echo "Node.js is already installed. Skip installing it." echo "Node.js is already installed. Skip installing it."
NODE_DIR="$(realpath $(dirname $(which node))/..)"
fi fi
# Install vim-language-server # Install vim-language-server
@ -120,6 +121,35 @@ fi
# Install bash-language-server # Install bash-language-server
"$NODE_DIR/bin/npm" install -g bash-language-server "$NODE_DIR/bin/npm" install -g bash-language-server
#######################################################################
# lua-language-server #
#######################################################################
SUMNEKO_LUA_DIR=$HOME/tools/lua-language-server
SUMNEKO_LUA_SRC_NAME=$HOME/packages/lua-language-server.tar.gz
SUMNEKO_LUA_LINK="https://github.com/sumneko/lua-language-server/releases/download/3.5.3/lua-language-server-3.5.3-linux-x64.tar.gz"
if [[ -z "$(command -v lua-language-server)" ]] && [[ ! -f "$SUMNEKO_LUA_DIR/bin/lua-language-server" ]]; then
echo 'Install lua-language-server'
if [[ ! -f $SUMNEKO_LUA_SRC_NAME ]]; then
echo "Downloading lua-language-server and renaming"
wget $SUMNEKO_LUA_LINK -O "$SUMNEKO_LUA_SRC_NAME"
fi
if [[ ! -d "$SUMNEKO_LUA_DIR" ]]; then
echo "Creating lua-language-server directory under tools directory"
mkdir -p "$SUMNEKO_LUA_DIR"
echo "Extracting to directory $SUMNEKO_LUA_DIR"
tar zxvf "$SUMNEKO_LUA_SRC_NAME" -C "$SUMNEKO_LUA_DIR"
fi
if [[ "$ADD_TO_SYSTEM_PATH" = true ]] && [[ "$USE_BASH_SHELL" = true ]]; then
echo "export PATH=\"$SUMNEKO_LUA_DIR/bin:\$PATH\"" >> "$HOME/.bash_profile"
fi
else
echo "lua-language-server is already installed. Skip installing it."
fi
####################################################################### #######################################################################
# Ripgrep part # # Ripgrep part #
####################################################################### #######################################################################
@ -145,8 +175,8 @@ if [[ -z "$(command -v rg)" ]] && [[ ! -f "$RIPGREP_DIR/rg" ]]; then
fi fi
# set up manpath and zsh completion for ripgrep # set up manpath and zsh completion for ripgrep
mkdir -p $HOME/tools/ripgrep/doc/man/man1 mkdir -p "$HOME/tools/ripgrep/doc/man/man1"
mv $HOME/tools/ripgrep/doc/rg.1 $HOME/tools/ripgrep/doc/man/man1 mv "$HOME/tools/ripgrep/doc/rg.1" "$HOME/tools/ripgrep/doc/man/man1"
if [[ "$USE_BASH_SHELL" = true ]]; then if [[ "$USE_BASH_SHELL" = true ]]; then
echo 'export MANPATH=$HOME/tools/ripgrep/doc/man:$MANPATH' >> "$HOME/.bash_profile" echo 'export MANPATH=$HOME/tools/ripgrep/doc/man:$MANPATH' >> "$HOME/.bash_profile"
@ -216,6 +246,7 @@ fi
echo "Setting up config and installing plugins" echo "Setting up config and installing plugins"
if [[ -d "$NVIM_CONFIG_DIR" ]]; then if [[ -d "$NVIM_CONFIG_DIR" ]]; then
rm -rf "$NVIM_CONFIG_DIR.backup"
mv "$NVIM_CONFIG_DIR" "$NVIM_CONFIG_DIR.backup" mv "$NVIM_CONFIG_DIR" "$NVIM_CONFIG_DIR.backup"
fi fi

View File

@ -1,6 +1,8 @@
# Install scoop # Set policy to avoid errors
Set-ExecutionPolicy RemoteSigned -scope CurrentUser Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex
# Install scoop
Invoke-WebRequest -UseBasicParsing get.scoop.sh | Invoke-Expression
# Install node # Install node
scoop install nodejs scoop install nodejs
@ -18,7 +20,7 @@ npm install -g vim-language-server
# Install bash-language-server # Install bash-language-server
npm install -g bash-language-server npm install -g bash-language-server
# Install miniconda3 # Install miniconda3 (for Python)
scoop install miniconda3 scoop install miniconda3
# Install pynvim # Install pynvim
@ -27,6 +29,27 @@ pip install -U pynvim
# Install python-language-server # Install python-language-server
pip install 'python-lsp-server[all]' pylsp-mypy pyls-isort pip install 'python-lsp-server[all]' pylsp-mypy pyls-isort
# Install visual c++ redistribution
scoop install vcredist2022
# Install 7zip
scoop install 7zip
# Install lua-language-server
$sumneko_lua_link = "https://github.com/sumneko/lua-language-server/releases/download/3.5.3/lua-language-server-3.5.3-win32-x64.zip"
$sumneko_lua_install_dir = "D:\portable_tools"
$sumneko_lua_src_dir = "$sumneko_lua_install_dir\lua-language-server.zip"
$sumneko_lua_dir = "$sumneko_lua_install_dir\lua-language-server"
# Download file, ref: https://stackoverflow.com/a/51225744/6064933
Invoke-WebRequest $sumneko_lua_link -OutFile "$sumneko_lua_src_dir"
# Extract the zip file using 7zip, ref: https://stackoverflow.com/a/41933215/6064933
7z x "$sumneko_lua_src_dir" -o"$sumneko_lua_dir"
# Setup PATH env variable, ref: https://stackoverflow.com/q/714877/6064933
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$sumneko_lua_dir\bin", "Machine")
# Install neovim nightly # Install neovim nightly
scoop bucket add versions scoop bucket add versions
scoop install neovim scoop install neovim

View File

@ -59,3 +59,16 @@ if exists('g:fvim_loaded')
FVimUIPopupMenu v:false FVimUIPopupMenu v:false
endif endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" config for neovide "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if exists("g:neovide")
set guifont=Hack\ NF:h10
let g:neovide_transparency = 1.0
let g:neovide_cursor_animation_length = 0.1
let g:neovide_cursor_trail_size=0.3
let g:neovide_cursor_vfx_mode = ""
let g:neovide_cursor_vfx_particle_density=10.0
let g:neovide_cursor_vfx_opacity=150.0
endif

38
init.lua Normal file
View File

@ -0,0 +1,38 @@
-- This is my personal Nvim configuration supporting Mac, Linux and Windows, with various plugins configured.
-- This configuration evolves as I learn more about Nvim and become more proficient in using Nvim.
-- Since it is very long (more than 1000 lines!), you should read it carefully and take only the settings that suit you.
-- I would not recommend cloning this repo and replace your own config. Good configurations are personal,
-- built over time with a lot of polish.
--
-- Author: Jie-dong Hao
-- Email: jdhao@hotmail.com
-- Blog: https://jdhao.github.io/
local api = vim.api
local utils = require("utils")
-- check if we have the latest stable version of nvim
local expected_ver = "0.7.2"
local nvim_ver = utils.get_nvim_version()
if nvim_ver ~= expected_ver then
local msg = string.format("Unsupported nvim version: expect %s, but got %s instead!", expected_ver, nvim_ver)
api.nvim_err_writeln(msg)
return
end
local core_conf_files = {
"globals.lua", -- some global settings
"options.vim", -- setting options in nvim
"autocommands.vim", -- various autocommands
"mappings.lua", -- all the user-defined mappings
"plugins.vim", -- all the plugins installed and their configurations
"colorschemes.lua", -- colorscheme settings
}
-- source all the core config files
for _, name in ipairs(core_conf_files) do
local path = string.format("%s/core/%s", vim.fn.stdpath("config"), name)
local source_cmd = "source " .. path
vim.cmd(source_cmd)
end

View File

@ -1,31 +0,0 @@
" This is my personal Nvim configuration supporting Mac, Linux and Windows, with various plugins configured.
" This configuration evolves as I learn more about Nvim and become more proficient in using Nvim.
" Since it is very long (more than 1000 lines!), you should read it carefully and take only the settings that suit you.
" I would not recommend cloning this repo and replace your own config. Good configurations are personal,
" built over time with a lot of polish.
"
" Author: Jie-dong Hao
" Email: jdhao@hotmail.com
" Blog: https://jdhao.github.io/
" check if we have the lastest stable version of nvim
let s:expect_ver = printf('nvim-%s', '0.7.2')
let s:actual_ver = matchstr(execute('version'), 'NVIM v\zs[^\n]*')
if !has(s:expect_ver)
echohl Error | echomsg printf("%s required, but got nvim %s!", s:expect_ver, s:actual_ver) | echohl None
finish
endif
let s:core_conf_files = [
\ 'globals.vim',
\ 'options.vim',
\ 'autocommands.vim',
\ 'mappings.vim',
\ 'plugins.vim',
\ 'themes.vim'
\ ]
for s:fname in s:core_conf_files
execute printf('source %s/core/%s', stdpath('config'), s:fname)
endfor

View File

@ -1,6 +1,6 @@
require("bqf").setup({ require("bqf").setup {
auto_resize_height = false, auto_resize_height = false,
preview = { preview = {
auto_preview = false, auto_preview = false,
} },
}) }

View File

@ -1,11 +1,14 @@
require("bufferline").setup({ require("bufferline").setup {
options = { options = {
numbers = "buffer_id", numbers = "buffer_id",
close_command = "bdelete! %d", close_command = "bdelete! %d",
right_mouse_command = nil, right_mouse_command = nil,
left_mouse_command = "buffer %d", left_mouse_command = "buffer %d",
middle_mouse_command = nil, middle_mouse_command = nil,
indicator_icon = "", indicator = {
icon = "", -- this should be omitted if indicator style is not 'icon'
style = "icon",
},
buffer_close_icon = "", buffer_close_icon = "",
modified_icon = "", modified_icon = "",
close_icon = "", close_icon = "",
@ -40,4 +43,4 @@ require("bufferline").setup({
always_show_bufferline = true, always_show_bufferline = true,
sort_by = "id", sort_by = "id",
}, },
}) }

View File

@ -52,8 +52,8 @@ dashboard.custom_center = {
desc = "Quit Nvim ", desc = "Quit Nvim ",
-- desc = "Quit Nvim ", -- desc = "Quit Nvim ",
action = "qa", action = "qa",
shortcut = "q " shortcut = "q ",
} },
} }
vim.cmd([[ vim.cmd([[

View File

@ -0,0 +1 @@
require("fidget").setup {}

8
lua/config/fugitive.lua Normal file
View File

@ -0,0 +1,8 @@
local keymap = vim.keymap
keymap.set("n", "<leader>gs", "<cmd>Git<cr>", { desc = "Git status" })
keymap.set("n", "<leader>gw", "<cmd>Gwrite<cr>", { desc = "Git add" })
keymap.set("n", "<leader>gc", "<cmd>Git commit<cr>", { desc = "Git commit" })
keymap.set("n", "<leader>gd", "<cmd>Gdiffsplit<cr>", { desc = "Git diff" })
keymap.set("n", "<leader>gpl", "<cmd>Git pull<cr>", { desc = "Git pull" })
keymap.set("n", "<leader>gpu", "<cmd>15 split|term git push<cr>", { desc = "Git push" })

15
lua/config/git-linker.lua Normal file
View File

@ -0,0 +1,15 @@
local keymap = vim.keymap
local gitlinker = require("gitlinker")
gitlinker.setup {
mappings = nil,
}
keymap.set({ "n", "v" }, "<leader>gl", "", {
silent = true,
desc = "get git permlink",
callback = function()
local mode = string.lower(vim.fn.mode())
gitlinker.get_buf_range_url(mode)
end,
})

45
lua/config/gitsigns.lua Normal file
View File

@ -0,0 +1,45 @@
local gs = require("gitsigns")
gs.setup {
signs = {
add = { hl = "GitSignsAdd", text = "+", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
change = { hl = "GitSignsChange", text = "~", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
delete = { hl = "GitSignsDelete", text = "_", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
topdelete = { hl = "GitSignsDelete", text = "", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
changedelete = { hl = "GitSignsChange", text = "", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
},
on_attach = function(bufnr)
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true, desc = "next hunk" })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true, desc = "previous hunk" })
-- Actions
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line { full = true }
end)
end,
}

View File

@ -1,34 +1,38 @@
require('hlslens').setup({ local api = vim.api
calm_down = true, local keymap = vim.keymap
nearest_only = true,
}) local hlslens = require("hlslens")
hlslens.setup {
calm_down = true,
nearest_only = true,
}
local activate_hlslens = function(direction) local activate_hlslens = function(direction)
local cmd = string.format("normal! %s%szzzv", vim.v.count1, direction) local cmd = string.format("normal! %s%szzzv", vim.v.count1, direction)
local status, msg = pcall(vim.fn.execute, cmd) local status, msg = pcall(vim.cmd, cmd)
-- 13 is the index where real error message starts
msg = msg:sub(13)
if not status then if not status then
vim.api.nvim_echo({{msg, "ErrorMsg"}}, false, {}) -- 13 is the index where real error message starts
msg = msg:sub(13)
api.nvim_err_writeln(msg)
return return
end end
require('hlslens').start()
hlslens.start()
end end
vim.keymap.set('n', 'n', '', keymap.set("n", "n", "", {
{ callback = function()
noremap = true, activate_hlslens("n")
silent = true, end,
callback = function() activate_hlslens('n') end
}) })
vim.keymap.set('n', 'N', '', keymap.set("n", "N", "", {
{ callback = function()
noremap = true, activate_hlslens("N")
silent = true, end,
callback = function() activate_hlslens('N') end
}) })
vim.keymap.set('n', '*', "<Plug>(asterisk-z*)<Cmd>lua require('hlslens').start()<CR>", { silent = true }) keymap.set("n", "*", "<Plug>(asterisk-z*)<Cmd>lua require('hlslens').start()<CR>")
vim.keymap.set('n', '#', "<Plug>(asterisk-z#)<Cmd>lua require('hlslens').start()<CR>", { silent = true }) keymap.set("n", "#", "<Plug>(asterisk-z#)<Cmd>lua require('hlslens').start()<CR>")

View File

@ -1,23 +1,29 @@
require("indent_blankline").setup({ local api = vim.api
local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha" }
require("indent_blankline").setup {
-- U+2502 may also be a good choice, it will be on the middle of cursor. -- U+2502 may also be a good choice, it will be on the middle of cursor.
-- U+250A is also a good choice -- U+250A is also a good choice
char = "", char = "",
show_end_of_line = false, show_end_of_line = false,
disable_with_nolist = true, disable_with_nolist = true,
buftype_exclude = { "terminal" }, buftype_exclude = { "terminal" },
filetype_exclude = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha" }, filetype_exclude = exclude_ft,
}
local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
api.nvim_create_autocmd("InsertEnter", {
pattern = "*",
group = gid,
command = "IndentBlanklineDisable",
}) })
vim.cmd([[ api.nvim_create_autocmd("InsertLeave", {
function! Should_activate_indentblankline() abort pattern = "*",
if index(g:indent_blankline_filetype_exclude, &filetype) == -1 group = gid,
IndentBlanklineEnable callback = function()
endif if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
endfunction vim.cmd([[IndentBlanklineEnable]])
end
augroup indent_blankline end,
autocmd! })
autocmd InsertEnter * IndentBlanklineDisable
autocmd InsertLeave * call Should_activate_indentblankline()
augroup END
]])

View File

@ -1,7 +1,7 @@
local iron = require("iron") local iron = require("iron")
iron.core.set_config({ iron.core.set_config {
preferred = { preferred = {
python = "ipython", python = "ipython",
}, },
repl_open_cmd = "vertical 120 split", repl_open_cmd = "vertical 120 split",
}) }

View File

@ -1,60 +1,72 @@
local fn = vim.fn local fn = vim.fn
local api = vim.api local api = vim.api
local keymap = vim.keymap
local lsp = vim.lsp local lsp = vim.lsp
local utils = require("utils") local utils = require("utils")
local custom_attach = function(client, bufnr) local custom_attach = function(client, bufnr)
-- Mappings. -- Mappings.
local opts = { silent = true, buffer = bufnr } local map = function(mode, l, r, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) opts = opts or {}
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, opts) opts.silent = true
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) opts.buffer = bufnr
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts) keymap.set(mode, l, r, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts) end
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "<space>q", function() vim.diagnostic.setqflist({open = true}) end, opts)
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, opts)
vim.api.nvim_create_autocmd("CursorHold", { map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
buffer=bufnr, map("n", "<C-]>", vim.lsp.buf.definition)
map("n", "K", vim.lsp.buf.hover)
map("n", "<C-k>", vim.lsp.buf.signature_help)
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
map("n", "[d", vim.diagnostic.goto_prev, { desc = "previous diagnostic" })
map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic" })
map("n", "<space>q", function()
vim.diagnostic.setqflist { open = true }
end, { desc = "put diagnostic to qf" })
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
map("n", "<space>wl", function()
inspect(vim.lsp.buf.list_workspace_folders())
end, { desc = "list workspace folder" })
-- Set some key bindings conditional on server capabilities
if client.resolved_capabilities.document_formatting then
map("n", "<space>f", vim.lsp.buf.formatting_sync, { desc = "format code" })
end
if client.resolved_capabilities.document_range_formatting then
map("x", "<space>f", vim.lsp.buf.range_formatting, { desc = "range format" })
end
api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function() callback = function()
local opts = { local float_opts = {
focusable = false, focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded', border = "rounded",
source = 'always', -- show source in diagnostic popup window source = "always", -- show source in diagnostic popup window
prefix = ' ' prefix = " ",
} }
if not vim.b.diagnostics_pos then if not vim.b.diagnostics_pos then
vim.b.diagnostics_pos = { nil, nil } vim.b.diagnostics_pos = { nil, nil }
end end
local cursor_pos = vim.api.nvim_win_get_cursor(0) local cursor_pos = api.nvim_win_get_cursor(0)
if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2]) and if
#vim.diagnostic.get() > 0 (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
and #vim.diagnostic.get() > 0
then then
vim.diagnostic.open_float(nil, opts) vim.diagnostic.open_float(nil, float_opts)
end end
vim.b.diagnostics_pos = cursor_pos vim.b.diagnostics_pos = cursor_pos
end end,
}) })
-- Set some key bindings conditional on server capabilities
if client.resolved_capabilities.document_formatting then
vim.keymap.set("n", "<space>f", vim.lsp.buf.formatting_sync, opts)
end
if client.resolved_capabilities.document_range_formatting then
vim.keymap.set("x", "<space>f", vim.lsp.buf.range_formatting, opts)
end
-- The blow command will highlight the current variable and its usages in the buffer. -- The blow command will highlight the current variable and its usages in the buffer.
if client.resolved_capabilities.document_highlight then if client.resolved_capabilities.document_highlight then
vim.cmd([[ vim.cmd([[
@ -69,20 +81,20 @@ local custom_attach = function(client, bufnr)
]]) ]])
end end
if vim.g.logging_level == 'debug' then if vim.g.logging_level == "debug" then
local msg = string.format("Language server %s started!", client.name) local msg = string.format("Language server %s started!", client.name)
vim.notify(msg, 'info', {title = 'Nvim-config'}) vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" })
end end
end end
local capabilities = lsp.protocol.make_client_capabilities() local capabilities = lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true
local lspconfig = require("lspconfig") local lspconfig = require("lspconfig")
if utils.executable('pylsp') then if utils.executable("pylsp") then
lspconfig.pylsp.setup({ lspconfig.pylsp.setup {
on_attach = custom_attach, on_attach = custom_attach,
settings = { settings = {
pylsp = { pylsp = {
@ -100,9 +112,9 @@ if utils.executable('pylsp') then
debounce_text_changes = 200, debounce_text_changes = 200,
}, },
capabilities = capabilities, capabilities = capabilities,
}) }
else else
vim.notify("pylsp not found!", 'warn', {title = 'Nvim-config'}) vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end end
-- if utils.executable('pyright') then -- if utils.executable('pyright') then
@ -111,78 +123,72 @@ end
-- capabilities = capabilities -- capabilities = capabilities
-- } -- }
-- else -- else
-- vim.notify("pyright not found!", 'warn', {title = 'Nvim-config'}) -- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
-- end -- end
if utils.executable('clangd') then if utils.executable("clangd") then
lspconfig.clangd.setup({ lspconfig.clangd.setup {
on_attach = custom_attach, on_attach = custom_attach,
capabilities = capabilities, capabilities = capabilities,
filetypes = { "c", "cpp", "cc" }, filetypes = { "c", "cpp", "cc" },
flags = { flags = {
debounce_text_changes = 500, debounce_text_changes = 500,
}, },
}) }
else else
vim.notify("clangd not found!", 'warn', {title = 'Nvim-config'}) vim.notify("clangd not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end end
-- set up vim-language-server -- set up vim-language-server
if utils.executable('vim-language-server') then if utils.executable("vim-language-server") then
lspconfig.vimls.setup({ lspconfig.vimls.setup {
on_attach = custom_attach, on_attach = custom_attach,
flags = { flags = {
debounce_text_changes = 500, debounce_text_changes = 500,
}, },
capabilities = capabilities, capabilities = capabilities,
}) }
else else
vim.notify("vim-language-server not found!", 'warn', {title = 'Nvim-config'}) vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end end
-- set up bash-language-server -- set up bash-language-server
if utils.executable('bash-language-server') then if utils.executable("bash-language-server") then
lspconfig.bashls.setup({ lspconfig.bashls.setup {
on_attach = custom_attach, on_attach = custom_attach,
capabilities = capabilities, capabilities = capabilities,
}) }
end end
local sumneko_binary_path = fn.exepath("lua-language-server") if utils.executable("lua-language-server") then
if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then -- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings .
local sumneko_root_path = fn.fnamemodify(sumneko_binary_path, ":h:h:h") lspconfig.sumneko_lua.setup {
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
lspconfig.sumneko_lua.setup({
on_attach = custom_attach, on_attach = custom_attach,
cmd = { sumneko_binary_path, "-E", sumneko_root_path .. "/main.lua" },
settings = { settings = {
Lua = { Lua = {
runtime = { runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT", version = "LuaJIT",
-- Setup your lua path
path = runtime_path,
}, },
diagnostics = { diagnostics = {
-- Get the language server to recognize the `vim` global -- Get the language server to recognize the `vim` global
globals = { "vim" }, globals = { "vim" },
}, },
workspace = { workspace = {
-- Make the server aware of Neovim runtime files -- Make the server aware of Neovim runtime files,
library = api.nvim_get_runtime_file("", true), -- see also https://github.com/sumneko/lua-language-server/wiki/Libraries#link-to-workspace .
}, -- Lua-dev.nvim also has similar settings for sumneko lua, https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua .
-- Do not send telemetry data containing a randomized but unique identifier library = {
telemetry = { fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim",
enable = false, fn.stdpath("config"),
},
maxPreload = 2000,
preloadFileSize = 50000,
}, },
}, },
}, },
capabilities = capabilities, capabilities = capabilities,
}) }
end end
-- Change diagnostic signs. -- Change diagnostic signs.
@ -192,12 +198,12 @@ fn.sign_define("DiagnosticSignInformation", { text = "", texthl = "Diagnostic
fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" }) fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
-- global config for diagnostic -- global config for diagnostic
vim.diagnostic.config({ vim.diagnostic.config {
underline = false, underline = false,
virtual_text = false, virtual_text = false,
signs = true, signs = true,
severity_sort = true, severity_sort = true,
}) }
-- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, { -- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, {
-- underline = false, -- underline = false,

View File

@ -1,6 +1,6 @@
require("neoscroll").setup({ require("neoscroll").setup {
easing_function = "quadratic", easing_function = "quadratic",
}) }
local t = {} local t = {}
-- Syntax: t[keys] = {function, {function arguments}} -- Syntax: t[keys] = {function, {function arguments}}

View File

@ -1,68 +1,68 @@
-- Setup nvim-cmp. -- Setup nvim-cmp.
local cmp = require'cmp' local cmp = require("cmp")
local lspkind = require'lspkind' local lspkind = require("lspkind")
cmp.setup({ cmp.setup {
snippet = { snippet = {
expand = function(args) expand = function(args)
-- For `ultisnips` user. -- For `ultisnips` user.
vim.fn["UltiSnips#Anon"](args.body) vim.fn["UltiSnips#Anon"](args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert {
['<Tab>'] = function(fallback) ["<Tab>"] = function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
else else
fallback() fallback()
end end
end, end,
['<S-Tab>'] = function(fallback) ["<S-Tab>"] = function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
else else
fallback() fallback()
end end
end, end,
['<CR>'] = cmp.mapping.confirm({ select = true }), ["<CR>"] = cmp.mapping.confirm { select = true },
['<C-e>'] = cmp.mapping.abort(), ["<C-e>"] = cmp.mapping.abort(),
['<Esc>'] = cmp.mapping.close(), ["<Esc>"] = cmp.mapping.close(),
['<C-d>'] = cmp.mapping.scroll_docs(-4), ["<C-d>"] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4), ["<C-f>"] = cmp.mapping.scroll_docs(4),
}), },
sources = { sources = {
{ name = 'nvim_lsp' }, -- For nvim-lsp { name = "nvim_lsp" }, -- For nvim-lsp
{ name = 'ultisnips' }, -- For ultisnips user. { name = "ultisnips" }, -- For ultisnips user.
{ name = 'path' }, -- for path completion { name = "path" }, -- for path completion
{ name = 'buffer', keyword_length = 4 }, -- for buffer word completion { name = "buffer", keyword_length = 2 }, -- for buffer word completion
{ name = 'omni' }, { name = "omni" },
{ name = 'emoji', insert = true, } -- emoji completion { name = "emoji", insert = true }, -- emoji completion
}, },
completion = { completion = {
keyword_length = 1, keyword_length = 1,
completeopt = "menu,noselect" completeopt = "menu,noselect",
}, },
view = { view = {
entries = 'custom', entries = "custom",
}, },
formatting = { formatting = {
format = lspkind.cmp_format({ format = lspkind.cmp_format {
mode = "symbol_text", mode = "symbol_text",
menu = ({ menu = {
nvim_lsp = "[LSP]", nvim_lsp = "[LSP]",
ultisnips = "[US]", ultisnips = "[US]",
nvim_lua = "[Lua]", nvim_lua = "[Lua]",
path = "[Path]", path = "[Path]",
buffer = "[Buffer]", buffer = "[Buffer]",
emoji = "[Emoji]", emoji = "[Emoji]",
omni = "[Omni]", omni = "[Omni]",
}), },
}), },
}, },
}) }
-- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu -- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu
vim.cmd[[ vim.cmd([[
highlight! link CmpItemMenu Comment highlight! link CmpItemMenu Comment
" gray " gray
highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080 highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080
@ -80,4 +80,4 @@ vim.cmd[[
highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4 highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4
highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4 highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4
highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4 highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4
]] ]])

View File

@ -1,10 +1,10 @@
local nvim_notify = require("notify") local nvim_notify = require("notify")
nvim_notify.setup({ nvim_notify.setup {
-- Animation style -- Animation style
stages = "fade_in_slide_out", stages = "fade_in_slide_out",
-- Default timeout for notifications -- Default timeout for notifications
timeout = 1500, timeout = 1500,
background_colour = "#2E3440", background_colour = "#2E3440",
}) }
vim.notify = nvim_notify vim.notify = nvim_notify

View File

@ -1,6 +1,7 @@
local keymap = vim.keymap
local nvim_tree = require("nvim-tree") local nvim_tree = require("nvim-tree")
nvim_tree.setup({ nvim_tree.setup {
auto_reload_on_write = true, auto_reload_on_write = true,
disable_netrw = false, disable_netrw = false,
hijack_cursor = false, hijack_cursor = false,
@ -111,9 +112,8 @@ nvim_tree.setup({
profile = false, profile = false,
}, },
}, },
}) }
vim.keymap.set('n', '<space>s', function() keymap.set("n", "<space>s", function()
return require('nvim-tree').toggle(false, true) return require("nvim-tree").toggle(false, true)
end, end, { silent = true, desc = "toggle nvim-tree" })
{ noremap = true, silent = true, desc = "toggle nvim-tree"})

View File

@ -1,14 +1,20 @@
vim.cmd[[ hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff ]] vim.cmd([[hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]])
vim.cmd[[ hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff ]] vim.cmd([[hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]])
vim.cmd[[ hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff ]] vim.cmd([[hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]])
require('hop').setup({ local keymap = vim.keymap
local hop = require("hop")
hop.setup {
case_insensitive = true, case_insensitive = true,
char2_fallback_key = '<CR>', char2_fallback_key = "<CR>",
quit_key='<Esc>', quit_key = "<Esc>",
}) }
vim.keymap.set('n', 'f', function() keymap.set({ "n", "v", "o" }, "f", "", {
return require('hop').hint_char2() silent = true,
end, noremap = true,
{ silent = true, noremap = true, desc = "nvim-hop char2" }) callback = function()
hop.hint_char2()
end,
desc = "nvim-hop char2",
})

View File

@ -11,9 +11,9 @@ end
local function ime_state() local function ime_state()
if vim.g.is_mac then if vim.g.is_mac then
-- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11 -- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11
local layout = fn.libcall(vim.g.XkbSwitchLib, 'Xkb_Switch_getXkbLayout', '') local layout = fn.libcall(vim.g.XkbSwitchLib, "Xkb_Switch_getXkbLayout", "")
if layout == '0' then if layout == "0" then
return '[CN]' return "[CN]"
end end
end end
@ -27,7 +27,7 @@ local function trailing_space()
local line_num = nil local line_num = nil
for i=1, fn.line('$') do for i = 1, fn.line("$") do
local linetext = fn.getline(i) local linetext = fn.getline(i)
-- To prevent invalid escape error, we wrap the regex string with `[[]]`. -- To prevent invalid escape error, we wrap the regex string with `[[]]`.
local idx = fn.match(linetext, [[\v\s+$]]) local idx = fn.match(linetext, [[\v\s+$]])
@ -53,28 +53,45 @@ local function mixed_indent()
local space_pat = [[\v^ +]] local space_pat = [[\v^ +]]
local tab_pat = [[\v^\t+]] local tab_pat = [[\v^\t+]]
local space_indent = fn.search(space_pat, 'nwc') local space_indent = fn.search(space_pat, "nwc")
local tab_indent = fn.search(tab_pat, 'nwc') local tab_indent = fn.search(tab_pat, "nwc")
local mixed = (space_indent > 0 and tab_indent > 0) local mixed = (space_indent > 0 and tab_indent > 0)
local mixed_same_line local mixed_same_line
if not mixed then if not mixed then
mixed_same_line = fn.search([[\v^(\t+ | +\t)]], 'nwc') mixed_same_line = fn.search([[\v^(\t+ | +\t)]], "nwc")
mixed = mixed_same_line > 0 mixed = mixed_same_line > 0
end end
if not mixed then return '' end if not mixed then
if mixed_same_line ~= nil and mixed_same_line > 0 then return ""
return 'MI:'..mixed_same_line
end end
local space_indent_cnt = fn.searchcount({pattern=space_pat, max_count=1e3}).total if mixed_same_line ~= nil and mixed_same_line > 0 then
local tab_indent_cnt = fn.searchcount({pattern=tab_pat, max_count=1e3}).total return "MI:" .. mixed_same_line
end
local space_indent_cnt = fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total
local tab_indent_cnt = fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total
if space_indent_cnt > tab_indent_cnt then if space_indent_cnt > tab_indent_cnt then
return 'MI:'..tab_indent return "MI:" .. tab_indent
else else
return 'MI:'..space_indent return "MI:" .. space_indent
end end
end end
require("lualine").setup({ local diff = function()
local git_status = vim.b.gitsigns_status_dict
if git_status == nil then
return
end
local modify_num = git_status.changed
local remove_num = git_status.removed
local add_num = git_status.added
local info = { added = add_num, modified = modify_num, removed = remove_num }
-- vim.pretty_print(info)
return info
end
require("lualine").setup {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = "auto", theme = "auto",
@ -87,16 +104,22 @@ require("lualine").setup({
}, },
sections = { sections = {
lualine_a = { "mode" }, lualine_a = { "mode" },
lualine_b = { "branch", "diff" }, lualine_b = {
"branch",
{
"diff",
source = diff,
},
},
lualine_c = { lualine_c = {
"filename", "filename",
{ {
ime_state, ime_state,
color = {fg = 'black', bg = '#f46868'} color = { fg = "black", bg = "#f46868" },
}, },
{ {
spell, spell,
color = {fg = 'black', bg = '#a7c080'} color = { fg = "black", bg = "#a7c080" },
}, },
}, },
lualine_x = { lualine_x = {
@ -116,15 +139,15 @@ require("lualine").setup({
"location", "location",
{ {
"diagnostics", "diagnostics",
sources = { "nvim_diagnostic" } sources = { "nvim_diagnostic" },
}, },
{ {
trailing_space, trailing_space,
color = "WarningMsg" color = "WarningMsg",
}, },
{ {
mixed_indent, mixed_indent,
color = "WarningMsg" color = "WarningMsg",
}, },
}, },
}, },
@ -137,6 +160,5 @@ require("lualine").setup({
lualine_z = {}, lualine_z = {},
}, },
tabline = {}, tabline = {},
extensions = {'quickfix', 'fugitive', 'nvim-tree'}, extensions = { "quickfix", "fugitive", "nvim-tree" },
}) }

View File

@ -1,8 +1,8 @@
require("nvim-treesitter.configs").setup({ require("nvim-treesitter.configs").setup {
ensure_installed = {"python", "cpp", "lua", "vim"}, ensure_installed = { "python", "cpp", "lua", "vim" },
ignore_install = {}, -- List of parsers to ignore installing ignore_install = {}, -- List of parsers to ignore installing
highlight = { highlight = {
enable = true, -- false will disable the whole extension enable = true, -- false will disable the whole extension
disable = {}, -- list of language that will be disabled disable = {}, -- list of language that will be disabled
}, },
}) }

View File

@ -1,4 +1,4 @@
require("which-key").setup({ require("which-key").setup {
plugins = { plugins = {
marks = true, -- shows a list of your marks on ' and ` marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
@ -46,7 +46,7 @@ require("which-key").setup({
align = "center", -- align columns left, center or right align = "center", -- align columns left, center or right
}, },
ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
show_help = true, -- show help message on the command line when the popup is visible show_help = true, -- show help message on the command line when the popup is visible
triggers = "auto", -- automatically setup triggers triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specify a list manually -- triggers = {"<leader>"} -- or specify a list manually
@ -57,4 +57,4 @@ require("which-key").setup({
-- most people should not need to change this -- most people should not need to change this
n = { "o", "O" }, n = { "o", "O" },
}, },
}) }

View File

@ -1,4 +1,4 @@
require("zen-mode").setup({ require("zen-mode").setup {
window = { window = {
backdrop = 0.8, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal backdrop = 0.8, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal
width = 120, width = 120,
@ -12,4 +12,4 @@ require("zen-mode").setup({
list = false, -- disable whitespace characters list = false, -- disable whitespace characters
}, },
}, },
}) }

77
lua/custom-autocmd.lua Normal file
View File

@ -0,0 +1,77 @@
local fn = vim.fn
local api = vim.api
local utils = require("utils")
-- Display a message when the current file is not in utf-8 format.
-- Note that we need to use `unsilent` command here because of this issue:
-- https://github.com/vim/vim/issues/4379
api.nvim_create_autocmd({ "BufRead" }, {
pattern = "*",
group = api.nvim_create_augroup("non_utf8_file", { clear = true }),
callback = function()
if vim.bo.fileencoding ~= "utf-8" then
vim.notify("File not in UTF-8 format!", vim.log.levels.WARN, { title = "nvim-config" })
end
end,
})
-- highlight yanked region, see `:h lua-highlight`
api.nvim_create_autocmd({ "TextYankPost" }, {
pattern = "*",
group = api.nvim_create_augroup("highlight_yank", { clear = true }),
callback = function()
vim.highlight.on_yank { higroup = "YankColor", timeout = 300 }
end,
})
-- Auto-generate packer_compiled.lua file
api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = "*/nvim/lua/plugins.lua",
group = api.nvim_create_augroup("packer_auto_compile", { clear = true }),
callback = function(ctx)
local cmd = "source " .. ctx.file
vim.cmd(cmd)
vim.cmd("PackerCompile")
end,
})
-- Auto-create dir when saving a file, in case some intermediate directory does not exist
api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = "*",
group = api.nvim_create_augroup("auto_create_dir", { clear = true }),
callback = function(ctx)
local dir = fn.fnamemodify(ctx.file, ":p:h")
utils.may_create_dir(dir)
end,
})
-- Automatically reload the file if it is changed outside of Nvim, see https://unix.stackexchange.com/a/383044/221410.
-- It seems that `checktime` does not work in command line. We need to check if we are in command
-- line before executing this command, see also https://vi.stackexchange.com/a/20397/15292 .
api.nvim_create_augroup("auto_read", { clear = true })
api.nvim_create_autocmd({ "FileChangedShellPost" }, {
pattern = "*",
group = "auto_read",
callback = function()
vim.notify("File changed on disk. Buffer reloaded!", vim.log.levels.WARN, { title = "nvim-config" })
end,
})
api.nvim_create_autocmd({ "FocusGained", "CursorHold" }, {
pattern = "*",
group = "auto_read",
callback = function()
if fn.getcmdwintype() == "" then
vim.cmd("checktime")
end
end,
})
-- Resize all windows when we resize the terminal
api.nvim_create_autocmd("VimResized", {
group = api.nvim_create_augroup("win_autoresize", { clear = true }),
desc = "autoresize windows on resizing operation",
command = "wincmd =",
})

View File

@ -1,8 +0,0 @@
local keymap = vim.keymap
-- Go to the begining and end of current line in insert mode quickly
keymap.set('i', '<C-A>', '<HOME>')
keymap.set('i', '<C-E>', '<END>')
-- Delete the character to the right of the cursor
keymap.set('i', '<C-D>', '<DEL>')

View File

@ -1,5 +0,0 @@
-- Some utility stuff
require 'utils'
-- plugin installation
require 'plugins'

View File

@ -1,14 +1,23 @@
local utils = require("utils") local utils = require("utils")
local fn = vim.fn local fn = vim.fn
vim.g.package_home = fn.stdpath("data") .. "/site/pack/packer/" -- The root dir to install all plugins. Plugins are under opt/ or start/ sub-directory.
local packer_install_dir = vim.g.package_home .. "/opt/packer.nvim" vim.g.plugin_home = fn.stdpath("data") .. "/site/pack/packer"
local packer_repo = "https://github.com/wbthomason/packer.nvim" -- Where to install packer.nvim -- the package manager (we make it opt)
local install_cmd = string.format("10split |term git clone --depth=1 %s %s", packer_repo, packer_install_dir) local packer_dir = vim.g.plugin_home .. "/opt/packer.nvim"
-- Whether this is a fresh install, i.e., packer itself and plugins have not been installed.
local fresh_install = false
-- Auto-install packer in case it hasn't been installed. -- Auto-install packer in case it hasn't been installed.
if fn.glob(packer_install_dir) == "" then if fn.glob(packer_dir) == "" then
fresh_install = true
-- Now we need to install packer.nvim first.
local packer_repo = "https://github.com/wbthomason/packer.nvim"
local install_cmd = string.format("!git clone --depth=1 %s %s", packer_repo, packer_dir)
vim.api.nvim_echo({ { "Installing packer.nvim", "Type" } }, true, {}) vim.api.nvim_echo({ { "Installing packer.nvim", "Type" } }, true, {})
vim.cmd(install_cmd) vim.cmd(install_cmd)
end end
@ -17,352 +26,356 @@ end
vim.cmd("packadd packer.nvim") vim.cmd("packadd packer.nvim")
local packer = require("packer") local packer = require("packer")
local packer_util = require('packer.util') local packer_util = require("packer.util")
packer.startup({ packer.startup {
function(use) function(use)
-- it is recommened to put impatient.nvim before any other plugins -- it is recommended to put impatient.nvim before any other plugins
use {'lewis6991/impatient.nvim', config = [[require('impatient')]]} use { "lewis6991/impatient.nvim", config = [[require('impatient')]] }
use({"wbthomason/packer.nvim", opt = true}) use { "wbthomason/packer.nvim", opt = true }
use({"onsails/lspkind-nvim", event = "VimEnter"}) use { "onsails/lspkind-nvim", event = "VimEnter" }
-- auto-completion engine -- auto-completion engine
use {"hrsh7th/nvim-cmp", after = "lspkind-nvim", config = [[require('config.nvim-cmp')]]} use { "hrsh7th/nvim-cmp", after = "lspkind-nvim", config = [[require('config.nvim-cmp')]] }
-- nvim-cmp completion sources -- nvim-cmp completion sources
use {"hrsh7th/cmp-nvim-lsp", after = "nvim-cmp"} use { "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" }
-- use {"hrsh7th/cmp-nvim-lua", after = "nvim-cmp"} use { "hrsh7th/cmp-path", after = "nvim-cmp" }
use {"hrsh7th/cmp-path", after = "nvim-cmp"} use { "hrsh7th/cmp-buffer", after = "nvim-cmp" }
use {"hrsh7th/cmp-buffer", after = "nvim-cmp"}
use { "hrsh7th/cmp-omni", after = "nvim-cmp" } use { "hrsh7th/cmp-omni", after = "nvim-cmp" }
use { "quangnguyen30192/cmp-nvim-ultisnips", after = { "nvim-cmp", "ultisnips" } }
-- use {"hrsh7th/cmp-cmdline", after = "nvim-cmp"}
use {"quangnguyen30192/cmp-nvim-ultisnips", after = {'nvim-cmp', 'ultisnips'}}
if vim.g.is_mac then if vim.g.is_mac then
use {"hrsh7th/cmp-emoji", after = 'nvim-cmp'} use { "hrsh7th/cmp-emoji", after = "nvim-cmp" }
end end
-- nvim-lsp configuration (it relies on cmp-nvim-lsp, so it should be loaded after cmp-nvim-lsp). -- nvim-lsp configuration (it relies on cmp-nvim-lsp, so it should be loaded after cmp-nvim-lsp).
use({ "neovim/nvim-lspconfig", after = "cmp-nvim-lsp", config = [[require('config.lsp')]] }) use { "neovim/nvim-lspconfig", after = "cmp-nvim-lsp", config = [[require('config.lsp')]] }
if vim.g.is_mac then if vim.g.is_mac then
use({ "nvim-treesitter/nvim-treesitter", event = 'BufEnter', run = ":TSUpdate", config = [[require('config.treesitter')]] }) use {
"nvim-treesitter/nvim-treesitter",
event = "BufEnter",
run = ":TSUpdate",
config = [[require('config.treesitter')]],
}
end end
-- Python indent (follows the PEP8 style) -- Python indent (follows the PEP8 style)
use({ "Vimjas/vim-python-pep8-indent", ft = { "python" } }) use { "Vimjas/vim-python-pep8-indent", ft = { "python" } }
-- Python-related text object -- Python-related text object
use({ "jeetsukumaran/vim-pythonsense", ft = { "python" } }) use { "jeetsukumaran/vim-pythonsense", ft = { "python" } }
use({"machakann/vim-swap", event = "VimEnter"}) use { "machakann/vim-swap", event = "VimEnter" }
-- IDE for Lisp -- IDE for Lisp
if utils.executable("sbcl") then if utils.executable("sbcl") then
-- use 'kovisoft/slimv' -- use 'kovisoft/slimv'
use({ "vlime/vlime", rtp = "vim/", ft = { "lisp" } }) use { "vlime/vlime", rtp = "vim/", ft = { "lisp" } }
end end
-- Super fast buffer jump -- Super fast buffer jump
use { use {
'phaazon/hop.nvim', "phaazon/hop.nvim",
event = "VimEnter", event = "VimEnter",
config = function() config = function()
vim.defer_fn(function() require('config.nvim_hop') end, 2000) vim.defer_fn(function()
end require("config.nvim_hop")
end, 2000)
end,
} }
-- Clear highlight search automatically for you
-- use({"romainl/vim-cool", event = "VimEnter"})
-- Show match number and index for searching -- Show match number and index for searching
use { use {
'kevinhwang91/nvim-hlslens', "kevinhwang91/nvim-hlslens",
branch = 'main', branch = "main",
keys = {{'n', '*'}, {'n', '#'}, {'n', 'n'}, {'n', 'N'}}, keys = { { "n", "*" }, { "n", "#" }, { "n", "n" }, { "n", "N" } },
config = [[require('config.hlslens')]] config = [[require('config.hlslens')]],
} }
-- Stay after pressing * and search selected text -- Stay after pressing * and search selected text
use({"haya14busa/vim-asterisk", event = 'VimEnter'}) use { "haya14busa/vim-asterisk", event = "VimEnter" }
-- File search, tag search and more -- File search, tag search and more
if vim.g.is_win then if vim.g.is_win then
use({"Yggdroot/LeaderF", cmd = "Leaderf"}) use { "Yggdroot/LeaderF", cmd = "Leaderf" }
else else
use({ "Yggdroot/LeaderF", cmd = "Leaderf", run = ":LeaderfInstallCExtension" }) use { "Yggdroot/LeaderF", cmd = "Leaderf", run = ":LeaderfInstallCExtension" }
end end
use { use {
'nvim-telescope/telescope.nvim', cmd = 'Telescope', "nvim-telescope/telescope.nvim",
requires = { {'nvim-lua/plenary.nvim'} } cmd = "Telescope",
requires = { { "nvim-lua/plenary.nvim" } },
} }
-- search emoji and other symbols -- search emoji and other symbols
use {'nvim-telescope/telescope-symbols.nvim', after = 'telescope.nvim'} use { "nvim-telescope/telescope-symbols.nvim", after = "telescope.nvim" }
-- Another similar plugin is command-t
-- use 'wincent/command-t'
-- Another grep tool (similar to Sublime Text Ctrl+Shift+F)
-- use 'dyng/ctrlsf.vim'
-- A grepping tool
-- use {'mhinz/vim-grepper', cmd = {'Grepper', '<plug>(GrepperOperator)'}}
-- A list of colorscheme plugin you may want to try. Find what suits you. -- A list of colorscheme plugin you may want to try. Find what suits you.
use({"lifepillar/vim-gruvbox8", opt = true}) use { "lifepillar/vim-gruvbox8", opt = true }
use({"navarasu/onedark.nvim", opt = true}) use { "navarasu/onedark.nvim", opt = true }
use({"sainnhe/edge", opt = true}) use { "sainnhe/edge", opt = true }
use({"sainnhe/sonokai", opt = true}) use { "sainnhe/sonokai", opt = true }
use({"sainnhe/gruvbox-material", opt = true}) use { "sainnhe/gruvbox-material", opt = true }
use({"shaunsingh/nord.nvim", opt = true}) use { "shaunsingh/nord.nvim", opt = true }
use({"NTBBloodbath/doom-one.nvim", opt = true}) use { "NTBBloodbath/doom-one.nvim", opt = true }
use({"sainnhe/everforest", opt = true}) use { "sainnhe/everforest", opt = true }
use({"EdenEast/nightfox.nvim", opt = true}) use { "EdenEast/nightfox.nvim", opt = true }
use({"rebelot/kanagawa.nvim", opt = true}) use { "rebelot/kanagawa.nvim", opt = true }
use({"catppuccin/nvim", as = "catppuccin", opt = true}) use { "catppuccin/nvim", as = "catppuccin", opt = true }
-- Show git change (change, delete, add) signs in vim sign column use { "kyazdani42/nvim-web-devicons", event = "VimEnter" }
use({"mhinz/vim-signify", event = 'BufEnter'})
-- Another similar plugin
-- use 'airblade/vim-gitgutter'
use {'kyazdani42/nvim-web-devicons', event = 'VimEnter'}
use { use {
'nvim-lualine/lualine.nvim', "nvim-lualine/lualine.nvim",
event = 'VimEnter', event = "VimEnter",
config = [[require('config.statusline')]] config = [[require('config.statusline')]],
} }
use({ "akinsho/bufferline.nvim", event = "VimEnter", config = [[require('config.bufferline')]] }) use { "akinsho/bufferline.nvim", event = "VimEnter", config = [[require('config.bufferline')]] }
-- fancy start screen -- fancy start screen
use { 'glepnir/dashboard-nvim', config = [[require('config.dashboard-nvim')]] } use { "glepnir/dashboard-nvim", event = "VimEnter", config = [[require('config.dashboard-nvim')]] }
use({ use {
"lukas-reineke/indent-blankline.nvim", "lukas-reineke/indent-blankline.nvim",
event = 'VimEnter', event = "VimEnter",
config = [[require('config.indent-blankline')]] config = [[require('config.indent-blankline')]],
}) }
-- Highlight URLs inside vim -- Highlight URLs inside vim
use({"itchyny/vim-highlighturl", event = "VimEnter"}) use { "itchyny/vim-highlighturl", event = "VimEnter" }
-- notification plugin -- notification plugin
use({ use {
"rcarriga/nvim-notify", "rcarriga/nvim-notify",
event = "BufEnter", event = "BufEnter",
config = function() config = function()
vim.defer_fn(function() require('config.nvim-notify') end, 2000) vim.defer_fn(function()
end require("config.nvim-notify")
}) end, 2000)
end,
}
-- For Windows and Mac, we can open an URL in the browser. For Linux, it may -- For Windows and Mac, we can open an URL in the browser. For Linux, it may
-- not be possible since we maybe in a server which disables GUI. -- not be possible since we maybe in a server which disables GUI.
if vim.g.is_win or vim.g.is_mac then if vim.g.is_win or vim.g.is_mac then
-- open URL in browser -- open URL in browser
use({"tyru/open-browser.vim", event = "VimEnter"}) use { "tyru/open-browser.vim", event = "VimEnter" }
end end
-- Only install these plugins if ctags are installed on the system -- Only install these plugins if ctags are installed on the system
if utils.executable("ctags") then if utils.executable("ctags") then
-- show file tags in vim window -- show file tags in vim window
use({"liuchengxu/vista.vim", cmd = "Vista"}) use { "liuchengxu/vista.vim", cmd = "Vista" }
end end
-- Snippet engine and snippet template -- Snippet engine and snippet template
use({"SirVer/ultisnips", event = 'InsertEnter'}) use { "SirVer/ultisnips", event = "InsertEnter" }
use({ "honza/vim-snippets", after = 'ultisnips'}) use { "honza/vim-snippets", after = "ultisnips" }
-- Automatic insertion and deletion of a pair of characters -- Automatic insertion and deletion of a pair of characters
use({"Raimondi/delimitMate", event = "InsertEnter"}) use { "Raimondi/delimitMate", event = "InsertEnter" }
-- Comment plugin -- Comment plugin
use({"tpope/vim-commentary", event = "VimEnter"}) use { "tpope/vim-commentary", event = "VimEnter" }
-- Multiple cursor plugin like Sublime Text? -- Multiple cursor plugin like Sublime Text?
-- use 'mg979/vim-visual-multi' -- use 'mg979/vim-visual-multi'
-- Autosave files on certain events -- Autosave files on certain events
use({"907th/vim-auto-save", event = "InsertEnter"}) use { "907th/vim-auto-save", event = "InsertEnter" }
-- Show undo history visually -- Show undo history visually
use({"simnalamburt/vim-mundo", cmd = {"MundoToggle", "MundoShow"}}) use { "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } }
-- Manage your yank history -- Manage your yank history
if vim.g.is_win or vim.g.is_mac then if vim.g.is_win or vim.g.is_mac then
use({"svermeulen/vim-yoink", event = "VimEnter"}) use { "svermeulen/vim-yoink", event = "VimEnter" }
end end
-- Handy unix command inside Vim (Rename, Move etc.) -- Handy unix command inside Vim (Rename, Move etc.)
use({"tpope/vim-eunuch", cmd = {"Rename", "Delete"}}) use { "tpope/vim-eunuch", cmd = { "Rename", "Delete" } }
-- Repeat vim motions -- Repeat vim motions
use({"tpope/vim-repeat", event = "VimEnter"}) use { "tpope/vim-repeat", event = "VimEnter" }
-- Show the content of register in preview window use { "nvim-zh/better-escape.vim", event = { "InsertEnter" } }
-- Plug 'junegunn/vim-peekaboo'
use({ "jdhao/better-escape.vim", event = { "InsertEnter" } })
if vim.g.is_mac then if vim.g.is_mac then
use({ "lyokha/vim-xkbswitch", event = { "InsertEnter" } }) use { "lyokha/vim-xkbswitch", event = { "InsertEnter" } }
elseif vim.g.is_win then elseif vim.g.is_win then
use({ "Neur1n/neuims", event = { "InsertEnter" } }) use { "Neur1n/neuims", event = { "InsertEnter" } }
end end
-- Syntax check and make
-- use 'neomake/neomake'
-- Auto format tools -- Auto format tools
use({ "sbdchd/neoformat", cmd = { "Neoformat" } }) use { "sbdchd/neoformat", cmd = { "Neoformat" } }
-- use 'Chiel92/vim-autoformat'
-- Git command inside vim -- Git command inside vim
use({ "tpope/vim-fugitive", event = "User InGitRepo" }) use { "tpope/vim-fugitive", event = "User InGitRepo", config = [[require('config.fugitive')]] }
-- Better git log display -- Better git log display
use({ "rbong/vim-flog", requires = "tpope/vim-fugitive", cmd = { "Flog" } }) use { "rbong/vim-flog", requires = "tpope/vim-fugitive", cmd = { "Flog" } }
use({ "christoomey/vim-conflicted", requires = "tpope/vim-fugitive", cmd = {"Conflicted"}}) use { "christoomey/vim-conflicted", requires = "tpope/vim-fugitive", cmd = { "Conflicted" } }
use({ "kevinhwang91/nvim-bqf", ft = "qf", config = [[require('config.bqf')]] }) use {
"ruifm/gitlinker.nvim",
requires = "nvim-lua/plenary.nvim",
event = "User InGitRepo",
config = [[require('config.git-linker')]],
}
-- Show git change (change, delete, add) signs in vim sign column
use { "lewis6991/gitsigns.nvim", config = [[require('config.gitsigns')]] }
-- Better git commit experience -- Better git commit experience
use({"rhysd/committia.vim", opt = true, setup = [[vim.cmd('packadd committia.vim')]]}) use { "rhysd/committia.vim", opt = true, setup = [[vim.cmd('packadd committia.vim')]] }
use { "kevinhwang91/nvim-bqf", ft = "qf", config = [[require('config.bqf')]] }
-- Another markdown plugin -- Another markdown plugin
use({ "plasticboy/vim-markdown", ft = { "markdown" } }) use { "plasticboy/vim-markdown", ft = { "markdown" } }
-- Faster footnote generation -- Faster footnote generation
use({ "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } }) use { "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } }
-- Vim tabular plugin for manipulate tabular, required by markdown plugins -- Vim tabular plugin for manipulate tabular, required by markdown plugins
use({ "godlygeek/tabular", cmd = { "Tabularize" } }) use { "godlygeek/tabular", cmd = { "Tabularize" } }
-- Markdown JSON header highlight plugin -- Markdown JSON header highlight plugin
use({ "elzr/vim-json", ft = { "json", "markdown" } }) use { "elzr/vim-json", ft = { "json", "markdown" } }
-- Markdown previewing (only for Mac and Windows) -- Markdown previewing (only for Mac and Windows)
if vim.g.is_win or vim.g.is_mac then if vim.g.is_win or vim.g.is_mac then
use({ use {
"iamcco/markdown-preview.nvim", "iamcco/markdown-preview.nvim",
run = function() run = function()
fn["mkdp#util#install"]() fn["mkdp#util#install"]()
end, end,
ft = { "markdown" }, ft = { "markdown" },
}) }
end end
use({'folke/zen-mode.nvim', cmd = 'ZenMode', config = [[require('config.zen-mode')]]}) use { "folke/zen-mode.nvim", cmd = "ZenMode", config = [[require('config.zen-mode')]] }
if vim.g.is_mac then if vim.g.is_mac then
use({ "rhysd/vim-grammarous", ft = { "markdown" } }) use { "rhysd/vim-grammarous", ft = { "markdown" } }
end end
use({"chrisbra/unicode.vim", event = "VimEnter"}) use { "chrisbra/unicode.vim", event = "VimEnter" }
-- Additional powerful text object for vim, this plugin should be studied -- Additional powerful text object for vim, this plugin should be studied
-- carefully to use its full power -- carefully to use its full power
use({"wellle/targets.vim", event = "VimEnter"}) use { "wellle/targets.vim", event = "VimEnter" }
-- Plugin to manipulate character pairs quickly -- Plugin to manipulate character pairs quickly
-- use 'tpope/vim-surround' use { "machakann/vim-sandwich", event = "VimEnter" }
use({"machakann/vim-sandwich", event = "VimEnter"})
-- Add indent object for vim (useful for languages like Python) -- Add indent object for vim (useful for languages like Python)
use({"michaeljsmith/vim-indent-object", event = "VimEnter"}) use { "michaeljsmith/vim-indent-object", event = "VimEnter" }
-- Only use these plugin on Windows and Mac and when LaTeX is installed -- Only use these plugin on Windows and Mac and when LaTeX is installed
if vim.g.is_win or vim.g.is_mac and utils.executable("latex") then if vim.g.is_win or vim.g.is_mac and utils.executable("latex") then
use({ "lervag/vimtex", ft = { "tex" } }) use { "lervag/vimtex", ft = { "tex" } }
-- use {'matze/vim-tex-fold', ft = {'tex', }}
-- use 'Konfekt/FastFold'
end end
-- Since tmux is only available on Linux and Mac, we only enable these plugins -- Since tmux is only available on Linux and Mac, we only enable these plugins
-- for Linux and Mac -- for Linux and Mac
if utils.executable("tmux") then if utils.executable("tmux") then
-- .tmux.conf syntax highlighting and setting check -- .tmux.conf syntax highlighting and setting check
use({ "tmux-plugins/vim-tmux", ft = { "tmux" } }) use { "tmux-plugins/vim-tmux", ft = { "tmux" } }
end end
-- Modern matchit implementation -- Modern matchit implementation
use({"andymass/vim-matchup", event = "VimEnter"}) use { "andymass/vim-matchup", event = "VimEnter" }
-- Smoothie motions -- Smoothie motions
-- use 'psliwka/vim-smoothie' use {
use({
"karb94/neoscroll.nvim", "karb94/neoscroll.nvim",
event = "VimEnter", event = "VimEnter",
config = function() config = function()
vim.defer_fn(function() require('config.neoscroll') end, 2000) vim.defer_fn(function()
end require("config.neoscroll")
}) end, 2000)
end,
}
use({"tpope/vim-scriptease", cmd = {"Scriptnames", "Message", "Verbose"}}) use { "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } }
-- Asynchronous command execution -- Asynchronous command execution
use({ "skywind3000/asyncrun.vim", opt = true, cmd = { "AsyncRun" } }) use { "skywind3000/asyncrun.vim", opt = true, cmd = { "AsyncRun" } }
-- Another asynchronous plugin
-- Plug 'tpope/vim-dispatch'
use({ "cespare/vim-toml", ft = { "toml" }, branch = "main" }) use { "cespare/vim-toml", ft = { "toml" }, branch = "main" }
-- Edit text area in browser using nvim -- Edit text area in browser using nvim
if vim.g.is_win or vim.g.is_mac then if vim.g.is_win or vim.g.is_mac then
use({ use {
"glacambre/firenvim", "glacambre/firenvim",
run = function() fn["firenvim#install"](0) end, run = function()
fn["firenvim#install"](0)
end,
opt = true, opt = true,
setup = [[vim.cmd('packadd firenvim')]], setup = [[vim.cmd('packadd firenvim')]],
}) }
end end
-- Debugger plugin -- Debugger plugin
if vim.g.is_win or vim.g.is_linux then if vim.g.is_win or vim.g.is_linux then
use({ "sakhnik/nvim-gdb", run = { "bash install.sh" }, opt = true, setup = [[vim.cmd('packadd nvim-gdb')]] }) use { "sakhnik/nvim-gdb", run = { "bash install.sh" }, opt = true, setup = [[vim.cmd('packadd nvim-gdb')]] }
end end
-- Session management plugin -- Session management plugin
use({"tpope/vim-obsession", cmd = 'Obsession'}) use { "tpope/vim-obsession", cmd = "Obsession" }
if vim.g.is_linux then if vim.g.is_linux then
use({"ojroques/vim-oscyank", cmd = {'OSCYank', 'OSCYankReg'}}) use { "ojroques/vim-oscyank", cmd = { "OSCYank", "OSCYankReg" } }
end end
-- The missing auto-completion for cmdline! -- The missing auto-completion for cmdline!
use({"gelguy/wilder.nvim", opt = true, setup = [[vim.cmd('packadd wilder.nvim')]]}) use { "gelguy/wilder.nvim", opt = true, setup = [[vim.cmd('packadd wilder.nvim')]] }
-- showing keybindings -- showing keybindings
use {"folke/which-key.nvim", use {
event = "VimEnter", "folke/which-key.nvim",
config = function() event = "VimEnter",
vim.defer_fn(function() require('config.which-key') end, 2000) config = function()
end vim.defer_fn(function()
require("config.which-key")
end, 2000)
end,
} }
-- show and trim trailing whitespaces -- show and trim trailing whitespaces
use {'jdhao/whitespace.nvim', event = 'VimEnter'} use { "jdhao/whitespace.nvim", event = "VimEnter" }
-- file explorer -- file explorer
use { use {
'kyazdani42/nvim-tree.lua', "kyazdani42/nvim-tree.lua",
requires = { 'kyazdani42/nvim-web-devicons' }, requires = { "kyazdani42/nvim-web-devicons" },
config = [[require('config.nvim-tree')]] config = [[require('config.nvim-tree')]],
} }
use { 'ii14/emmylua-nvim', ft = 'lua' } use { "ii14/emmylua-nvim", ft = "lua" }
use { "j-hui/fidget.nvim", after = "nvim-lspconfig", config = [[require('config.fidget-nvim')]] }
end, end,
config = { config = {
max_jobs = 16, max_jobs = 16,
compile_path = packer_util.join_paths(fn.stdpath('data'), 'site', 'lua', 'packer_compiled.lua'), compile_path = packer_util.join_paths(fn.stdpath("data"), "site", "lua", "packer_compiled.lua"),
}, },
}) }
local status, _ = pcall(require, 'packer_compiled') -- For fresh install, we need to install plugins. Otherwise, we just need to require `packer_compiled.lua`.
if not status then if fresh_install then
vim.notify("Error requiring packer_compiled.lua: run PackerSync to fix!") -- We run packer.sync() here, because only after packer.startup, can we know which plugins to install.
-- So plugin installation should be done after the startup process.
packer.sync()
else
local status, _ = pcall(require, "packer_compiled")
if not status then
local msg = "File packer_compiled.lua not found: run PackerSync to fix!"
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
end
end end

View File

@ -1,10 +1,5 @@
local fn = vim.fn local fn = vim.fn
-- inspect something
function inspect(item)
vim.pretty_print(item)
end
local M = {} local M = {}
function M.executable(name) function M.executable(name)
@ -15,14 +10,57 @@ function M.executable(name)
return false return false
end end
function M.may_create_dir() --- check whether a feature exists in Nvim
local fpath = fn.expand('<afile>') --- @feat: string
local parent_dir = fn.fnamemodify(fpath, ":p:h") --- the feature name, like `nvim-0.7` or `unix`.
local res = fn.isdirectory(parent_dir) --- return: bool
M.has = function(feat)
if fn.has(feat) == 1 then
return true
end
return false
end
--- Create a dir if it does not exist
function M.may_create_dir(dir)
local res = fn.isdirectory(dir)
if res == 0 then if res == 0 then
fn.mkdir(parent_dir, 'p') fn.mkdir(dir, "p")
end end
end end
function M.get_nvim_version()
local actual_ver = vim.version()
local nvim_ver_str = string.format("%d.%d.%d", actual_ver.major, actual_ver.minor, actual_ver.patch)
return nvim_ver_str
end
--- Generate random integers in the range [Low, High], inclusive,
--- adapted from https://stackoverflow.com/a/12739441/6064933
--- @low: the lower value for this range
--- @high: the upper value for this range
function M.rand_int(low, high)
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
math.randomseed(os.time())
return math.random(low, high)
end
--- Select a random element from a sequence/list.
--- @seq: the sequence to choose an element
function M.rand_element(seq)
local idx = M.rand_int(1, #seq)
return seq[idx]
end
function M.add_pack(name)
local status, error = pcall(vim.cmd, "packadd " .. name)
return status
end
return M return M

View File

@ -47,7 +47,7 @@ $0
endsnippet endsnippet
snippet font "HTML font tag" snippet font "HTML font tag"
<font color="${1:red}">${2:TEXT}</font> <font color="${1:blue}">${2:TEXT}</font>
endsnippet endsnippet
snippet link "Markdown links" snippet link "Markdown links"

View File

@ -2,7 +2,7 @@ snippet use "usepackage" b
\usepackage{${1:package}} \usepackage{${1:package}}
endsnippet endsnippet
snippet eqa "equation enviroment" b snippet eqa "equation environment" b
\begin{equation}\label{$1} \begin{equation}\label{$1}
$2 $2
\end{equation} \end{equation}

View File

@ -430,3 +430,13 @@ metatable
open3d open3d
pyntcloud pyntcloud
param param
reddit
viml
PostgreSQL
CNY
wechat
ziroom
Postgres
plpgsql
postgres
PySpark