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

82 Commits

Author SHA1 Message Date
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
jdhao
4d7fd6580a Merge pull request #58 from jdhao/mapping-doc
update readme about mappings
2022-08-11 01:29:33 +08:00
jdhao
f492a94db6 update readme about mappings 2022-08-11 01:28:14 +08:00
jdhao
0c92d9a018 update mappings
1. add mapping for gJ
2. remove mappings for <C-H>, since I rarely use them
2022-08-10 21:24:14 +08:00
jdhao
369687b047 refactor: disable showing trailing space and mix indent for non-modifiable buffers 2022-08-07 00:25:08 +08:00
jdhao
54908dfe9f fix: dashboard map is not local 2022-08-07 00:24:37 +08:00
jdhao
2e5f5c5991 update demo image in README 2022-08-07 00:12:55 +08:00
jdhao
8291b15599 remove alpha-nvim, use dashboard-nvim 2022-08-07 00:01:23 +08:00
jdhao
3de31f7d0a disable language command in macOS for now
Due to packaging issue, nvim version 0.7.2 for macOS does not have
`:language` command built in, see also neovim/neovim#19127.
2022-08-06 22:36:49 +08:00
jdhao
6b59c268f9 Merge pull request #57 from jdhao/fix-trailing-space
fix: trailing white sapces do not show as expected
2022-08-06 17:22:32 +08:00
jdhao
dd550dc3d0 fix: trailing white sapces do not show as expected
The plugin whitespace.nvim has changed its internal implementation.
It is not reliable to depend on external plugins.
2022-08-06 17:19:13 +08:00
jdhao
3aae07df56 Merge pull request #56 from jdhao/js-setup
add setup for javascript
2022-08-06 14:23:31 +08:00
jdhao
ed5ddf60cc add setup for javascript 2022-08-06 14:20:28 +08:00
jdhao
bcdc8d3f66 small fix 2022-08-01 20:57:37 +08:00
jdhao
5498a05bf7 revert to vim-auto-save
auto-save.nvim is erroring out
2022-08-01 01:14:09 +08:00
jdhao
644f8b6e2d add theme catppuccin 2022-07-28 01:32:41 +08:00
jdhao
3af7dd51b8 update packer config 2022-07-28 01:22:10 +08:00
jdhao
e0fc068f2e update nvim-cmp conf since cmp-nvim-lua is removed 2022-07-28 00:51:48 +08:00
jdhao
58ed71f870 use emmylua-nvim instead of cmp-nvim-lua for better completion 2022-07-27 21:08:03 +08:00
jdhao
aae9a7b7a7 update winblend 2022-07-27 13:17:22 +08:00
jdhao
33270f3257 add command ToPDF 2022-07-19 01:18:26 +08:00
jdhao
99d5a0343b update title str format 2022-07-11 23:14:16 +08:00
jdhao
3678da1b3c update titlestring 2022-07-02 16:47:58 +08:00
jdhao
a8fdbf3573 disable showing current theme used 2022-06-28 00:36:37 +08:00
jdhao
351ba5fc63 update option shortmess 2022-06-28 00:36:19 +08:00
37 changed files with 812 additions and 424 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"
no_call_parentheses = true

View File

@@ -36,7 +36,7 @@
# Introduction
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).
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).
+ 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).
+ 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).
+ 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).
@@ -88,16 +88,16 @@ and how to set up on different platforms (Linux, macOS, and Windows).
For more UI demos, check [here](https://github.com/jdhao/nvim-config/issues/15).
## Start screen with alpha-nvim
## Start screen with dashboard-nvim
<p align="center">
<img src="https://user-images.githubusercontent.com/16662357/139459989-0537ded4-c119-4749-99bf-b551ca1ba118.jpg" width="800">
<img src="https://user-images.githubusercontent.com/16662357/183256752-fb23b215-a6b8-4646-beed-9999f52d53f1.png" width="800">
</p>
## fuzzy finding using LeaderF
## File fuzzy finding using LeaderF
<p align="center">
<img src="https://user-images.githubusercontent.com/16662357/139462025-7bce98c5-d2d5-413f-9659-20545865cdca.gif" width="800">
<img src="https://user-images.githubusercontent.com/16662357/183257017-2d9d7605-3c4b-4e1d-8955-30998f9b6f28.gif" width="800">
</p>
## Code autocompletion with nvim-cmp
@@ -142,43 +142,46 @@ Go to a string starting with `se`
Some of the shortcuts I use frequently are listed here. In the following shortcuts, `<leader>` represents ASCII character `,`.
| Shortcut | Mode | platform | Description |
|-------------------|---------------|-----------------|------------------------------------------------------------------|
| `<leader>ff` | Normal | Linux/macOS/Win | Fuzzy file searching in a floating window |
| `<leader>fh` | Normal | Linux/macOS/Win | Fuzzy help file grepping in a floating window |
| `<leader>fg` | Normal | Linux/macOS/Win | Fuzzy project-wide grepping in a floating window |
| `<leader>ft` | Normal | Linux/macOS/Win | Fuzzy buffer tag searching in a floating window |
| `<leader>fb` | Normal | Linux/macOS/Win | Fuzzy buffer switching in a floating window |
| `<leader><Space>` | Normal | Linux/macOS/Win | Remove trailing white spaces |
| `<leader>v` | Normal | Linux/macOS/Win | Reselect last pasted text |
| `<leader>ev` | Normal | Linux/macOS/Win | Edit Nvim config in a new tabpage |
| `<leader>sv` | Normal | Linux/macOS/Win | Reload Nvim config |
| `<leader>st` | Normal | Linux/macOS/Win | Show highlight group for cursor text |
| `<leader>q` | Normal | Linux/macOS/Win | Quit current window |
| `<leader>Q` | Normal | Linux/macOS/Win | Quit all window and close Nvim |
| `<leader>w` | Normal | Linux/macOS/Win | Save current buffer content |
| `<leader>y` | Normal | Linux/macOS/Win | Copy the content of entire buffer to default register |
| `<leader>cl` | Normal | Linux/macOS/Win | Toggle cursor column |
| `<leader>cd` | Normal | Linux/macOS/Win | Change current working directory to to the dir of current buffer |
| `<space>t` | Normal | Linux/macOS/Win | Toggle tag window (show project tags in the right window) |
| `<leader>gs` | Normal | Linux/macOS/Win | Show Git status result |
| `<leader>gw` | Normal | Linux/macOS/Win | Run Git add for current file |
| `<leader>gd` | Normal | Linux/macOS/Win | Run git diff for current file |
| `<leader>gc` | Normal | Linux/macOS/Win | Run git commit |
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
| `<F9>` | Normal | Linux/macOS/Win | Run current source file (for Python, C++) |
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
| `\x` | Normal | Linux/macOS/Win | Close location or quickfix window |
| `\d` | Normal | Linux/macOS/Win | Close current buffer and go to previous buffer |
| `{count}gb` | Normal | Linux/macOS/Win | Go to buffer {count} or next buffer in the buffer list. |
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection |
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
| Shortcut | Mode | platform | Description |
|-------------------|---------------|-----------------|--------------------------------------------------------------------------|
| `<leader>ff` | Normal | Linux/macOS/Win | Fuzzy file searching in a floating window |
| `<leader>fh` | Normal | Linux/macOS/Win | Fuzzy help file grepping in a floating window |
| `<leader>fg` | Normal | Linux/macOS/Win | Fuzzy project-wide grepping in a floating window |
| `<leader>ft` | Normal | Linux/macOS/Win | Fuzzy buffer tag searching in a floating window |
| `<leader>fb` | Normal | Linux/macOS/Win | Fuzzy buffer switching in a floating window |
| `<leader><Space>` | Normal | Linux/macOS/Win | Remove trailing white spaces |
| `<leader>v` | Normal | Linux/macOS/Win | Reselect last pasted text |
| `<leader>ev` | Normal | Linux/macOS/Win | Edit Nvim config in a new tabpage |
| `<leader>sv` | Normal | Linux/macOS/Win | Reload Nvim config |
| `<leader>st` | Normal | Linux/macOS/Win | Show highlight group for cursor text |
| `<leader>q` | Normal | Linux/macOS/Win | Quit current window |
| `<leader>Q` | Normal | Linux/macOS/Win | Quit all window and close Nvim |
| `<leader>w` | Normal | Linux/macOS/Win | Save current buffer content |
| `<leader>y` | Normal | Linux/macOS/Win | Copy the content of entire buffer to default register |
| `<leader>cl` | Normal | Linux/macOS/Win | Toggle cursor column |
| `<leader>cd` | Normal | Linux/macOS/Win | Change current working directory to to the dir of current buffer |
| `<space>t` | Normal | Linux/macOS/Win | Toggle tag window (show project tags in the right window) |
| `<leader>gs` | Normal | Linux/macOS/Win | Show Git status result |
| `<leader>gw` | Normal | Linux/macOS/Win | Run Git add for current file |
| `<leader>gd` | Normal | Linux/macOS/Win | Run git diff for current file |
| `<leader>gc` | Normal | Linux/macOS/Win | Run git commit |
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
| `<F9>` | Normal | Linux/macOS/Win | Compile&run current source file (for C++, LaTeX, Lua, Python) |
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
| `\x` | Normal | Linux/macOS/Win | Close location or quickfix window |
| `\d` | Normal | Linux/macOS/Win | Close current buffer and go to previous buffer |
| `{count}gb` | Normal | Linux/macOS/Win | Go to buffer `{count}` or next buffer in the buffer list. |
| `{operator}iB` | Normal | Linux/macOS/Win | Operate in the whole buffer, `{operator}` can be `v`, `y`, `c`, `d` etc. |
| `Alt-k` | Normal | Linux/macOS/Win | Move current line or selected lines up |
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
| `Alt-Shift-m` | Normal | macOS/Win | Stopping Markdown previewing in system browser |
| `ob` | Normal/Visual | macOS/Win | Open link under cursor or search visual selection |
| `ctrl-u` | Insert | Linux/macOS/Win | Turn word under cursor to upper case |
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
# Custom commands

View File

@@ -0,0 +1,8 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
set tabstop=2 " number of visual spaces per TAB
set softtabstop=2 " number of spaces in tab when editing
set shiftwidth=2 " number of spaces to use for autoindent
set expandtab " expand tab to spaces so that tabs are spaces

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
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
" 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.
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
endif

View File

@@ -27,21 +27,6 @@ function! utils#HasColorscheme(name) abort
return !empty(globpath(&runtimepath, l:pat))
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
function! utils#VimFolds(lnum) abort
" get content of current line and the line below
@@ -131,9 +116,11 @@ function! utils#Get_titlestr() abort
if g:is_linux
let l:title_str = hostname() . ' '
endif
let l:title_str = l:title_str . expand('%:p:~') . ' '
if &buflisted
let l:title_str = l:title_str . strftime('%Y-%m-%d %H:%M',getftime(expand('%')))
let l:buf_path = expand('%:p:~')
let l:title_str = l:title_str . l:buf_path . ' '
if &buflisted && l:buf_path != ""
let l:title_str = l:title_str . strftime('%Y-%m-%d %H:%M:%S%z', getftime(expand('%')))
endif
return l:title_str
@@ -154,7 +141,7 @@ function! utils#Inside_git_repo() abort
if match(res, 'true') == -1
return v:false
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).
" See also https://github.com/wbthomason/packer.nvim/discussions/534.
doautocmd User InGitRepo
@@ -196,14 +183,3 @@ function! utils#MultiEdit(patterns) abort
endfor
endfor
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
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
autocmd!
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
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
autocmd!
autocmd BufEnter * call s:quit_current_win()
@@ -125,13 +99,25 @@ augroup git_repo_check
autocmd VimEnter,DirChanged * call utils#Inside_git_repo()
augroup END
" Auto-generate packer_compiled.lua file
augroup packer_auto_compile
" ref: https://vi.stackexchange.com/a/169/15292
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 BufWritePost */nvim/lua/plugins.lua source <afile> | PackerCompile
autocmd BufReadPre * call s:handle_large_file()
augroup END
augroup auto_create_dir
autocmd!
autocmd BufWritePre * lua require('utils').may_create_dir()
augroup END
" Load auto-command defined in Lua
lua require("custom-autocmd")

126
core/colorschemes.lua Normal file
View File

@@ -0,0 +1,126 @@
--- 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()

View File

@@ -37,7 +37,9 @@ let g:mapleader = ','
let g:vimsyn_embed = 'l'
" Use English as main language
language en_US.utf-8
if !g:is_mac
language en_US.utf-8
endif
" use filetype.lua instead of filetype.vim
let g:do_filetype_lua = 1

View File

@@ -87,10 +87,10 @@ xnoremap > >gv
inoremap <expr> <tab> pumvisible() ? "\<c-n>" : "\<tab>"
inoremap <expr> <s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
" Edit and reload init.vim quickly
" Edit and reload nvim config file 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>
\ call v:lua.vim.notify("Nvim config successfully reloaded!", 2, {'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])
@@ -101,10 +101,6 @@ nnoremap / /\v
" Search in selected region
xnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>
" Find and replace (like Sublime Text 3)
nnoremap <C-H> :%s/
xnoremap <C-H> :s/
" 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>
@@ -171,6 +167,7 @@ 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 [',', '.', '!', '?', ';', ':']

View File

@@ -112,6 +112,9 @@ set shortmess+=c
" choice, IMHO.
set shortmess+=S
" Disable showing intro message (:intro)
set shortmess+=I
" Completion behaviour
" set completeopt+=noinsert " Auto select the first completion entry
set completeopt+=menuone " Show menu even if there is only one item
@@ -120,7 +123,7 @@ set completeopt-=preview " Disable the preview window
set pumheight=10 " Maximum number of items to show in popup menu
set pumblend=10 " pseudo transparency for completion menu
set winblend=5 " pseudo transparency for floating window
set winblend=0 " pseudo transparency for floating window
" Insert mode key word completion setting
set complete+=kspell complete-=w complete-=b complete-=u complete-=t

View File

@@ -1,7 +1,7 @@
scriptencoding utf-8
" Plugin specification and lua stuff
lua require('lua-init')
lua require('plugins')
" Use short names for common plugin manager commands to simplify typing.
" To use these shortcuts: first activate command line with `:`, then input the
@@ -260,7 +260,7 @@ omap s <Nop>
""""""""""""""""""""""""""""vimtex settings"""""""""""""""""""""""""""""
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/.
function! s:write_server_name() abort
let nvim_server_file = (has('win32') ? $TEMP : '/tmp') . '/vimtexserver.txt'
@@ -371,9 +371,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
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
endif
@@ -425,3 +432,6 @@ function! s:wilder_init() abort
echohl Error |echomsg "Wilder.nvim missing: run :PackerSync to fix."|echohl None
endtry
endfunction
""""""""""""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""""""""""
let g:auto_save = 1 " enable AutoSave on Vim startup

View File

@@ -1,91 +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
" 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',
\ }
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 == 'info'
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
## 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.
## Python
## Dependencies
### Python
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).
@@ -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`,
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.
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
```
## 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.
@@ -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`.
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/).
For Linux, you can use the following script:
@@ -60,7 +99,7 @@ source ~/.bash_profile
# 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:
@@ -70,7 +109,7 @@ npm install -g vim-language-server
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.
@@ -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.
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.
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.
## Ripgrep
### Ripgrep
[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.
@@ -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.
## Linters
### Linters
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.
@@ -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.
## 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.
# Install Nvim
## Install Nvim
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).
## 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 also use the system package manager to install nvim,
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.
@@ -164,7 +186,7 @@ choco 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:
@@ -175,9 +197,11 @@ brew install neovim
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**.
# 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.
@@ -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
```
## How to install this configuration
### How to install this configuration
On Linux and macOS, the directory is `~/.config/nvim`.
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.
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.

View File

@@ -120,6 +120,35 @@ fi
# Install 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 #
#######################################################################
@@ -145,8 +174,8 @@ if [[ -z "$(command -v rg)" ]] && [[ ! -f "$RIPGREP_DIR/rg" ]]; then
fi
# set up manpath and zsh completion for ripgrep
mkdir -p $HOME/tools/ripgrep/doc/man/man1
mv $HOME/tools/ripgrep/doc/rg.1 $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"
if [[ "$USE_BASH_SHELL" = true ]]; then
echo 'export MANPATH=$HOME/tools/ripgrep/doc/man:$MANPATH' >> "$HOME/.bash_profile"
@@ -216,6 +245,7 @@ fi
echo "Setting up config and installing plugins"
if [[ -d "$NVIM_CONFIG_DIR" ]]; then
rm -rf "$NVIM_CONFIG_DIR.backup"
mv "$NVIM_CONFIG_DIR" "$NVIM_CONFIG_DIR.backup"
fi

View File

@@ -1,6 +1,8 @@
# Install scoop
# Set policy to avoid errors
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex
# Install scoop
Invoke-WebRequest -UseBasicParsing get.scoop.sh | Invoke-Expression
# Install node
scoop install nodejs
@@ -18,7 +20,7 @@ npm install -g vim-language-server
# Install bash-language-server
npm install -g bash-language-server
# Install miniconda3
# Install miniconda3 (for Python)
scoop install miniconda3
# Install pynvim
@@ -27,6 +29,27 @@ pip install -U pynvim
# Install python-language-server
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
scoop bucket add versions
scoop install neovim

37
init.lua Normal file
View File

@@ -0,0 +1,37 @@
-- 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 latest stable version of nvim
local expected_ver = "0.7.2"
local utils = require "utils"
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)
vim.api.nvim_echo({ { msg, "ErrorMsg" } }, false, {})
return
end
local core_conf_files = {
"globals.vim", -- some global settings
"options.vim", -- setting options in nvim
"autocommands.vim", -- various autocommands
"mappings.vim", -- 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,32 +0,0 @@
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
-- Set header
dashboard.section.header.val = {
" ",
" ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ",
" ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ",
" ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ",
" ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ",
" ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ",
" ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ",
" ",
}
-- Set menu
dashboard.section.buttons.val = {
dashboard.button( "Leader f f", " > Find file", ":Leaderf file --popup<CR>"),
dashboard.button( "Leader f r", " > Recent files" , ":Leaderf mru --popup<CR>"),
dashboard.button( "Leader f g", " > Project grep" , ":Leaderf rg --popup<CR>"),
dashboard.button( "u", " > Update plugins" , ":PackerSync<CR>"),
dashboard.button( "e", " > New file" , ":enew <CR>"),
dashboard.button( "q", " > Quit NVIM", ":qa<CR>"),
}
local fortune = require("alpha.fortune")
dashboard.section.footer.val = fortune()
alpha.setup(dashboard.opts)
-- Send config to alpha
alpha.setup(dashboard.opts)

View File

@@ -1,15 +0,0 @@
require("autosave").setup({
enabled = true,
execution_message = "Autosaved at " .. vim.fn.strftime("%H:%M:%S"),
events = { "InsertLeave", "TextChanged" },
conditions = {
exists = true,
filename_is_not = {"plugins.lua"},
filetype_is_not = {},
modifiable = true,
},
write_all_buffers = false,
on_off_commands = true,
clean_command_line_interval = 1000,
debounce_delay = 135,
})

View File

@@ -5,7 +5,10 @@ require("bufferline").setup({
right_mouse_command = nil,
left_mouse_command = "buffer %d",
middle_mouse_command = nil,
indicator_icon = "",
indicator = {
icon = '', -- this should be omitted if indicator style is not 'icon'
style = 'icon',
},
buffer_close_icon = "",
modified_icon = "",
close_icon = "",

View File

@@ -0,0 +1,65 @@
local dashboard = require("dashboard")
dashboard.custom_header = {
" ",
" ",
" ",
" ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗",
" ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║",
" ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║",
" ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║",
" ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║",
" ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝",
" ",
" ",
" ",
" ",
}
dashboard.custom_center = {
{
icon = "",
desc = "Find File ",
action = "Leaderf file --popup",
shortcut = "<Leader> f f",
},
{
icon = "",
desc = "Recently opened files ",
action = "Leaderf mru --popup",
shortcut = "<Leader> f r",
},
{
icon = "",
desc = "Project grep ",
action = "Leaderf rg --popup",
shortcut = "<Leader> f g",
},
{
icon = "",
desc = "Open Nvim config ",
action = "tabnew $MYVIMRC | tcd %:p:h",
shortcut = "<Leader> e v",
},
{
icon = "",
desc = "New file ",
action = "enew",
shortcut = "e ",
},
{
icon = "",
desc = "Quit Nvim ",
-- desc = "Quit Nvim ",
action = "qa",
shortcut = "q "
}
}
vim.cmd([[
augroup dashboard_enter
au!
autocmd FileType dashboard nnoremap <buffer> q :qa<CR>
autocmd FileType dashboard nnoremap <buffer> e :enew<CR>
augroup END
]])

View File

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

View File

@@ -1,3 +1,6 @@
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+250A is also a good choice
@@ -5,19 +8,22 @@ require("indent_blankline").setup({
show_end_of_line = false,
disable_with_nolist = true,
buftype_exclude = { "terminal" },
filetype_exclude = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha" },
filetype_exclude = exclude_ft,
})
vim.cmd([[
function! Should_activate_indentblankline() abort
if index(g:indent_blankline_filetype_exclude, &filetype) == -1
IndentBlanklineEnable
endif
endfunction
local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
api.nvim_create_autocmd("InsertEnter", {
pattern = "*",
group = gid,
command = "IndentBlanklineDisable"
})
augroup indent_blankline
autocmd!
autocmd InsertEnter * IndentBlanklineDisable
autocmd InsertLeave * call Should_activate_indentblankline()
augroup END
]])
api.nvim_create_autocmd("InsertLeave", {
pattern = "*",
group = gid,
callback = function()
if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
vim.cmd [[IndentBlanklineEnable]]
end
end
})

View File

@@ -13,7 +13,7 @@ local custom_attach = function(client, bufnr)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
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>wl", function() 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)
@@ -21,10 +21,10 @@ local custom_attach = function(client, bufnr)
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", {
api.nvim_create_autocmd("CursorHold", {
buffer=bufnr,
callback = function()
local opts = {
local float_opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = 'rounded',
@@ -36,11 +36,11 @@ local custom_attach = function(client, bufnr)
vim.b.diagnostics_pos = { nil, nil }
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
#vim.diagnostic.get() > 0
then
vim.diagnostic.open_float(nil, opts)
vim.diagnostic.open_float(nil, float_opts)
end
vim.b.diagnostics_pos = cursor_pos
@@ -71,7 +71,7 @@ local custom_attach = function(client, bufnr)
if vim.g.logging_level == 'debug' then
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
@@ -102,7 +102,7 @@ if utils.executable('pylsp') then
capabilities = capabilities,
})
else
vim.notify("pylsp not found!", 'warn', {title = 'Nvim-config'})
vim.notify("pylsp not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
end
-- if utils.executable('pyright') then
@@ -111,7 +111,7 @@ end
-- capabilities = capabilities
-- }
-- else
-- vim.notify("pyright not found!", 'warn', {title = 'Nvim-config'})
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
-- end
if utils.executable('clangd') then
@@ -124,7 +124,7 @@ if utils.executable('clangd') then
},
})
else
vim.notify("clangd not found!", 'warn', {title = 'Nvim-config'})
vim.notify("clangd not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
end
-- set up vim-language-server
@@ -137,7 +137,7 @@ if utils.executable('vim-language-server') then
capabilities = capabilities,
})
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
-- set up bash-language-server
@@ -148,36 +148,30 @@ if utils.executable('bash-language-server') then
})
end
local sumneko_binary_path = fn.exepath("lua-language-server")
if vim.g.is_mac or vim.g.is_linux and sumneko_binary_path ~= "" then
local sumneko_root_path = fn.fnamemodify(sumneko_binary_path, ":h:h:h")
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
if utils.executable("lua-language-server") then
-- settings for lua-language-server can be found on https://github.com/sumneko/lua-language-server/wiki/Settings .
lspconfig.sumneko_lua.setup({
on_attach = custom_attach,
cmd = { sumneko_binary_path, "-E", sumneko_root_path .. "/main.lua" },
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
-- Setup your lua path
path = runtime_path,
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
-- Make the server aware of Neovim runtime files,
-- 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 .
library = {
fn.stdpath('data') .. "/site/pack/packer/opt/emmylua-nvim",
fn.stdpath('config'),
},
maxPreload = 2000,
preloadFileSize = 50000,
},
},
},

View File

@@ -33,9 +33,8 @@ cmp.setup({
sources = {
{ name = 'nvim_lsp' }, -- For nvim-lsp
{ name = 'ultisnips' }, -- For ultisnips user.
{ name = 'nvim_lua' }, -- for nvim lua function
{ 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 = 'emoji', insert = true, } -- emoji completion
},
@@ -56,7 +55,7 @@ cmp.setup({
path = "[Path]",
buffer = "[Buffer]",
emoji = "[Emoji]",
omni = "[Omni]",
omni = "[Omni]",
}),
}),
},

View File

@@ -21,20 +21,36 @@ local function ime_state()
end
local function trailing_space()
-- Get the positions of trailing whitespaces from plugin 'jdhao/whitespace.nvim'.
local trailing_space_pos = vim.b.trailing_whitespace_pos
if not vim.o.modifiable then
return ""
end
local line_num = nil
for i=1, fn.line('$') do
local linetext = fn.getline(i)
-- To prevent invalid escape error, we wrap the regex string with `[[]]`.
local idx = fn.match(linetext, [[\v\s+$]])
if idx ~= -1 then
line_num = i
break
end
end
local msg = ""
if #trailing_space_pos > 0 then
-- Note that lua index is 1-based, not zero based!!!
local line = trailing_space_pos[1][1]
msg = string.format("[%d]trailing", line)
if line_num ~= nil then
msg = string.format("[%d]trailing", line_num)
end
return msg
end
local function mixed_indent()
if not vim.o.modifiable then
return ""
end
local space_pat = [[\v^ +]]
local tab_pat = [[\v^\t+]]
local space_indent = fn.search(space_pat, 'nwc')

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

@@ -0,0 +1,89 @@
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_augroup("non_utf8_file", {
clear = true
})
api.nvim_create_autocmd({ "BufRead" }, {
pattern = "*",
group = "non_utf8_file",
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_augroup("highlight_yank", {
clear = true
})
api.nvim_create_autocmd({ "TextYankPost" }, {
pattern = "*",
group = "highlight_yank",
callback = function()
vim.highlight.on_yank { higroup = "YankColor", timeout = 300, on_visual = false }
end
})
-- Auto-generate packer_compiled.lua file
api.nvim_create_augroup("packer_auto_compile", {
clear = true
})
api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = "*/nvim/lua/plugins.lua",
group = "packer_auto_compile",
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_augroup("auto_create_dir", {
clear = true
})
api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = "*",
group = "auto_create_dir",
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
})

View File

@@ -1,8 +1,11 @@
local keymap = vim.keymap
-- Go to the begining and end of current line in insert mode quickly
-- 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,5 +0,0 @@
-- Some utility stuff
require 'utils'
-- plugin installation
require 'plugins'

View File

@@ -1,25 +1,36 @@
local utils = require("utils")
local fn = vim.fn
vim.g.package_home = fn.stdpath("data") .. "/site/pack/packer/"
local packer_install_dir = vim.g.package_home .. "/opt/packer.nvim"
-- The root dir to install all plugins. Plugins are under opt/ or start/ sub-directory.
vim.g.plugin_home = fn.stdpath("data") .. "/site/pack/packer"
local packer_repo = "https://github.com/wbthomason/packer.nvim"
local install_cmd = string.format("10split |term git clone --depth=1 %s %s", packer_repo, packer_install_dir)
-- Where to install packer.nvim -- the package manager (we make it opt)
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.
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.cmd(install_cmd)
end
-- Load packer.nvim
vim.cmd("packadd packer.nvim")
local util = require('packer.util')
require("packer").startup({
local packer = require("packer")
local packer_util = require('packer.util')
packer.startup({
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({"wbthomason/packer.nvim", opt = true})
@@ -30,7 +41,7 @@ require("packer").startup({
-- nvim-cmp completion sources
use {"hrsh7th/cmp-nvim-lsp", after = "nvim-cmp"}
use {"hrsh7th/cmp-nvim-lua", after = "nvim-cmp"}
-- use {"hrsh7th/cmp-nvim-lua", after = "nvim-cmp"}
use {"hrsh7th/cmp-path", after = "nvim-cmp"}
use {"hrsh7th/cmp-buffer", after = "nvim-cmp"}
use { "hrsh7th/cmp-omni", after = "nvim-cmp" }
@@ -119,6 +130,7 @@ require("packer").startup({
use({"sainnhe/everforest", opt = true})
use({"EdenEast/nightfox.nvim", opt = true})
use({"rebelot/kanagawa.nvim", opt = true})
use({"catppuccin/nvim", as = "catppuccin", opt = true})
-- Show git change (change, delete, add) signs in vim sign column
use({"mhinz/vim-signify", event = 'BufEnter'})
@@ -136,7 +148,7 @@ require("packer").startup({
use({ "akinsho/bufferline.nvim", event = "VimEnter", config = [[require('config.bufferline')]] })
-- fancy start screen
-- use { 'goolord/alpha-nvim', event = 'VimEnter', config = [[require('config.alpha-nvim')]] }
use { 'glepnir/dashboard-nvim', event = "VimEnter", config = [[require('config.dashboard-nvim')]] }
use({
"lukas-reineke/indent-blankline.nvim",
@@ -183,13 +195,7 @@ require("packer").startup({
-- use 'mg979/vim-visual-multi'
-- Autosave files on certain events
use({
"Pocco81/AutoSave.nvim",
event = "VimEnter",
config = function()
vim.defer_fn(function() require('config.autosave') end, 1500)
end
})
use({"907th/vim-auto-save", event = "InsertEnter"})
-- Show undo history visually
use({"simnalamburt/vim-mundo", cmd = {"MundoToggle", "MundoShow"}})
@@ -356,14 +362,26 @@ require("packer").startup({
requires = { 'kyazdani42/nvim-web-devicons' },
config = [[require('config.nvim-tree')]]
}
use { 'ii14/emmylua-nvim', ft = 'lua' }
use { 'j-hui/fidget.nvim', after = 'nvim-lspconfig', config = [[require('config.fidget-nvim')]]}
end,
config = {
max_jobs = 16,
compile_path = 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')
if not status then
vim.notify("Error requiring packer_compiled.lua: run PackerSync to fix!")
-- For fresh install, we need to install plugins. Otherwise, we just need to require `packer_compiled.lua`.
if fresh_install then
-- 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

View File

@@ -1,7 +1,7 @@
local fn = vim.fn
-- inspect something
function inspect(item)
function _G.inspect(item)
vim.pretty_print(item)
end
@@ -15,14 +15,46 @@ function M.executable(name)
return false
end
function M.may_create_dir()
local fpath = fn.expand('<afile>')
local parent_dir = fn.fnamemodify(fpath, ":p:h")
local res = fn.isdirectory(parent_dir)
--- Create a dir if it does not exist
function M.may_create_dir(dir)
local res = fn.isdirectory(dir)
if res == 0 then
fn.mkdir(parent_dir, 'p')
fn.mkdir(dir, 'p')
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

View File

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

View File

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

View File

@@ -8,3 +8,40 @@ call utils#Cabbrev('man', 'Man')
" show current date and time in human readable format
command! -nargs=? Datetime echo utils#iso_time(<q-args>)
" Convert Markdown file to PDF
command! ToPDF call s:md_to_pdf()
function! s:md_to_pdf() abort
" check if pandoc is installed
if executable('pandoc') != 1
echoerr "pandoc not found"
return
endif
let l:md_path = expand("%:p")
let l:pdf_path = fnamemodify(l:md_path, ":r") .. ".pdf"
let l:header_path = stdpath('config') . '/resources/head.tex'
let l:cmd = "pandoc --pdf-engine=xelatex --highlight-style=zenburn --table-of-content " .
\ "--include-in-header=" . l:header_path . " -V fontsize=10pt -V colorlinks -V toccolor=NavyBlue " .
\ "-V linkcolor=red -V urlcolor=teal -V filecolor=magenta -s " .
\ l:md_path . " -o " . l:pdf_path
if g:is_mac
let l:cmd = l:cmd . '&& open ' . l:pdf_path
endif
if g:is_win
let l:cmd = l:cmd . '&& start ' . l:pdf_path
endif
" echomsg l:cmd
let l:id = jobstart(l:cmd)
if l:id == 0 || l:id == -1
echoerr "Error running command"
endif
endfunction

78
resources/head.tex Normal file
View File

@@ -0,0 +1,78 @@
\usepackage{fancyvrb,newverbs}
\usepackage[top=2cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
\usepackage{hyperref}
% begin a new page for each section (first level header),
% we need to combine this with `-V subparagraph` when invoking pandc
% \usepackage{titlesec}
% \newcommand{\sectionbreak}{\clearpage}
% change background color for inline code in markdown files.
% The following code does not work well for long text, because the text will exceed the page boundary.
\definecolor{bgcolor}{HTML}{DADADA}
\let\oldtexttt\texttt
\renewcommand{\texttt}[1]{
\colorbox{bgcolor}{\oldtexttt{#1}}
}
% change style of quote, see also https://tex.stackexchange.com/a/436253/114857
\usepackage[most]{tcolorbox}
\definecolor{linequote}{RGB}{224,215,188}
\definecolor{backquote}{RGB}{249,245,233}
\definecolor{bordercolor}{RGB}{221,221,221}
% change left border: https://tex.stackexchange.com/a/475716/114857
% change left margin: https://tex.stackexchange.com/a/457936/114857
\newtcolorbox{myquote}[1][]{%
enhanced,
breakable,
size=minimal,
left=10pt,
top=5pt,
bottom=5pt,
frame hidden,
boxrule=0pt,
sharp corners=all,
colback=backquote,
borderline west={2pt}{0pt}{bordercolor},
#1
}
% redefine quote environment to use the myquote environment, see https://tex.stackexchange.com/a/337587/114857
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
% start a new page after toc, we need to save the old command before defining
% new one to avoid recursive command calls,
% see https://tex.stackexchange.com/questions/47351/can-i-redefine-a-command-to-contain-itself
\let\oldtoc\tableofcontents
\renewcommand{\tableofcontents}{\oldtoc\newpage}
% fix header level issue
\usepackage{enumitem}
\setlistdepth{9}
\setlist[itemize,1]{label=$\bullet$}
\setlist[itemize,2]{label=$\bullet$}
\setlist[itemize,3]{label=$\bullet$}
\setlist[itemize,4]{label=$\bullet$}
\setlist[itemize,5]{label=$\bullet$}
\setlist[itemize,6]{label=$\bullet$}
\setlist[itemize,7]{label=$\bullet$}
\setlist[itemize,8]{label=$\bullet$}
\setlist[itemize,9]{label=$\bullet$}
\renewlist{itemize}{itemize}{9}
\setlist[enumerate,1]{label=$\arabic*.$}
\setlist[enumerate,2]{label=$\alph*.$}
\setlist[enumerate,3]{label=$\roman*.$}
\setlist[enumerate,4]{label=$\arabic*.$}
\setlist[enumerate,5]{label=$\alpha*$}
\setlist[enumerate,6]{label=$\roman*.$}
\setlist[enumerate,7]{label=$\arabic*.$}
\setlist[enumerate,8]{label=$\alph*.$}
\setlist[enumerate,9]{label=$\roman*.$}
\renewlist{enumerate}{enumerate}{9}

View File

@@ -430,3 +430,4 @@ metatable
open3d
pyntcloud
param
reddit