mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
118 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f95d4c09b4 | ||
|
|
7e706515a8 | ||
|
|
1d66475cae | ||
|
|
5328c477a8 | ||
|
|
917ab82ffb | ||
|
|
54eb3ca811 | ||
|
|
64b41fbd58 | ||
|
|
d941be482b | ||
|
|
ab75189231 | ||
|
|
7645751dc1 | ||
|
|
8880268140 | ||
|
|
d86f599483 | ||
|
|
8dfae271d0 | ||
|
|
1141a18c5f | ||
|
|
fe3d5e5922 | ||
|
|
9769c24633 | ||
|
|
97f72936ac | ||
|
|
94cade03be | ||
|
|
590bd6c7e6 | ||
|
|
4171f190f2 | ||
|
|
5426c88a90 | ||
|
|
d715ce8f31 | ||
|
|
3040fa7969 | ||
|
|
b9cf3cc6ed | ||
|
|
154cde3d71 | ||
|
|
81f64ed32e | ||
|
|
db380ca7a7 | ||
|
|
51f81093da | ||
|
|
a9fc298063 | ||
|
|
9071e045eb | ||
|
|
fa79647a63 | ||
|
|
4b4ff5f549 | ||
|
|
12b0ff02b6 | ||
|
|
e3930e8aa7 | ||
|
|
21522bd194 | ||
|
|
a3c8b3d5b5 | ||
|
|
d150f39afc | ||
|
|
3904cd4ccf | ||
|
|
95d3b2f2d8 | ||
|
|
c3d8dc3e1d | ||
|
|
f9780c2dff | ||
|
|
256c37a946 | ||
|
|
eff98d036d | ||
|
|
6e60475f3f | ||
|
|
d90273df8e | ||
|
|
659f410b9e | ||
|
|
a602d98819 | ||
|
|
9ff76931e3 | ||
|
|
85232b82a8 | ||
|
|
cfc0089bb5 | ||
|
|
f1062a3d8f | ||
|
|
fd6df981cd | ||
|
|
8af8ebd72a | ||
|
|
4c697d89f3 | ||
|
|
e6f95cedb1 | ||
|
|
262ad6aa38 | ||
|
|
b30cc9ed78 | ||
|
|
b3a26e4226 | ||
|
|
794b098090 | ||
|
|
b728b39784 | ||
|
|
acc3ed7829 | ||
|
|
44e9e5a1ce | ||
|
|
5502d29f40 | ||
|
|
fe95658319 | ||
|
|
e165276763 | ||
|
|
933b887281 | ||
|
|
69643e143a | ||
|
|
7f4772fd31 | ||
|
|
bf49e90947 | ||
|
|
784b435f0e | ||
|
|
beec97c086 | ||
|
|
bbb8545403 | ||
|
|
9efadac8fb | ||
|
|
6e137fe9a3 | ||
|
|
719fbfc1ab | ||
|
|
e815de294f | ||
|
|
ca7430056c | ||
|
|
cb8c9208e1 | ||
|
|
ce1e13e2c9 | ||
|
|
2af616bb0d | ||
|
|
3694d3c237 | ||
|
|
69d8543495 | ||
|
|
be3d134c37 | ||
|
|
601396f700 | ||
|
|
e462ebcbcc | ||
|
|
2f8482639d | ||
|
|
050eacaee2 | ||
|
|
01bc4b40d3 | ||
|
|
c06d46e84d | ||
|
|
7cf70f31af | ||
|
|
8416508686 | ||
|
|
df9491b05b | ||
|
|
17d2e3ab3e | ||
|
|
2c9948300d | ||
|
|
dfaa3d97a5 | ||
|
|
8d74fcb75c | ||
|
|
b1f0ef63ef | ||
|
|
54ca6d4191 | ||
|
|
97af59e670 | ||
|
|
4d8ef868ad | ||
|
|
3137850db6 | ||
|
|
eccdc62f38 | ||
|
|
ad483a7dc0 | ||
|
|
6df27d1c22 | ||
|
|
7f6627cfa1 | ||
|
|
7ff11a9760 | ||
|
|
cc4688d089 | ||
|
|
8a1b3193a4 | ||
|
|
e92362041c | ||
|
|
63ff776758 | ||
|
|
41c8c81f21 | ||
|
|
997c6286df | ||
|
|
359621b126 | ||
|
|
4dc2d9575b | ||
|
|
fc1c447319 | ||
|
|
1391ca7ff1 | ||
|
|
6a6f8ff597 | ||
|
|
946e65662b |
30
README.md
30
README.md
@@ -13,7 +13,7 @@
|
|||||||
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
|
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/neovim/neovim/releases/tag/stable">
|
<a href="https://github.com/neovim/neovim/releases/tag/stable">
|
||||||
<img src="https://img.shields.io/badge/Neovim-0.9.1-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
|
<img src="https://img.shields.io/badge/Neovim-0.10.2-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/jdhao/nvim-config/search?l=vim-script">
|
<a href="https://github.com/jdhao/nvim-config/search?l=vim-script">
|
||||||
<img src="https://img.shields.io/github/languages/top/jdhao/nvim-config" alt="Top languages"/>
|
<img src="https://img.shields.io/github/languages/top/jdhao/nvim-config" alt="Top languages"/>
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
<a href="https://github.com/jdhao/nvim-config/graphs/commit-activity">
|
<a href="https://github.com/jdhao/nvim-config/graphs/commit-activity">
|
||||||
<img src="https://img.shields.io/github/commit-activity/m/jdhao/nvim-config?style=flat-square" />
|
<img src="https://img.shields.io/github/commit-activity/m/jdhao/nvim-config?style=flat-square" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.9.1">
|
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.10.1">
|
||||||
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.9.1?style=flat-square" />
|
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.1?style=flat-square" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/jdhao/nvim-config/graphs/contributors">
|
<a href="https://github.com/jdhao/nvim-config/graphs/contributors">
|
||||||
<img src="https://img.shields.io/github/contributors/jdhao/nvim-config?style=flat-square" />
|
<img src="https://img.shields.io/github/contributors/jdhao/nvim-config?style=flat-square" />
|
||||||
@@ -57,14 +57,14 @@ and how to set up on different platforms (Linux, macOS, and Windows).
|
|||||||
|
|
||||||
# Features #
|
# Features #
|
||||||
|
|
||||||
+ Plugin management via [Packer.nvim](https://github.com/wbthomason/packer.nvim).
|
+ Plugin management via [Lazy.nvim](https://github.com/folke/lazy.nvim).
|
||||||
+ Code, snippet, word auto-completion via [nvim-cmp](https://github.com/hrsh7th/nvim-cmp).
|
+ Code, snippet, word auto-completion via [nvim-cmp](https://github.com/hrsh7th/nvim-cmp).
|
||||||
+ Language server protocol (LSP) support via [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
|
+ Language server protocol (LSP) support via [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
|
||||||
+ Git integration via [vim-fugitive](https://github.com/tpope/vim-fugitive).
|
+ Git integration via [vim-fugitive](https://github.com/tpope/vim-fugitive).
|
||||||
+ Better escaping from insert mode via [better-escape.vim](https://github.com/nvim-zh/better-escape.vim).
|
+ Better escaping from insert mode via [better-escape.vim](https://github.com/nvim-zh/better-escape.vim).
|
||||||
+ Ultra-fast project-wide fuzzy searching via [LeaderF](https://github.com/Yggdroot/LeaderF).
|
+ Ultra-fast project-wide fuzzy searching via [LeaderF](https://github.com/Yggdroot/LeaderF).
|
||||||
+ Faster code commenting via [vim-commentary](https://github.com/tpope/vim-commentary).
|
+ Faster code commenting via [vim-commentary](https://github.com/tpope/vim-commentary).
|
||||||
+ Faster matching pair insertion and jump via [delimitMate](https://github.com/Raimondi/delimitMate).
|
+ Faster matching pair insertion and jump via [nvim-autopairs](https://github.com/windwp/nvim-autopairs).
|
||||||
+ Smarter and faster matching pair management (add, replace or delete) via [vim-sandwich](https://github.com/machakann/vim-sandwich).
|
+ Smarter and faster matching pair management (add, replace or delete) via [vim-sandwich](https://github.com/machakann/vim-sandwich).
|
||||||
+ Fast buffer jump via [hop.nvim](https://github.com/phaazon/hop.nvim).
|
+ Fast buffer jump via [hop.nvim](https://github.com/phaazon/hop.nvim).
|
||||||
+ Powerful snippet insertion via [Ultisnips](https://github.com/SirVer/ultisnips).
|
+ Powerful snippet insertion via [Ultisnips](https://github.com/SirVer/ultisnips).
|
||||||
@@ -84,6 +84,7 @@ and how to set up on different platforms (Linux, macOS, and Windows).
|
|||||||
+ Tags navigation via [vista](https://github.com/liuchengxu/vista.vim).
|
+ Tags navigation via [vista](https://github.com/liuchengxu/vista.vim).
|
||||||
+ Code formatting via [Neoformat](https://github.com/sbdchd/neoformat).
|
+ Code formatting via [Neoformat](https://github.com/sbdchd/neoformat).
|
||||||
+ Undo management via [vim-mundo](https://github.com/simnalamburt/vim-mundo)
|
+ Undo management via [vim-mundo](https://github.com/simnalamburt/vim-mundo)
|
||||||
|
+ Code folding with [nvim-ufo](https://github.com/kevinhwang91/nvim-ufo) and [statuscol.nvim](https://github.com/luukvbaal/statuscol.nvim)
|
||||||
+ ......
|
+ ......
|
||||||
|
|
||||||
# UI Demo
|
# UI Demo
|
||||||
@@ -140,6 +141,12 @@ Go to a string starting with `se`
|
|||||||
<img src="https://user-images.githubusercontent.com/16662357/128589873-aadb8264-1098-4834-9876-fa66a309be05.gif" width="800">
|
<img src="https://user-images.githubusercontent.com/16662357/128589873-aadb8264-1098-4834-9876-fa66a309be05.gif" width="800">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
## code folding with nvim-ufo and statuscol.nvim
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="https://github.com/user-attachments/assets/a01a56b2-7c91-43de-b305-f2fbaa81dcec" width="800">
|
||||||
|
</p>
|
||||||
|
|
||||||
# Shortcuts
|
# Shortcuts
|
||||||
|
|
||||||
Some of the shortcuts I use frequently are listed here. In the following shortcuts, `<leader>` represents ASCII character `,`.
|
Some of the shortcuts I use frequently are listed here. In the following shortcuts, `<leader>` represents ASCII character `,`.
|
||||||
@@ -165,12 +172,14 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu
|
|||||||
| `<space>t` | Normal | Linux/macOS/Win | Toggle tag window (show project tags in the right window) |
|
| `<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>gs` | Normal | Linux/macOS/Win | Show Git status result |
|
||||||
| `<leader>gw` | Normal | Linux/macOS/Win | Run Git add for current file |
|
| `<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>gc` | Normal | Linux/macOS/Win | Run git commit |
|
||||||
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
|
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
|
||||||
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
|
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
|
||||||
| `<leader>gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines
|
| `<leader>gbd` | Normal | Linux/macOS/Win | Delete a branch |
|
||||||
| `<leader>gb` | Normal | macOS | Browse current git repo in browser
|
| `<leader>gbn` | Normal | Linux/macOS/Win | Create a new branch |
|
||||||
|
| `<leader>gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines |
|
||||||
|
| `<leader>gbr` | Normal | macOS | Browse current git repo in browser |
|
||||||
|
| `<leader>gb` | Visual | macOS | Blame current line |
|
||||||
| `<F9>` | Normal | Linux/macOS/Win | Compile&run current source file (for C++, LaTeX, Lua, Python) |
|
| `<F9>` | Normal | Linux/macOS/Win | Compile&run current source file (for C++, LaTeX, Lua, Python) |
|
||||||
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
|
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
|
||||||
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
|
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
|
||||||
@@ -182,7 +191,6 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu
|
|||||||
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
|
| `Alt-j` | Normal | Linux/macOS/Win | Move current line or selected lines down |
|
||||||
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
|
| `Alt-m` | Normal | macOS/Win | Markdown previewing in system browser |
|
||||||
| `Alt-Shift-m` | Normal | macOS/Win | Stopping 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-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 |
|
| `ctrl-t` | Insert | Linux/macOS/Win | Turn word under cursor to title case |
|
||||||
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
|
| `jk` | Insert | Linux/macOS/Win | Return to Normal mode without lagging |
|
||||||
@@ -192,10 +200,12 @@ Some of the shortcuts I use frequently are listed here. In the following shortcu
|
|||||||
In addition to commands provided by various plugins, I have also created some custom commands for personal use.
|
In addition to commands provided by various plugins, I have also created some custom commands for personal use.
|
||||||
|
|
||||||
| command | description | example |
|
| command | description | example |
|
||||||
|------------|-------------------------------------------------------------------------|--------------------------------|
|
|--------------|-------------------------------------------------------------------------|--------------------------------|
|
||||||
| `Redir` | capture command output to a tabpage for easier inspection. | `Redir hi` |
|
| `Redir` | capture command output to a tabpage for easier inspection. | `Redir hi` |
|
||||||
| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` |
|
| `Edit` | edit multiple files at the same time, supports globing | `Edit *.vim` |
|
||||||
| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` |
|
| `Datetime` | print current date and time or convert Unix time stamp to date and time | `Datetime 12345` or `Datetime` |
|
||||||
|
| `JSONFormat` | format a JSON file | `JSONFormat` |
|
||||||
|
| `CopyPath` | copy current file path to clipboard | `CopyPath relative` |
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,3 @@ function s:create_term_buf(_type, size) abort
|
|||||||
endif
|
endif
|
||||||
execute 'resize ' . a:size
|
execute 'resize ' . a:size
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" For delimitMate
|
|
||||||
let b:delimitMate_matchpairs = "(:),[:],{:}"
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
" let the initial folding state be that all folds are closed.
|
|
||||||
set foldlevel=0
|
|
||||||
|
|
||||||
" Use nvim-treesitter for folding
|
|
||||||
set foldmethod=expr
|
|
||||||
set foldexpr=nvim_treesitter#foldexpr()
|
|
||||||
@@ -4,5 +4,4 @@ set formatoptions-=r
|
|||||||
|
|
||||||
nnoremap <buffer><silent> <F9> :luafile %<CR>
|
nnoremap <buffer><silent> <F9> :luafile %<CR>
|
||||||
|
|
||||||
" For delimitMate
|
nnoremap <buffer><silent> <space>f <cmd>silent !stylua %<CR>
|
||||||
let b:delimitMate_matchpairs = "(:),[:],{:}"
|
|
||||||
|
|||||||
@@ -12,6 +12,3 @@ set tabstop=4 " number of visual spaces per TAB
|
|||||||
set softtabstop=4 " number of spaces in tab when editing
|
set softtabstop=4 " number of spaces in tab when editing
|
||||||
set shiftwidth=4 " number of spaces to use for autoindent
|
set shiftwidth=4 " 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
|
||||||
|
|
||||||
" For delimitMate
|
|
||||||
let b:delimitMate_matchpairs = "(:),[:],{:}"
|
|
||||||
|
|||||||
@@ -128,11 +128,22 @@ endfunction
|
|||||||
|
|
||||||
" Output current time or unix timestamp in human-readable format.
|
" Output current time or unix timestamp in human-readable format.
|
||||||
function! utils#iso_time(timestamp) abort
|
function! utils#iso_time(timestamp) abort
|
||||||
if a:timestamp
|
" Get current datetime
|
||||||
return strftime('%Y-%m-%d %H:%M:%S%z', a:timestamp)
|
if !a:timestamp
|
||||||
|
return strftime('%Y-%m-%d %H:%M:%S%z')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return strftime('%Y-%m-%d %H:%M:%S%z')
|
" this timestamp in expressed in milliseconds
|
||||||
|
if len(a:timestamp) == 13
|
||||||
|
let l:timestamp = a:timestamp[:-4]
|
||||||
|
" this timestamp in expressed in microseconds
|
||||||
|
elseif len(a:timestamp) == 16
|
||||||
|
let l:timestamp = a:timestamp[:-7]
|
||||||
|
else
|
||||||
|
let l:timestamp = a:timestamp
|
||||||
|
endif
|
||||||
|
return strftime('%Y-%m-%d %H:%M:%S%z', l:timestamp)
|
||||||
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Check if we are inside a Git repo.
|
" Check if we are inside a Git repo.
|
||||||
@@ -141,9 +152,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 special user autocmd InGitRepo (to use it for
|
" Manually trigger a special user autocmd InGitRepo (used lazyloading.
|
||||||
" lazyloading of fugitive by packer.nvim).
|
|
||||||
" See also https://github.com/wbthomason/packer.nvim/discussions/534.
|
|
||||||
doautocmd User InGitRepo
|
doautocmd User InGitRepo
|
||||||
return v:true
|
return v:true
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
" Do not use smart case in command line mode, extracted from https://vi.stackexchange.com/a/16511/15292.
|
|
||||||
augroup dynamic_smartcase
|
|
||||||
autocmd!
|
|
||||||
autocmd CmdLineEnter : set nosmartcase
|
|
||||||
autocmd CmdLineLeave : set smartcase
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
augroup term_settings
|
|
||||||
autocmd!
|
|
||||||
" Do not use number and relative number for terminal inside nvim
|
|
||||||
autocmd TermOpen * setlocal norelativenumber nonumber
|
|
||||||
" Go to insert mode by default to start typing command
|
|
||||||
autocmd TermOpen * startinsert
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" More accurate syntax highlighting? (see `:h syn-sync`)
|
|
||||||
augroup accurate_syn_highlight
|
|
||||||
autocmd!
|
|
||||||
autocmd BufEnter * :syntax sync fromstart
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" Return to last cursor position when opening a file
|
|
||||||
augroup resume_cursor_position
|
|
||||||
autocmd!
|
|
||||||
autocmd BufReadPost * call s:resume_cursor_position()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" Only resume last cursor position when there is no go-to-line command (something like '+23').
|
|
||||||
function s:resume_cursor_position() abort
|
|
||||||
if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
|
|
||||||
let l:args = v:argv " command line arguments
|
|
||||||
for l:cur_arg in l:args
|
|
||||||
" Check if a go-to-line command is given.
|
|
||||||
let idx = match(l:cur_arg, '\v^\+(\d){1,}$')
|
|
||||||
if idx != -1
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
execute "normal! g`\"zvzz"
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
augroup numbertoggle
|
|
||||||
autocmd!
|
|
||||||
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
|
|
||||||
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" Define or override some highlight groups
|
|
||||||
augroup custom_highlight
|
|
||||||
autocmd!
|
|
||||||
autocmd ColorScheme * call s:custom_highlight()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
function! s:custom_highlight() abort
|
|
||||||
" For yank highlight
|
|
||||||
highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71
|
|
||||||
|
|
||||||
" For cursor colors
|
|
||||||
highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black
|
|
||||||
highlight Cursor2 guifg=red guibg=red
|
|
||||||
|
|
||||||
" For floating windows border highlight
|
|
||||||
highlight FloatBorder guifg=LightGreen guibg=NONE
|
|
||||||
|
|
||||||
" highlight for matching parentheses
|
|
||||||
highlight MatchParen cterm=bold,underline gui=bold,underline
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
augroup auto_close_win
|
|
||||||
autocmd!
|
|
||||||
autocmd BufEnter * call s:quit_current_win()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" Quit Nvim if we have only one window, and its filetype match our pattern.
|
|
||||||
function! s:quit_current_win() abort
|
|
||||||
let l:quit_filetypes = ['qf', 'vista', 'NvimTree']
|
|
||||||
|
|
||||||
let l:should_quit = v:true
|
|
||||||
|
|
||||||
let l:tabwins = nvim_tabpage_list_wins(0)
|
|
||||||
for w in l:tabwins
|
|
||||||
let l:buf = nvim_win_get_buf(w)
|
|
||||||
let l:bf = getbufvar(l:buf, '&filetype')
|
|
||||||
|
|
||||||
if index(l:quit_filetypes, l:bf) == -1
|
|
||||||
let l:should_quit = v:false
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
if l:should_quit
|
|
||||||
qall
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
augroup git_repo_check
|
|
||||||
autocmd!
|
|
||||||
autocmd VimEnter,DirChanged * call utils#Inside_git_repo()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" 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 BufReadPre * call s:handle_large_file()
|
|
||||||
augroup END
|
|
||||||
|
|
||||||
" Load auto-command defined in Lua
|
|
||||||
lua require("custom-autocmd")
|
|
||||||
@@ -111,23 +111,23 @@ 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 [lazy.nvim](https://github.com/folke/lazy.nvim) and other git-related plugins.
|
||||||
|
|
||||||
For Linux and macOS, Git is usually pre-installed.
|
For Linux and macOS, Git is usually pre-installed.
|
||||||
The version of Git on the Linux system may be too old so that plugins may break.
|
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
|
### universal-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.
|
||||||
|
|
||||||
To install it on Linux, we need to build it from source. See [here](https://askubuntu.com/a/836521/768311) for the details.
|
To install it on Linux, we need to build it from source. See [here](https://askubuntu.com/a/836521/768311) for the details.
|
||||||
To install ctags on macOS, use [Homebrew](https://github.com/universal-ctags/homebrew-universal-ctags):
|
To install ctags on macOS, use [Homebrew](https://formulae.brew.sh/formula/universal-ctags):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew install ctags
|
brew install universal-ctags
|
||||||
```
|
```
|
||||||
|
|
||||||
To install it Windows, use [chocolatey](https://chocolatey.org/) or [scoop](https://scoop.sh/)
|
To install it Windows, use [chocolatey](https://chocolatey.org/) or [scoop](https://scoop.sh/)
|
||||||
@@ -166,57 +166,15 @@ Set their PATH properly and make sure you can run `pylint`, `flake8` and `vint`
|
|||||||
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
|
Please check the official doc on how to install Neovim on different systems: https://github.com/neovim/neovim/blob/master/INSTALL.md
|
||||||
|
|
||||||
You can directly download the binary release from [here](https://github.com/neovim/neovim/releases/download/stable/nvim-linux64.tar.gz).
|
After installing Nvim, we need to set the PATH to nvim correctly.
|
||||||
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
|
|
||||||
|
|
||||||
You may download from [nvim release](https://github.com/neovim/neovim/releases/download/stable/nvim-win64.zip) from GitHub and manually extract it.
|
|
||||||
|
|
||||||
Another way to install Nvim on Windows is via chocolatey or scoop:
|
|
||||||
|
|
||||||
```
|
|
||||||
choco install neovim
|
|
||||||
|
|
||||||
# via scoop
|
|
||||||
# scoop bucket add versions
|
|
||||||
# scoop install neovim
|
|
||||||
```
|
|
||||||
|
|
||||||
### macOS
|
|
||||||
|
|
||||||
It is recommended to install neovim via [Homebrew](https://brew.sh/) on macOS. Simply run the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
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**.
|
**Make sure that you can run `nvim` from the command line after all these setups**.
|
||||||
|
|
||||||
## Setting up Nvim
|
## Setting up Nvim
|
||||||
|
|
||||||
After installing nvim and all the dependencies, we will install plugin managers and set up this config.
|
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.
|
|
||||||
|
|
||||||
For Windows, if curl is installed, run the following command (on PowerShell):
|
|
||||||
|
|
||||||
```
|
|
||||||
git clone --depth=1 https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\opt\packer.nvim"
|
|
||||||
```
|
|
||||||
|
|
||||||
For macOS and Linux, run the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
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`.
|
||||||
@@ -228,7 +186,7 @@ then go to this directory, and run the following command:
|
|||||||
git clone --depth=1 https://github.com/jdhao/nvim-config.git .
|
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, all the plugins will be installed automatically.
|
||||||
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.
|
||||||
|
|
||||||
[^1]: Use `echo %userprofile%` to see where your `$HOME` is.
|
[^1]: Use `echo %userprofile%` to see where your `$HOME` is.
|
||||||
|
|||||||
@@ -252,13 +252,7 @@ fi
|
|||||||
|
|
||||||
git clone --depth=1 https://github.com/jdhao/nvim-config.git "$NVIM_CONFIG_DIR"
|
git clone --depth=1 https://github.com/jdhao/nvim-config.git "$NVIM_CONFIG_DIR"
|
||||||
|
|
||||||
echo "Installing packer.nvim"
|
|
||||||
if [[ ! -d ~/.local/share/nvim/site/pack/packer/opt/packer.nvim ]]; then
|
|
||||||
git clone --depth=1 https://github.com/wbthomason/packer.nvim \
|
|
||||||
~/.local/share/nvim/site/pack/packer/opt/packer.nvim
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Installing nvim plugins, please wait"
|
echo "Installing nvim plugins, please wait"
|
||||||
"$NVIM_DIR/bin/nvim" -c "autocmd User PackerComplete quitall" -c "PackerSync"
|
"$NVIM_DIR/bin/nvim" -c "autocmd User LazyInstall quitall" -c "lua require('lazy').install()"
|
||||||
|
|
||||||
echo "Finished installing Nvim and its dependencies!"
|
echo "Finished installing Nvim and its dependencies!"
|
||||||
|
|||||||
50
init.lua
50
init.lua
@@ -11,39 +11,23 @@
|
|||||||
-- StackOverflow: https://stackoverflow.com/users/6064933/jdhao
|
-- StackOverflow: https://stackoverflow.com/users/6064933/jdhao
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
|
|
||||||
local api = vim.api
|
local utils = require("utils")
|
||||||
local version = vim.version
|
|
||||||
|
|
||||||
-- check if we have the latest stable version of nvim
|
local expected_version = "0.10.2"
|
||||||
local expected_ver = "0.9.1"
|
utils.is_compatible_version(expected_version)
|
||||||
local ev = version.parse(expected_ver)
|
|
||||||
local actual_ver = version()
|
|
||||||
|
|
||||||
if version.cmp(ev, actual_ver) ~= 0 then
|
local config_dir = vim.fn.stdpath("config")
|
||||||
local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch)
|
---@cast config_dir string
|
||||||
local msg = string.format("Unsupported nvim version: expect %s, but got %s instead!", expected_ver, _ver)
|
|
||||||
api.nvim_err_writeln(msg)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local core_conf_files = {
|
-- some global settings
|
||||||
"globals.lua", -- some global settings
|
require("globals")
|
||||||
"options.vim", -- setting options in nvim
|
-- setting options in nvim
|
||||||
"autocommands.vim", -- various autocommands
|
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/options.vim"))
|
||||||
"mappings.lua", -- all the user-defined mappings
|
-- various autocommands
|
||||||
"plugins.vim", -- all the plugins installed and their configurations
|
require("custom-autocmd")
|
||||||
"colorschemes.lua", -- colorscheme settings
|
-- all the user-defined mappings
|
||||||
}
|
require("mappings")
|
||||||
|
-- all the plugins installed and their configurations
|
||||||
-- source all the core config files
|
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
|
||||||
for _, file_name in ipairs(core_conf_files) do
|
-- colorscheme settings
|
||||||
if vim.endswith(file_name, 'vim') then
|
require("colorschemes")
|
||||||
local path = string.format("%s/core/%s", vim.fn.stdpath("config"), file_name)
|
|
||||||
local source_cmd = "source " .. path
|
|
||||||
vim.cmd(source_cmd)
|
|
||||||
else
|
|
||||||
local module_name, _ = string.gsub(file_name, "%.lua", "")
|
|
||||||
package.loaded[module_name] = nil
|
|
||||||
require(module_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -6,141 +6,77 @@ local M = {}
|
|||||||
|
|
||||||
-- Colorscheme to its directory name mapping, because colorscheme repo name is not necessarily
|
-- Colorscheme to its directory name mapping, because colorscheme repo name is not necessarily
|
||||||
-- the same as the colorscheme name itself.
|
-- the same as the colorscheme name itself.
|
||||||
M.colorscheme2dir = {
|
M.colorscheme_conf = {
|
||||||
onedark = "onedark.nvim",
|
onedark = function()
|
||||||
edge = "edge",
|
|
||||||
sonokai = "sonokai",
|
|
||||||
gruvbox_material = "gruvbox-material",
|
|
||||||
nord = "nord.nvim",
|
|
||||||
everforest = "everforest",
|
|
||||||
nightfox = "nightfox.nvim",
|
|
||||||
kanagawa = "kanagawa.nvim",
|
|
||||||
catppuccin = "catppuccin",
|
|
||||||
rose_pine = "rose-pine",
|
|
||||||
onedarkpro = "onedarkpro.nvim",
|
|
||||||
monokai = "monokai.nvim",
|
|
||||||
material = "material.nvim",
|
|
||||||
}
|
|
||||||
|
|
||||||
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]])
|
vim.cmd([[colorscheme onedark]])
|
||||||
end
|
end,
|
||||||
|
edge = function()
|
||||||
M.edge = function()
|
|
||||||
vim.g.edge_enable_italic = 1
|
vim.g.edge_enable_italic = 1
|
||||||
vim.g.edge_better_performance = 1
|
vim.g.edge_better_performance = 1
|
||||||
|
|
||||||
vim.cmd([[colorscheme edge]])
|
vim.cmd([[colorscheme edge]])
|
||||||
end
|
end,
|
||||||
|
sonokai = function()
|
||||||
M.sonokai = function()
|
|
||||||
vim.g.sonokai_enable_italic = 1
|
vim.g.sonokai_enable_italic = 1
|
||||||
vim.g.sonokai_better_performance = 1
|
vim.g.sonokai_better_performance = 1
|
||||||
|
|
||||||
vim.cmd([[colorscheme sonokai]])
|
vim.cmd([[colorscheme sonokai]])
|
||||||
end
|
end,
|
||||||
|
gruvbox_material = function()
|
||||||
M.gruvbox_material = function()
|
|
||||||
-- foreground option can be material, mix, or original
|
-- foreground option can be material, mix, or original
|
||||||
vim.g.gruvbox_material_foreground = "material"
|
vim.g.gruvbox_material_foreground = "original"
|
||||||
--background option can be hard, medium, soft
|
--background option can be hard, medium, soft
|
||||||
vim.g.gruvbox_material_background = "soft"
|
vim.g.gruvbox_material_background = "medium"
|
||||||
vim.g.gruvbox_material_enable_italic = 1
|
vim.g.gruvbox_material_enable_italic = 1
|
||||||
vim.g.gruvbox_material_better_performance = 1
|
vim.g.gruvbox_material_better_performance = 1
|
||||||
|
|
||||||
vim.cmd([[colorscheme gruvbox-material]])
|
vim.cmd([[colorscheme gruvbox-material]])
|
||||||
end
|
end,
|
||||||
|
everforest = function()
|
||||||
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_enable_italic = 1
|
||||||
vim.g.everforest_better_performance = 1
|
vim.g.everforest_better_performance = 1
|
||||||
|
|
||||||
vim.cmd([[colorscheme everforest]])
|
vim.cmd([[colorscheme everforest]])
|
||||||
end
|
end,
|
||||||
|
nightfox = function()
|
||||||
M.nightfox = function()
|
|
||||||
vim.cmd([[colorscheme nordfox]])
|
vim.cmd([[colorscheme nordfox]])
|
||||||
end
|
end,
|
||||||
|
catppuccin = function()
|
||||||
M.kanagawa = function()
|
|
||||||
vim.cmd([[colorscheme kanagawa]])
|
|
||||||
end
|
|
||||||
|
|
||||||
M.catppuccin = function()
|
|
||||||
-- available option: latte, frappe, macchiato, mocha
|
-- available option: latte, frappe, macchiato, mocha
|
||||||
vim.g.catppuccin_flavour = "frappe"
|
vim.g.catppuccin_flavour = "frappe"
|
||||||
|
|
||||||
require("catppuccin").setup()
|
require("catppuccin").setup()
|
||||||
|
|
||||||
vim.cmd([[colorscheme catppuccin]])
|
vim.cmd([[colorscheme catppuccin]])
|
||||||
end
|
end,
|
||||||
|
onedarkpro = function()
|
||||||
M.rose_pine = function()
|
|
||||||
require('rose-pine').setup({
|
|
||||||
--- @usage 'main' | 'moon'
|
|
||||||
dark_variant = 'moon',
|
|
||||||
})
|
|
||||||
|
|
||||||
-- set colorscheme after options
|
-- set colorscheme after options
|
||||||
vim.cmd('colorscheme rose-pine')
|
vim.cmd("colorscheme onedark_vivid")
|
||||||
end
|
end,
|
||||||
|
material = function()
|
||||||
M.onedarkpro = function()
|
|
||||||
-- set colorscheme after options
|
|
||||||
vim.cmd('colorscheme onedark_vivid')
|
|
||||||
end
|
|
||||||
|
|
||||||
M.monokai = function()
|
|
||||||
vim.cmd('colorscheme monokai_pro')
|
|
||||||
end
|
|
||||||
|
|
||||||
M.material = function ()
|
|
||||||
vim.g.material_style = "oceanic"
|
vim.g.material_style = "oceanic"
|
||||||
vim.cmd('colorscheme material')
|
vim.cmd("colorscheme material")
|
||||||
end
|
end,
|
||||||
|
arctic = function()
|
||||||
|
vim.cmd("colorscheme arctic")
|
||||||
|
end,
|
||||||
|
kanagawa = function()
|
||||||
|
vim.cmd("colorscheme kanagawa-wave")
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
--- Use a random colorscheme from the pre-defined list of colorschemes.
|
--- Use a random colorscheme from the pre-defined list of colorschemes.
|
||||||
M.rand_colorscheme = function()
|
M.rand_colorscheme = function()
|
||||||
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme2dir))
|
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
|
||||||
|
|
||||||
if not vim.tbl_contains(vim.tbl_keys(M), colorscheme) then
|
if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then
|
||||||
local msg = "Invalid colorscheme: " .. colorscheme
|
local msg = "Invalid colorscheme: " .. colorscheme
|
||||||
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
|
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
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
|
-- Load the colorscheme and its settings
|
||||||
M[colorscheme]()
|
M.colorscheme_conf[colorscheme]()
|
||||||
|
|
||||||
if vim.g.logging_level == "debug" then
|
if vim.g.logging_level == "debug" then
|
||||||
local msg = "Colorscheme: " .. colorscheme
|
local msg = "Colorscheme: " .. colorscheme
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require("bufferline").setup {
|
require("bufferline").setup {
|
||||||
options = {
|
options = {
|
||||||
numbers = "buffer_id",
|
numbers = "none",
|
||||||
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",
|
||||||
@@ -44,3 +44,7 @@ require("bufferline").setup {
|
|||||||
sort_by = "id",
|
sort_by = "id",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<space>bp", "<cmd>BufferLinePick<CR>", {
|
||||||
|
desc = "pick a buffer",
|
||||||
|
})
|
||||||
|
|||||||
@@ -59,17 +59,17 @@ conf.center = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
dashboard.setup({
|
dashboard.setup {
|
||||||
theme = 'doom',
|
theme = "doom",
|
||||||
shortcut_type = 'number',
|
shortcut_type = "number",
|
||||||
config = conf
|
config = conf,
|
||||||
})
|
}
|
||||||
|
|
||||||
api.nvim_create_autocmd("FileType", {
|
api.nvim_create_autocmd("FileType", {
|
||||||
pattern = "dashboard",
|
pattern = "dashboard",
|
||||||
group = api.nvim_create_augroup("dashboard_enter", { clear = true }),
|
group = api.nvim_create_augroup("dashboard_enter", { clear = true }),
|
||||||
callback = function ()
|
callback = function()
|
||||||
keymap.set("n", "q", ":qa<CR>", { buffer = true, silent = true })
|
keymap.set("n", "q", ":qa<CR>", { buffer = true, silent = true })
|
||||||
keymap.set("n", "e", ":enew<CR>", { buffer = true, silent = true })
|
keymap.set("n", "e", ":enew<CR>", { buffer = true, silent = true })
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,11 +1,27 @@
|
|||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
|
|
||||||
keymap.set("n", "<leader>gs", "<cmd>Git<cr>", { desc = "Git status" })
|
keymap.set("n", "<leader>gs", "<cmd>Git<cr>", { desc = "Git: show status" })
|
||||||
keymap.set("n", "<leader>gw", "<cmd>Gwrite<cr>", { desc = "Git add" })
|
keymap.set("n", "<leader>gw", "<cmd>Gwrite<cr>", { desc = "Git: add file" })
|
||||||
keymap.set("n", "<leader>gc", "<cmd>Git commit<cr>", { desc = "Git commit" })
|
keymap.set("n", "<leader>gc", "<cmd>Git commit<cr>", { desc = "Git: commit changes" })
|
||||||
keymap.set("n", "<leader>gd", "<cmd>Gdiffsplit<cr>", { desc = "Git diff" })
|
keymap.set("n", "<leader>gpl", "<cmd>Git pull<cr>", { desc = "Git: pull changes" })
|
||||||
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 changes" })
|
||||||
keymap.set("n", "<leader>gpu", "<cmd>15 split|term git push<cr>", { desc = "Git push" })
|
keymap.set("v", "<leader>gb", ":Git blame<cr>", { desc = "Git: blame selected line" })
|
||||||
|
|
||||||
-- convert git to Git in command line mode
|
-- convert git to Git in command line mode
|
||||||
vim.fn['utils#Cabbrev']('git', 'Git')
|
vim.fn["utils#Cabbrev"]("git", "Git")
|
||||||
|
|
||||||
|
keymap.set("n", "<leader>gbn", function()
|
||||||
|
vim.ui.input({ prompt = "Enter a new branch name" }, function(user_input)
|
||||||
|
if user_input == nil or user_input == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd_str = string.format("G checkout -b %s", user_input)
|
||||||
|
vim.cmd(cmd_str)
|
||||||
|
end)
|
||||||
|
end, {
|
||||||
|
desc = "Git: create new branch",
|
||||||
|
})
|
||||||
|
|
||||||
|
keymap.set("n", "<leader>gf", ":Git fetch ", { desc = "Git: prune branches" })
|
||||||
|
keymap.set("n", "<leader>gbd", ":Git branch -D ", { desc = "Git: delete branch" })
|
||||||
|
|||||||
@@ -5,16 +5,26 @@ gitlinker.setup {
|
|||||||
callbacks = {
|
callbacks = {
|
||||||
["dev.azure.com"] = function(url_data)
|
["dev.azure.com"] = function(url_data)
|
||||||
vim.print(url_data)
|
vim.print(url_data)
|
||||||
local url = require"gitlinker.hosts".get_base_https_url(url_data)
|
local url = require("gitlinker.hosts").get_base_https_url(url_data)
|
||||||
|
|
||||||
if url_data.lstart then
|
if url_data.lstart then
|
||||||
if url_data.lend == nil then
|
if url_data.lend == nil then
|
||||||
url_data.lend = url_data.lstart
|
url_data.lend = url_data.lstart
|
||||||
end
|
end
|
||||||
url = url .. "?path=/" .. url_data.file .. "&version=GC" .. url_data.rev .. "&line=" .. url_data.lstart .. "&lineEnd=" .. url_data.lend .. "&lineStartColumn=1" .. "&lineEndColumn=120"
|
url = url
|
||||||
|
.. "?path=/"
|
||||||
|
.. url_data.file
|
||||||
|
.. "&version=GC"
|
||||||
|
.. url_data.rev
|
||||||
|
.. "&line="
|
||||||
|
.. url_data.lstart
|
||||||
|
.. "&lineEnd="
|
||||||
|
.. url_data.lend
|
||||||
|
.. "&lineStartColumn=1"
|
||||||
|
.. "&lineEndColumn=120"
|
||||||
end
|
end
|
||||||
return url
|
return url
|
||||||
end
|
end,
|
||||||
},
|
},
|
||||||
mappings = nil,
|
mappings = nil,
|
||||||
}
|
}
|
||||||
@@ -24,14 +34,14 @@ keymap.set({ "n", "v" }, "<leader>gl", function()
|
|||||||
gitlinker.get_buf_range_url(mode)
|
gitlinker.get_buf_range_url(mode)
|
||||||
end, {
|
end, {
|
||||||
silent = true,
|
silent = true,
|
||||||
desc = "get git permlink",
|
desc = "Git: get permlink",
|
||||||
})
|
})
|
||||||
|
|
||||||
keymap.set("n", "<leader>gb", function()
|
keymap.set("n", "<leader>gbr", function()
|
||||||
gitlinker.get_repo_url({
|
gitlinker.get_repo_url {
|
||||||
action_callback = gitlinker.actions.open_in_browser
|
action_callback = gitlinker.actions.open_in_browser,
|
||||||
})
|
}
|
||||||
end, {
|
end, {
|
||||||
silent = true,
|
silent = true,
|
||||||
desc = "browse repo in browser",
|
desc = "Git: browse repo in browser",
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ local gs = require("gitsigns")
|
|||||||
|
|
||||||
gs.setup {
|
gs.setup {
|
||||||
signs = {
|
signs = {
|
||||||
add = { hl = "GitSignsAdd", text = "+", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" },
|
add = { text = "+" },
|
||||||
change = { hl = "GitSignsChange", text = "~", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
|
change = { text = "~" },
|
||||||
delete = { hl = "GitSignsDelete", text = "_", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
|
delete = { text = "_" },
|
||||||
topdelete = { hl = "GitSignsDelete", text = "‾", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" },
|
topdelete = { text = "‾" },
|
||||||
changedelete = { hl = "GitSignsChange", text = "│", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" },
|
changedelete = { text = "│" },
|
||||||
},
|
},
|
||||||
word_diff = true,
|
word_diff = true,
|
||||||
on_attach = function(bufnr)
|
on_attach = function(bufnr)
|
||||||
@@ -45,13 +45,13 @@ gs.setup {
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('ColorScheme', {
|
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.cmd [[
|
vim.cmd([[
|
||||||
hi GitSignsChangeInline gui=reverse
|
hi GitSignsChangeInline gui=reverse
|
||||||
hi GitSignsAddInline gui=reverse
|
hi GitSignsAddInline gui=reverse
|
||||||
hi GitSignsDeleteInline gui=reverse
|
hi GitSignsDeleteInline gui=reverse
|
||||||
]]
|
]])
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ 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.cmd, cmd)
|
local status, msg = pcall(vim.cmd, cmd)
|
||||||
|
|
||||||
|
-- Deal with the case that there is no such pattern in current buffer.
|
||||||
if not status then
|
if not status then
|
||||||
-- 13 is the index where real error message starts
|
local start_idx, _ = string.find(msg, "E486", 1, true)
|
||||||
msg = msg:sub(13)
|
local msg_part = string.sub(msg, start_idx)
|
||||||
api.nvim_err_writeln(msg)
|
api.nvim_err_writeln(msg_part)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -34,15 +35,48 @@ keymap.set("n", "N", "", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local check_cursor_word = function()
|
||||||
|
local cursor_word = vim.fn.expand("<cword>")
|
||||||
|
local result = cursor_word == ""
|
||||||
|
if result then
|
||||||
|
local msg = "E348: No string under cursor"
|
||||||
|
api.nvim_err_writeln(msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
return result, cursor_word
|
||||||
|
end
|
||||||
|
|
||||||
keymap.set("n", "*", "", {
|
keymap.set("n", "*", "", {
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.fn.execute("normal! *N")
|
local cursor_word_empty, cursor_word = check_cursor_word()
|
||||||
|
if cursor_word_empty then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = string.format([[normal! /\v<%s>]], cursor_word)
|
||||||
|
|
||||||
|
-- In order to say that we are pressing Enter key, instead of typing literally the character,
|
||||||
|
-- we need to replace special notation with their internal representation.
|
||||||
|
local escaped_enter = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
||||||
|
|
||||||
|
-- character `N` is used to keep the cursor when pressing `*`
|
||||||
|
local full_cmd = cmd .. escaped_enter .. "N"
|
||||||
|
vim.fn.execute(full_cmd)
|
||||||
hlslens.start()
|
hlslens.start()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
keymap.set("n", "#", "", {
|
keymap.set("n", "#", "", {
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.fn.execute("normal! #N")
|
local cursor_word_empty, cursor_word = check_cursor_word()
|
||||||
|
if cursor_word_empty then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local cmd = string.format([[normal! ?\v<%s>]], cursor_word)
|
||||||
|
local escaped_enter = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
||||||
|
|
||||||
|
local full_cmd = cmd .. escaped_enter .. "N"
|
||||||
|
vim.fn.execute(full_cmd)
|
||||||
hlslens.start()
|
hlslens.start()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha" }
|
local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha", "dashboard" }
|
||||||
require("indent_blankline").setup {
|
|
||||||
-- U+2502 may also be a good choice, it will be on the middle of cursor.
|
require("ibl").setup {
|
||||||
-- U+250A is also a good choice
|
indent = {
|
||||||
|
-- -- U+2502 may also be a good choice, it will be on the middle of cursor.
|
||||||
|
-- -- U+250A is also a good choice
|
||||||
char = "▏",
|
char = "▏",
|
||||||
show_end_of_line = false,
|
},
|
||||||
disable_with_nolist = true,
|
scope = {
|
||||||
buftype_exclude = { "terminal" },
|
show_start = false,
|
||||||
filetype_exclude = exclude_ft,
|
show_end = false,
|
||||||
|
},
|
||||||
|
exclude = {
|
||||||
|
filetypes = exclude_ft,
|
||||||
|
buftypes = { "terminal" },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
|
local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
|
||||||
api.nvim_create_autocmd("InsertEnter", {
|
api.nvim_create_autocmd("InsertEnter", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
group = gid,
|
group = gid,
|
||||||
command = "IndentBlanklineDisable",
|
command = "IBLDisable",
|
||||||
})
|
})
|
||||||
|
|
||||||
api.nvim_create_autocmd("InsertLeave", {
|
api.nvim_create_autocmd("InsertLeave", {
|
||||||
@@ -23,7 +30,7 @@ api.nvim_create_autocmd("InsertLeave", {
|
|||||||
group = gid,
|
group = gid,
|
||||||
callback = function()
|
callback = function()
|
||||||
if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
|
if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
|
||||||
vim.cmd([[IndentBlanklineEnable]])
|
vim.cmd([[IBLEnable]])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
4
lua/config/live-command.lua
Normal file
4
lua/config/live-command.lua
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
require("live-command").setup {
|
||||||
|
enable_highlighting = true,
|
||||||
|
inline_highlighting = true,
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ local api = vim.api
|
|||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
local lsp = vim.lsp
|
local lsp = vim.lsp
|
||||||
local diagnostic = vim.diagnostic
|
local diagnostic = vim.diagnostic
|
||||||
|
local lspconfig = require("lspconfig")
|
||||||
|
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
@@ -12,10 +13,10 @@ local set_qflist = function(buf_num, severity)
|
|||||||
diagnostics = diagnostic.get(buf_num, { severity = severity })
|
diagnostics = diagnostic.get(buf_num, { severity = severity })
|
||||||
|
|
||||||
local qf_items = diagnostic.toqflist(diagnostics)
|
local qf_items = diagnostic.toqflist(diagnostics)
|
||||||
vim.fn.setqflist({}, ' ', { title = 'Diagnostics', items = qf_items })
|
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
|
||||||
|
|
||||||
-- open quickfix by default
|
-- open quickfix by default
|
||||||
vim.cmd[[copen]]
|
vim.cmd([[copen]])
|
||||||
end
|
end
|
||||||
|
|
||||||
local custom_attach = function(client, bufnr)
|
local custom_attach = function(client, bufnr)
|
||||||
@@ -38,19 +39,25 @@ local custom_attach = function(client, bufnr)
|
|||||||
-- this puts diagnostics from opened files to quickfix
|
-- this puts diagnostics from opened files to quickfix
|
||||||
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
||||||
-- this puts diagnostics from current buffer to quickfix
|
-- this puts diagnostics from current buffer to quickfix
|
||||||
map("n", "<space>qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" })
|
map("n", "<space>qb", function()
|
||||||
|
set_qflist(bufnr)
|
||||||
|
end, { desc = "put buffer diagnostics to qf" })
|
||||||
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
|
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>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>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
|
||||||
map("n", "<space>wl", function()
|
map("n", "<space>wl", function()
|
||||||
inspect(vim.lsp.buf.list_workspace_folders())
|
vim.print(vim.lsp.buf.list_workspace_folders())
|
||||||
end, { desc = "list workspace folder" })
|
end, { desc = "list workspace folder" })
|
||||||
|
|
||||||
-- Set some key bindings conditional on server capabilities
|
-- Set some key bindings conditional on server capabilities
|
||||||
if client.server_capabilities.documentFormattingProvider then
|
if client.server_capabilities.documentFormattingProvider and client.name ~= "lua_ls" then
|
||||||
map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" })
|
map({ "n", "x" }, "<space>f", vim.lsp.buf.format, { desc = "format code" })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Uncomment code below to enable inlay hint from language server, some LSP server supports inlay hint,
|
||||||
|
-- but disable this feature by default, so you may need to enable inlay hint in the LSP server config.
|
||||||
|
-- vim.lsp.inlay_hint.enable(true, {buffer=bufnr})
|
||||||
|
|
||||||
api.nvim_create_autocmd("CursorHold", {
|
api.nvim_create_autocmd("CursorHold", {
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function()
|
callback = function()
|
||||||
@@ -67,7 +74,8 @@ local custom_attach = function(client, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local cursor_pos = 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])
|
if
|
||||||
|
(cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
|
||||||
and #diagnostic.get() > 0
|
and #diagnostic.get() > 0
|
||||||
then
|
then
|
||||||
diagnostic.open_float(nil, float_opts)
|
diagnostic.open_float(nil, float_opts)
|
||||||
@@ -86,20 +94,20 @@ local custom_attach = function(client, bufnr)
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||||
api.nvim_create_autocmd("CursorHold" , {
|
api.nvim_create_autocmd("CursorHold", {
|
||||||
group = gid,
|
group = gid,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function ()
|
callback = function()
|
||||||
lsp.buf.document_highlight()
|
lsp.buf.document_highlight()
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
api.nvim_create_autocmd("CursorMoved" , {
|
api.nvim_create_autocmd("CursorMoved", {
|
||||||
group = gid,
|
group = gid,
|
||||||
buffer = bufnr,
|
buffer = bufnr,
|
||||||
callback = function ()
|
callback = function()
|
||||||
lsp.buf.clear_references()
|
lsp.buf.clear_references()
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -109,65 +117,101 @@ local custom_attach = function(client, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
|
|
||||||
local lspconfig = require("lspconfig")
|
-- required by nvim-ufo
|
||||||
|
capabilities.textDocument.foldingRange = {
|
||||||
|
dynamicRegistration = false,
|
||||||
|
lineFoldingOnly = true,
|
||||||
|
}
|
||||||
|
|
||||||
if utils.executable("pylsp") then
|
-- For what diagnostic is enabled in which type checking mode, check doc:
|
||||||
local venv_path = os.getenv('VIRTUAL_ENV')
|
-- https://github.com/microsoft/pyright/blob/main/docs/configuration.md#diagnostic-settings-defaults
|
||||||
local py_path = nil
|
-- Currently, the pyright also has some issues displaying hover documentation:
|
||||||
-- decide which python executable to use for mypy
|
-- https://www.reddit.com/r/neovim/comments/1gdv1rc/what_is_causeing_the_lsp_hover_docs_to_looks_like/
|
||||||
if venv_path ~= nil then
|
|
||||||
py_path = venv_path .. "/bin/python3"
|
|
||||||
else
|
|
||||||
py_path = vim.g.python3_host_prog
|
|
||||||
end
|
|
||||||
|
|
||||||
lspconfig.pylsp.setup {
|
if utils.executable("pyright") then
|
||||||
|
local new_capability = {
|
||||||
|
-- this will remove some of the diagnostics that duplicates those from ruff, idea taken and adapted from
|
||||||
|
-- here: https://github.com/astral-sh/ruff-lsp/issues/384#issuecomment-1989619482
|
||||||
|
textDocument = {
|
||||||
|
publishDiagnostics = {
|
||||||
|
tagSupport = {
|
||||||
|
valueSet = { 2 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
hover = {
|
||||||
|
contentFormat = { "plaintext" },
|
||||||
|
dynamicRegistration = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
local merged_capability = vim.tbl_deep_extend("force", capabilities, new_capability)
|
||||||
|
|
||||||
|
lspconfig.pyright.setup {
|
||||||
|
cmd = { "delance-langserver", "--stdio" },
|
||||||
on_attach = custom_attach,
|
on_attach = custom_attach,
|
||||||
|
capabilities = merged_capability,
|
||||||
settings = {
|
settings = {
|
||||||
pylsp = {
|
pyright = {
|
||||||
plugins = {
|
-- disable import sorting and use Ruff for this
|
||||||
-- formatter options
|
disableOrganizeImports = true,
|
||||||
black = { enabled = true },
|
disableTaggedHints = false,
|
||||||
autopep8 = { enabled = false },
|
|
||||||
yapf = { enabled = false },
|
|
||||||
-- linter options
|
|
||||||
pylint = { enabled = true, executable = "pylint" },
|
|
||||||
ruff = { enabled = false },
|
|
||||||
pyflakes = { enabled = false },
|
|
||||||
pycodestyle = { enabled = false },
|
|
||||||
-- type checker
|
|
||||||
pylsp_mypy = {
|
|
||||||
enabled = true,
|
|
||||||
overrides = { "--python-executable", py_path, true },
|
|
||||||
report_progress = true,
|
|
||||||
live_mode = false
|
|
||||||
},
|
},
|
||||||
-- auto-completion options
|
python = {
|
||||||
jedi_completion = { fuzzy = true },
|
analysis = {
|
||||||
-- import sorting
|
autoSearchPaths = true,
|
||||||
isort = { enabled = true },
|
diagnosticMode = "workspace",
|
||||||
|
typeCheckingMode = "standard",
|
||||||
|
useLibraryCodeForTypes = true,
|
||||||
|
-- we can this setting below to redefine some diagnostics
|
||||||
|
diagnosticSeverityOverrides = {
|
||||||
|
deprecateTypingAliases = false,
|
||||||
|
},
|
||||||
|
-- inlay hint settings are provided by pylance?
|
||||||
|
inlayHints = {
|
||||||
|
callArgumentNames = "partial",
|
||||||
|
functionReturnTypes = true,
|
||||||
|
pytestParameters = true,
|
||||||
|
variableTypes = true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
flags = {
|
|
||||||
debounce_text_changes = 200,
|
|
||||||
},
|
},
|
||||||
capabilities = capabilities,
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" })
|
vim.notify("pyright not found!", vim.log.levels.WARN, { title = "Nvim-config" })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if utils.executable('pyright') then
|
if utils.executable("ruff") then
|
||||||
-- lspconfig.pyright.setup{
|
require("lspconfig").ruff.setup {
|
||||||
-- on_attach = custom_attach,
|
on_attach = custom_attach,
|
||||||
-- capabilities = capabilities
|
capabilities = capabilities,
|
||||||
-- }
|
init_options = {
|
||||||
-- else
|
-- the settings can be found here: https://docs.astral.sh/ruff/editors/settings/
|
||||||
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
|
settings = {
|
||||||
-- end
|
organizeImports = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Disable ruff hover feature in favor of Pyright
|
||||||
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
|
group = vim.api.nvim_create_augroup("lsp_attach_disable_ruff_hover", { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
|
-- vim.print(client.name, client.server_capabilities)
|
||||||
|
|
||||||
|
if client == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if client.name == "ruff" then
|
||||||
|
client.server_capabilities.hoverProvider = false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
desc = "LSP: Disable hover capability from Ruff",
|
||||||
|
})
|
||||||
|
|
||||||
if utils.executable("ltex-ls") then
|
if utils.executable("ltex-ls") then
|
||||||
lspconfig.ltex.setup {
|
lspconfig.ltex.setup {
|
||||||
@@ -176,11 +220,11 @@ if utils.executable("ltex-ls") then
|
|||||||
filetypes = { "text", "plaintex", "tex", "markdown" },
|
filetypes = { "text", "plaintex", "tex", "markdown" },
|
||||||
settings = {
|
settings = {
|
||||||
ltex = {
|
ltex = {
|
||||||
language = "en"
|
language = "en",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
flags = { debounce_text_changes = 300 },
|
flags = { debounce_text_changes = 300 },
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if utils.executable("clangd") then
|
if utils.executable("clangd") then
|
||||||
@@ -215,8 +259,8 @@ if utils.executable("bash-language-server") then
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- settings for lua-language-server can be found on https://luals.github.io/wiki/settings/
|
||||||
if utils.executable("lua-language-server") then
|
if utils.executable("lua-language-server") then
|
||||||
-- settings for lua-language-server can be found on https://github.com/LuaLS/lua-language-server/wiki/Settings .
|
|
||||||
lspconfig.lua_ls.setup {
|
lspconfig.lua_ls.setup {
|
||||||
on_attach = custom_attach,
|
on_attach = custom_attach,
|
||||||
settings = {
|
settings = {
|
||||||
@@ -225,20 +269,8 @@ if utils.executable("lua-language-server") then
|
|||||||
-- 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",
|
||||||
},
|
},
|
||||||
diagnostics = {
|
hint = {
|
||||||
-- Get the language server to recognize the `vim` global
|
enable = true,
|
||||||
globals = { "vim" },
|
|
||||||
},
|
|
||||||
workspace = {
|
|
||||||
-- Make the server aware of Neovim runtime files,
|
|
||||||
-- see also https://github.com/LuaLS/lua-language-server/wiki/Libraries#link-to-workspace .
|
|
||||||
-- Lua-dev.nvim also has similar settings for lua ls, https://github.com/folke/neodev.nvim/blob/main/lua/neodev/luals.lua .
|
|
||||||
library = {
|
|
||||||
fn.stdpath("data") .. "/site/pack/packer/opt/emmylua-nvim",
|
|
||||||
fn.stdpath("config"),
|
|
||||||
},
|
|
||||||
maxPreload = 2000,
|
|
||||||
preloadFileSize = 50000,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -247,10 +279,10 @@ if utils.executable("lua-language-server") then
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Change diagnostic signs.
|
-- Change diagnostic signs.
|
||||||
fn.sign_define("DiagnosticSignError", { text = '🆇', texthl = "DiagnosticSignError" })
|
fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" })
|
||||||
fn.sign_define("DiagnosticSignWarn", { text = '⚠️', texthl = "DiagnosticSignWarn" })
|
fn.sign_define("DiagnosticSignWarn", { text = "⚠️", texthl = "DiagnosticSignWarn" })
|
||||||
fn.sign_define("DiagnosticSignInfo", { text = 'ℹ️', texthl = "DiagnosticSignInfo" })
|
fn.sign_define("DiagnosticSignInfo", { text = "ℹ️", texthl = "DiagnosticSignInfo" })
|
||||||
fn.sign_define("DiagnosticSignHint", { text = '', texthl = "DiagnosticSignHint" })
|
fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
|
||||||
|
|
||||||
-- global config for diagnostic
|
-- global config for diagnostic
|
||||||
diagnostic.config {
|
diagnostic.config {
|
||||||
|
|||||||
@@ -97,44 +97,109 @@ local diff = function()
|
|||||||
return info
|
return info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local virtual_env = function()
|
||||||
|
-- only show virtual env for Python
|
||||||
|
if vim.bo.filetype ~= "python" then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local conda_env = os.getenv("CONDA_DEFAULT_ENV")
|
||||||
|
local venv_path = os.getenv("VIRTUAL_ENV")
|
||||||
|
|
||||||
|
if venv_path == nil then
|
||||||
|
if conda_env == nil then
|
||||||
|
return ""
|
||||||
|
else
|
||||||
|
return string.format(" %s (conda)", conda_env)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local venv_name = vim.fn.fnamemodify(venv_path, ":t")
|
||||||
|
return string.format(" %s (venv)", venv_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_active_lsp = function()
|
||||||
|
local msg = "No Active Lsp"
|
||||||
|
local buf_ft = vim.api.nvim_get_option_value("filetype", {})
|
||||||
|
local clients = vim.lsp.get_clients { bufnr = 0 }
|
||||||
|
if next(clients) == nil then
|
||||||
|
return msg
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, client in ipairs(clients) do
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
|
local filetypes = client.config.filetypes
|
||||||
|
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
|
||||||
|
return client.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return msg
|
||||||
|
end
|
||||||
|
|
||||||
require("lualine").setup {
|
require("lualine").setup {
|
||||||
options = {
|
options = {
|
||||||
icons_enabled = true,
|
icons_enabled = true,
|
||||||
theme = "auto",
|
theme = "auto",
|
||||||
-- component_separators = { left = "", right = "" },
|
component_separators = { left = "⏐", right = "⏐" },
|
||||||
-- section_separators = { left = "", right = "" },
|
|
||||||
section_separators = "",
|
section_separators = "",
|
||||||
component_separators = "",
|
|
||||||
disabled_filetypes = {},
|
disabled_filetypes = {},
|
||||||
always_divide_middle = true,
|
always_divide_middle = true,
|
||||||
},
|
},
|
||||||
sections = {
|
sections = {
|
||||||
lualine_a = { "mode" },
|
lualine_a = {
|
||||||
|
"mode",
|
||||||
|
},
|
||||||
lualine_b = {
|
lualine_b = {
|
||||||
|
{
|
||||||
"branch",
|
"branch",
|
||||||
|
fmt = function(name, _)
|
||||||
|
-- truncate branch name in case the name is too long
|
||||||
|
return string.sub(name, 1, 20)
|
||||||
|
end,
|
||||||
|
color = { gui = "italic,bold" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
virtual_env,
|
||||||
|
color = { fg = "black", bg = "#F1CA81" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
lualine_c = {
|
||||||
|
{
|
||||||
|
"filename",
|
||||||
|
symbols = {
|
||||||
|
readonly = "[🔒]",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"diff",
|
"diff",
|
||||||
source = diff,
|
source = diff,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
lualine_c = {
|
|
||||||
"filename",
|
|
||||||
{
|
{
|
||||||
ime_state,
|
"%S",
|
||||||
color = { fg = "black", bg = "#f46868" },
|
color = { gui = "bold", fg = "cyan" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
spell,
|
spell,
|
||||||
color = { fg = "black", bg = "#a7c080" },
|
color = { fg = "black", bg = "#a7c080" },
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
lualine_x = {
|
||||||
|
{
|
||||||
|
ime_state,
|
||||||
|
color = { fg = "black", bg = "#f46868" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
get_active_lsp,
|
||||||
|
icon = " LSP:",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"diagnostics",
|
"diagnostics",
|
||||||
sources = { "nvim_diagnostic" },
|
sources = { "nvim_diagnostic" },
|
||||||
symbols = {error = '🆇 ', warn = '⚠️ ', info = 'ℹ️ ', hint = ' '},
|
symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lualine_x = {
|
lualine_y = {
|
||||||
"encoding",
|
{ "encoding", fmt = string.upper },
|
||||||
{
|
{
|
||||||
"fileformat",
|
"fileformat",
|
||||||
symbols = {
|
symbols = {
|
||||||
@@ -145,10 +210,6 @@ require("lualine").setup {
|
|||||||
},
|
},
|
||||||
"filetype",
|
"filetype",
|
||||||
},
|
},
|
||||||
lualine_y = {
|
|
||||||
"location",
|
|
||||||
"progress",
|
|
||||||
},
|
|
||||||
lualine_z = {
|
lualine_z = {
|
||||||
{
|
{
|
||||||
trailing_space,
|
trailing_space,
|
||||||
@@ -158,6 +219,8 @@ require("lualine").setup {
|
|||||||
mixed_indent,
|
mixed_indent,
|
||||||
color = "WarningMsg",
|
color = "WarningMsg",
|
||||||
},
|
},
|
||||||
|
"location",
|
||||||
|
"progress",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
inactive_sections = {
|
inactive_sections = {
|
||||||
@@ -35,7 +35,6 @@ cmp.setup {
|
|||||||
{ name = "ultisnips" }, -- For ultisnips user.
|
{ name = "ultisnips" }, -- For ultisnips user.
|
||||||
{ name = "path" }, -- for path completion
|
{ name = "path" }, -- for path completion
|
||||||
{ name = "buffer", keyword_length = 2 }, -- for buffer word completion
|
{ name = "buffer", keyword_length = 2 }, -- for buffer word completion
|
||||||
{ name = "emoji", insert = true }, -- emoji completion
|
|
||||||
},
|
},
|
||||||
completion = {
|
completion = {
|
||||||
keyword_length = 1,
|
keyword_length = 1,
|
||||||
@@ -50,12 +49,14 @@ cmp.setup {
|
|||||||
menu = {
|
menu = {
|
||||||
nvim_lsp = "[LSP]",
|
nvim_lsp = "[LSP]",
|
||||||
ultisnips = "[US]",
|
ultisnips = "[US]",
|
||||||
nvim_lua = "[Lua]",
|
|
||||||
path = "[Path]",
|
path = "[Path]",
|
||||||
buffer = "[Buffer]",
|
buffer = "[Buffer]",
|
||||||
emoji = "[Emoji]",
|
emoji = "[Emoji]",
|
||||||
omni = "[Omni]",
|
omni = "[Omni]",
|
||||||
},
|
},
|
||||||
|
show_labelDetails = true,
|
||||||
|
maxwidth = 40,
|
||||||
|
ellipsis_char = "...",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
23
lua/config/nvim-statuscol.lua
Normal file
23
lua/config/nvim-statuscol.lua
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
local builtin = require("statuscol.builtin")
|
||||||
|
local ffi = require("statuscol.ffidef")
|
||||||
|
local C = ffi.C
|
||||||
|
|
||||||
|
-- only show fold level up to this level
|
||||||
|
local fold_level_limit = 3
|
||||||
|
local function foldfunc(args)
|
||||||
|
local foldinfo = C.fold_info(args.wp, args.lnum)
|
||||||
|
if foldinfo.level > fold_level_limit then
|
||||||
|
return " "
|
||||||
|
end
|
||||||
|
|
||||||
|
return builtin.foldfunc(args)
|
||||||
|
end
|
||||||
|
|
||||||
|
require("statuscol").setup {
|
||||||
|
relculright = false,
|
||||||
|
segments = {
|
||||||
|
{ text = { "%s" }, click = "v:lua.ScSa" },
|
||||||
|
{ text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
|
||||||
|
{ text = { foldfunc, " " }, condition = { true, builtin.not_empty }, click = "v:lua.ScFa" },
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -4,26 +4,19 @@ 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_netrw = true,
|
hijack_netrw = true,
|
||||||
|
hijack_cursor = false,
|
||||||
hijack_unnamed_buffer_when_opening = false,
|
hijack_unnamed_buffer_when_opening = false,
|
||||||
open_on_tab = false,
|
open_on_tab = false,
|
||||||
sort_by = "name",
|
sort_by = "name",
|
||||||
update_cwd = false,
|
update_cwd = false,
|
||||||
view = {
|
view = {
|
||||||
width = 30,
|
width = 30,
|
||||||
hide_root_folder = false,
|
|
||||||
side = "left",
|
side = "left",
|
||||||
preserve_window_proportions = false,
|
preserve_window_proportions = false,
|
||||||
number = false,
|
number = false,
|
||||||
relativenumber = false,
|
relativenumber = false,
|
||||||
signcolumn = "yes",
|
signcolumn = "yes",
|
||||||
mappings = {
|
|
||||||
custom_only = false,
|
|
||||||
list = {
|
|
||||||
-- user mappings go here
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
renderer = {
|
renderer = {
|
||||||
indent_markers = {
|
indent_markers = {
|
||||||
@@ -85,7 +78,7 @@ nvim_tree.setup {
|
|||||||
enable = true,
|
enable = true,
|
||||||
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
|
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
|
||||||
exclude = {
|
exclude = {
|
||||||
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
|
filetype = { "notify", "qf", "diff", "fugitive", "fugitiveblame" },
|
||||||
buftype = { "nofile", "terminal", "help" },
|
buftype = { "nofile", "terminal", "help" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
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 HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff]])
|
|
||||||
|
|
||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
local hop = require("hop")
|
local hop = require("hop")
|
||||||
hop.setup {
|
hop.setup {
|
||||||
case_insensitive = true,
|
case_insensitive = true,
|
||||||
char2_fallback_key = "<CR>",
|
char2_fallback_key = "<CR>",
|
||||||
quit_key = "<Esc>",
|
quit_key = "<Esc>",
|
||||||
|
match_mappings = { "zh_sc" },
|
||||||
}
|
}
|
||||||
|
|
||||||
keymap.set({ "n", "v", "o" }, "f", "", {
|
keymap.set({ "n", "v", "o" }, "f", "", {
|
||||||
@@ -18,3 +15,14 @@ keymap.set({ "n", "v", "o" }, "f", "", {
|
|||||||
end,
|
end,
|
||||||
desc = "nvim-hop char2",
|
desc = "nvim-hop char2",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("ColorScheme", {
|
||||||
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
vim.cmd([[
|
||||||
|
hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
|
||||||
|
hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
|
||||||
|
hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
|
||||||
|
]])
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|||||||
44
lua/config/nvim_ufo.lua
Normal file
44
lua/config/nvim_ufo.lua
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
local handler = function(virtText, lnum, endLnum, width, truncate)
|
||||||
|
local newVirtText = {}
|
||||||
|
local foldedLines = endLnum - lnum
|
||||||
|
local suffix = (" %d"):format(foldedLines)
|
||||||
|
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
||||||
|
local targetWidth = width - sufWidth
|
||||||
|
local curWidth = 0
|
||||||
|
|
||||||
|
for _, chunk in ipairs(virtText) do
|
||||||
|
local chunkText = chunk[1]
|
||||||
|
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||||
|
if targetWidth > curWidth + chunkWidth then
|
||||||
|
table.insert(newVirtText, chunk)
|
||||||
|
else
|
||||||
|
chunkText = truncate(chunkText, targetWidth - curWidth)
|
||||||
|
local hlGroup = chunk[2]
|
||||||
|
table.insert(newVirtText, { chunkText, hlGroup })
|
||||||
|
chunkWidth = vim.fn.strdisplaywidth(chunkText)
|
||||||
|
-- str width returned from truncate() may less than 2nd argument, need padding
|
||||||
|
if curWidth + chunkWidth < targetWidth then
|
||||||
|
suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
curWidth = curWidth + chunkWidth
|
||||||
|
end
|
||||||
|
local rAlignAppndx = math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0)
|
||||||
|
suffix = (" "):rep(rAlignAppndx) .. suffix
|
||||||
|
table.insert(newVirtText, { suffix, "MoreMsg" })
|
||||||
|
return newVirtText
|
||||||
|
end
|
||||||
|
|
||||||
|
require("ufo").setup {
|
||||||
|
fold_virt_text_handler = handler,
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.keymap.set("n", "zR", require("ufo").openAllFolds)
|
||||||
|
vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
|
||||||
|
vim.keymap.set("n", "zr", require("ufo").openFoldsExceptKinds)
|
||||||
|
vim.keymap.set("n", "<leader>K", function()
|
||||||
|
local _ = require("ufo").peekFoldedLinesUnderCursor()
|
||||||
|
end, {
|
||||||
|
desc = "Preview folded maps",
|
||||||
|
})
|
||||||
@@ -3,6 +3,6 @@ require("nvim-treesitter.configs").setup {
|
|||||||
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 = { 'help' }, -- list of language that will be disabled
|
disable = { "help" }, -- list of language that will be disabled
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +1,6 @@
|
|||||||
require("which-key").setup {
|
require("which-key").setup {
|
||||||
plugins = {
|
preset = "modern",
|
||||||
marks = true, -- shows a list of your marks on ' and `
|
|
||||||
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
|
|
||||||
spelling = {
|
|
||||||
enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
|
|
||||||
suggestions = 9, -- how many suggestions should be shown in the list?
|
|
||||||
},
|
|
||||||
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
|
|
||||||
-- No actual key bindings are created
|
|
||||||
presets = {
|
|
||||||
operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion
|
|
||||||
motions = true, -- adds help for motions
|
|
||||||
text_objects = true, -- help for text objects triggered after entering an operator
|
|
||||||
windows = true, -- default bindings on <c-w>
|
|
||||||
nav = true, -- misc bindings to work with windows
|
|
||||||
z = true, -- bindings for folds, spelling and others prefixed with z
|
|
||||||
g = true, -- bindings for prefixed with g
|
|
||||||
},
|
|
||||||
},
|
|
||||||
-- add operators that will trigger motion and text object completion
|
|
||||||
-- to enable all native operators, set the preset / operators plugin above
|
|
||||||
operators = { gc = "Comments" },
|
|
||||||
key_labels = {
|
|
||||||
-- override the label used to display some keys. It doesn't effect WK in any other way.
|
|
||||||
-- For example:
|
|
||||||
-- ["<space>"] = "SPC",
|
|
||||||
-- ["<cr>"] = "RET",
|
|
||||||
-- ["<tab>"] = "TAB",
|
|
||||||
},
|
|
||||||
icons = {
|
icons = {
|
||||||
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
|
mappings = false,
|
||||||
separator = "➜", -- symbol used between a key and it's label
|
|
||||||
group = "+", -- symbol prepended to a group
|
|
||||||
},
|
|
||||||
window = {
|
|
||||||
border = "none", -- none, single, double, shadow
|
|
||||||
position = "bottom", -- bottom, top
|
|
||||||
margin = { 0, 0, 0, 0 }, -- extra window margin [top, right, bottom, left]
|
|
||||||
padding = { 1, 0, 1, 0 }, -- extra window padding [top, right, bottom, left]
|
|
||||||
},
|
|
||||||
layout = {
|
|
||||||
height = { min = 1, max = 25 }, -- min and max height of the columns
|
|
||||||
width = { min = 20, max = 50 }, -- min and max width of the columns
|
|
||||||
spacing = 1, -- spacing between columns
|
|
||||||
align = "center", -- align columns left, center or right
|
|
||||||
},
|
|
||||||
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
|
|
||||||
show_help = true, -- show help message on the command line when the popup is visible
|
|
||||||
triggers = "auto", -- automatically setup triggers
|
|
||||||
-- triggers = {"<leader>"} -- or specify a list manually
|
|
||||||
|
|
||||||
triggers_blacklist = {
|
|
||||||
-- list of mode / prefixes that should never be hooked by WhichKey
|
|
||||||
-- this is mostly relevant for key maps that start with a native binding
|
|
||||||
-- most people should not need to change this
|
|
||||||
n = { "o", "O" },
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
require("yanky").setup({
|
require("yanky").setup {
|
||||||
ring = {
|
|
||||||
history_length = 50,
|
|
||||||
storage = "memory",
|
|
||||||
},
|
|
||||||
preserve_cursor_position = {
|
preserve_cursor_position = {
|
||||||
enabled = false,
|
enabled = false,
|
||||||
},
|
},
|
||||||
})
|
highlight = {
|
||||||
|
on_put = true,
|
||||||
|
on_yank = false,
|
||||||
|
timer = 300,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.keymap.set({ "n", "x" }, "p", "<Plug>(YankyPutAfter)")
|
||||||
|
vim.keymap.set({ "n", "x" }, "P", "<Plug>(YankyPutBefore)")
|
||||||
|
|
||||||
-- cycle through the yank history, only work after paste
|
-- cycle through the yank history, only work after paste
|
||||||
vim.keymap.set("n", "[y", "<Plug>(YankyCycleForward)")
|
vim.keymap.set("n", "[y", "<Plug>(YankyPreviousEntry)")
|
||||||
vim.keymap.set("n", "]y", "<Plug>(YankyCycleBackward)")
|
vim.keymap.set("n", "]y", "<Plug>(YankyNextEntry)")
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
require("zen-mode").setup {
|
|
||||||
window = {
|
|
||||||
backdrop = 0.8, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal
|
|
||||||
width = 120,
|
|
||||||
options = {
|
|
||||||
-- signcolumn = "no", -- disable signcolumn
|
|
||||||
-- number = false, -- disable number column
|
|
||||||
-- relativenumber = false, -- disable relative numbers
|
|
||||||
cursorline = false, -- disable cursorline
|
|
||||||
cursorcolumn = false, -- disable cursor column
|
|
||||||
foldcolumn = "0", -- disable fold column
|
|
||||||
list = false, -- disable whitespace characters
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -17,14 +17,33 @@ api.nvim_create_autocmd({ "BufRead" }, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- highlight yanked region, see `:h lua-highlight`
|
-- highlight yanked region, see `:h lua-highlight`
|
||||||
|
local yank_group = api.nvim_create_augroup("highlight_yank", { clear = true })
|
||||||
api.nvim_create_autocmd({ "TextYankPost" }, {
|
api.nvim_create_autocmd({ "TextYankPost" }, {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
group = api.nvim_create_augroup("highlight_yank", { clear = true }),
|
group = yank_group,
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.highlight.on_yank { higroup = "YankColor", timeout = 300 }
|
vim.highlight.on_yank { higroup = "YankColor", timeout = 300 }
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd({ "CursorMoved" }, {
|
||||||
|
pattern = "*",
|
||||||
|
group = yank_group,
|
||||||
|
callback = function()
|
||||||
|
vim.g.current_cursor_pos = vim.fn.getcurpos()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("TextYankPost", {
|
||||||
|
pattern = "*",
|
||||||
|
group = yank_group,
|
||||||
|
callback = function(ev)
|
||||||
|
if vim.v.event.operator == "y" then
|
||||||
|
vim.fn.setpos(".", vim.g.current_cursor_pos)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
-- Auto-create dir when saving a file, in case some intermediate directory does not exist
|
-- Auto-create dir when saving a file, in case some intermediate directory does not exist
|
||||||
api.nvim_create_autocmd({ "BufWritePre" }, {
|
api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
@@ -64,3 +83,192 @@ api.nvim_create_autocmd("VimResized", {
|
|||||||
desc = "autoresize windows on resizing operation",
|
desc = "autoresize windows on resizing operation",
|
||||||
command = "wincmd =",
|
command = "wincmd =",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function open_nvim_tree(data)
|
||||||
|
-- check if buffer is a directory
|
||||||
|
local directory = vim.fn.isdirectory(data.file) == 1
|
||||||
|
|
||||||
|
if not directory then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- create a new, empty buffer
|
||||||
|
vim.cmd.enew()
|
||||||
|
|
||||||
|
-- wipe the directory buffer
|
||||||
|
vim.cmd.bw(data.buf)
|
||||||
|
|
||||||
|
-- open the tree
|
||||||
|
require("nvim-tree.api").tree.open()
|
||||||
|
end
|
||||||
|
|
||||||
|
api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
||||||
|
|
||||||
|
-- Do not use smart case in command line mode, extracted from https://vi.stackexchange.com/a/16511/15292.
|
||||||
|
api.nvim_create_augroup("dynamic_smartcase", { clear = true })
|
||||||
|
api.nvim_create_autocmd("CmdLineEnter", {
|
||||||
|
group = "dynamic_smartcase",
|
||||||
|
pattern = ":",
|
||||||
|
callback = function()
|
||||||
|
vim.o.smartcase = false
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("CmdLineLeave", {
|
||||||
|
group = "dynamic_smartcase",
|
||||||
|
pattern = ":",
|
||||||
|
callback = function()
|
||||||
|
vim.o.smartcase = true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("TermOpen", {
|
||||||
|
group = api.nvim_create_augroup("term_start", { clear = true }),
|
||||||
|
pattern = "*",
|
||||||
|
callback = function()
|
||||||
|
-- Do not use number and relative number for terminal inside nvim
|
||||||
|
vim.wo.relativenumber = false
|
||||||
|
vim.wo.number = false
|
||||||
|
|
||||||
|
-- Go to insert mode by default to start typing command
|
||||||
|
vim.cmd("startinsert")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Return to last cursor position when opening a file, note that here we cannot use BufReadPost
|
||||||
|
-- as event. It seems that when BufReadPost is triggered, FileType event is still not run.
|
||||||
|
-- So the filetype for this buffer is empty string.
|
||||||
|
api.nvim_create_autocmd("FileType", {
|
||||||
|
group = api.nvim_create_augroup("resume_cursor_position", { clear = true }),
|
||||||
|
pattern = "*",
|
||||||
|
callback = function(ev)
|
||||||
|
local mark_pos = api.nvim_buf_get_mark(ev.buf, '"')
|
||||||
|
local last_cursor_line = mark_pos[1]
|
||||||
|
|
||||||
|
local max_line = vim.fn.line("$")
|
||||||
|
local buf_filetype = api.nvim_get_option_value("filetype", { buf = ev.buf })
|
||||||
|
local buftype = api.nvim_get_option_value("buftype", { buf = ev.buf })
|
||||||
|
|
||||||
|
-- only handle normal files
|
||||||
|
if buf_filetype == "" or buftype ~= "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Only resume last cursor position when there is no go-to-line command (something like '+23').
|
||||||
|
if vim.fn.match(vim.v.argv, [[\v^\+(\d){1,}$]]) ~= -1 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if last_cursor_line > 1 and last_cursor_line <= max_line then
|
||||||
|
-- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos)))
|
||||||
|
-- it seems that without vim.schedule, the cursor position can not be set correctly
|
||||||
|
vim.schedule(function()
|
||||||
|
local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
|
||||||
|
if not status then
|
||||||
|
api.nvim_err_writeln(
|
||||||
|
string.format("Failed to resume cursor position. Context %s, error: %s", vim.inspect(ev), result)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
-- the following two ways also seem to work,
|
||||||
|
-- ref: https://www.reddit.com/r/neovim/comments/104lc26/how_can_i_press_escape_key_using_lua/
|
||||||
|
-- vim.api.nvim_feedkeys("g`\"", "n", true)
|
||||||
|
-- vim.fn.execute("normal! g`\"")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
local number_toggle_group = api.nvim_create_augroup("numbertoggle", { clear = true })
|
||||||
|
api.nvim_create_autocmd({ "BufEnter", "FocusGained", "InsertLeave", "WinEnter" }, {
|
||||||
|
pattern = "*",
|
||||||
|
group = number_toggle_group,
|
||||||
|
desc = "togger line number",
|
||||||
|
callback = function()
|
||||||
|
if vim.wo.number then
|
||||||
|
vim.wo.relativenumber = true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd({ "BufLeave", "FocusLost", "InsertEnter", "WinLeave" }, {
|
||||||
|
group = number_toggle_group,
|
||||||
|
desc = "togger line number",
|
||||||
|
callback = function()
|
||||||
|
if vim.wo.number then
|
||||||
|
vim.wo.relativenumber = false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("ColorScheme", {
|
||||||
|
group = api.nvim_create_augroup("custom_highlight", { clear = true }),
|
||||||
|
pattern = "*",
|
||||||
|
desc = "Define or overrride some highlight groups",
|
||||||
|
callback = function()
|
||||||
|
-- For yank highlight
|
||||||
|
vim.api.nvim_set_hl(0, "YankColor", { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 })
|
||||||
|
|
||||||
|
-- For cursor colors
|
||||||
|
vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", bold = true })
|
||||||
|
vim.api.nvim_set_hl(0, "Cursor2", { fg = "red", bg = "red" })
|
||||||
|
|
||||||
|
-- For floating windows border highlight
|
||||||
|
vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen" })
|
||||||
|
|
||||||
|
-- highlight for matching parentheses
|
||||||
|
vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true })
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd("BufEnter", {
|
||||||
|
pattern = "*",
|
||||||
|
group = api.nvim_create_augroup("auto_close_win", { clear = true }),
|
||||||
|
desc = "Quit Nvim if we have only one window, and its filetype match our pattern",
|
||||||
|
callback = function(ev)
|
||||||
|
local quit_filetypes = { "qf", "vista", "NvimTree" }
|
||||||
|
|
||||||
|
local should_quit = true
|
||||||
|
local tabwins = api.nvim_tabpage_list_wins(0)
|
||||||
|
|
||||||
|
for _, win in pairs(tabwins) do
|
||||||
|
local buf = api.nvim_win_get_buf(win)
|
||||||
|
local bf = fn.getbufvar(buf, "&filetype")
|
||||||
|
|
||||||
|
if fn.index(quit_filetypes, bf) == -1 then
|
||||||
|
should_quit = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if should_quit then
|
||||||
|
vim.cmd("qall")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, {
|
||||||
|
group = api.nvim_create_augroup("git_repo_check", { clear = true }),
|
||||||
|
pattern = "*",
|
||||||
|
desc = "check if we are inside Git repo",
|
||||||
|
command = "call utils#Inside_git_repo()",
|
||||||
|
})
|
||||||
|
|
||||||
|
-- ref: https://vi.stackexchange.com/a/169/15292
|
||||||
|
api.nvim_create_autocmd("BufReadPre", {
|
||||||
|
group = api.nvim_create_augroup("large_file", { clear = true }),
|
||||||
|
pattern = "*",
|
||||||
|
desc = "check if we are inside Git repo",
|
||||||
|
callback = function(ev)
|
||||||
|
local file_size_limit = 524288 -- 0.5MB
|
||||||
|
local f = ev.file
|
||||||
|
|
||||||
|
if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then
|
||||||
|
vim.o.eventignore = "all"
|
||||||
|
-- turning off relative number helps a lot
|
||||||
|
vim.wo.relativenumber = false
|
||||||
|
|
||||||
|
vim.bo.swapfile = false
|
||||||
|
vim.bo.bufhidden = "unload"
|
||||||
|
vim.bo.undolevels = -1
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
|
|
||||||
local utils = require('utils')
|
local utils = require("utils")
|
||||||
|
|
||||||
-- Inspect something
|
|
||||||
function _G.inspect(item)
|
|
||||||
vim.print(item)
|
|
||||||
end
|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
-- custom variables --
|
-- custom variables --
|
||||||
@@ -25,9 +20,9 @@ vim.g.loaded_ruby_provider = 0 -- Disable ruby provider
|
|||||||
vim.g.loaded_node_provider = 0 -- Disable node provider
|
vim.g.loaded_node_provider = 0 -- Disable node provider
|
||||||
vim.g.did_install_default_menus = 1 -- do not load menu
|
vim.g.did_install_default_menus = 1 -- do not load menu
|
||||||
|
|
||||||
if utils.executable('python3') then
|
if utils.executable("python3") then
|
||||||
if vim.g.is_win then
|
if vim.g.is_win then
|
||||||
vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", '', 'g')
|
vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", "", "g")
|
||||||
else
|
else
|
||||||
vim.g.python3_host_prog = fn.exepath("python3")
|
vim.g.python3_host_prog = fn.exepath("python3")
|
||||||
end
|
end
|
||||||
@@ -37,13 +32,13 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Custom mapping <leader> (see `:h mapleader` for more info)
|
-- Custom mapping <leader> (see `:h mapleader` for more info)
|
||||||
vim.g.mapleader = ','
|
vim.g.mapleader = ","
|
||||||
|
|
||||||
-- Enable highlighting for lua HERE doc inside vim script
|
-- Enable highlighting for lua HERE doc inside vim script
|
||||||
vim.g.vimsyn_embed = 'l'
|
vim.g.vimsyn_embed = "l"
|
||||||
|
|
||||||
-- Use English as main language
|
-- Use English as main language
|
||||||
vim.cmd [[language en_US.UTF-8]]
|
vim.cmd([[language en_US.UTF-8]])
|
||||||
|
|
||||||
-- Disable loading certain plugins
|
-- Disable loading certain plugins
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
local api = vim.api
|
local uv = vim.uv
|
||||||
local uv = vim.loop
|
|
||||||
|
|
||||||
-- Save key strokes (now we do not need to press shift to enter command mode).
|
-- Save key strokes (now we do not need to press shift to enter command mode).
|
||||||
keymap.set({ "n", "x" }, ";", ":")
|
keymap.set({ "n", "x" }, ";", ":")
|
||||||
@@ -46,7 +45,21 @@ keymap.set("n", [[\x]], "<cmd>windo lclose <bar> cclose <cr>", {
|
|||||||
-- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933
|
-- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933
|
||||||
keymap.set("n", [[\d]], "<cmd>bprevious <bar> bdelete #<cr>", {
|
keymap.set("n", [[\d]], "<cmd>bprevious <bar> bdelete #<cr>", {
|
||||||
silent = true,
|
silent = true,
|
||||||
desc = "delete buffer",
|
desc = "delete current buffer",
|
||||||
|
})
|
||||||
|
|
||||||
|
keymap.set("n", [[\D]], function()
|
||||||
|
local buf_ids = vim.api.nvim_list_bufs()
|
||||||
|
local cur_buf = vim.api.nvim_win_get_buf(0)
|
||||||
|
|
||||||
|
for _, buf_id in pairs(buf_ids) do
|
||||||
|
-- do not Delete unlisted buffers, which may lead to unexpected errors
|
||||||
|
if vim.api.nvim_get_option_value("buflisted", { buf = buf_id }) and buf_id ~= cur_buf then
|
||||||
|
vim.api.nvim_buf_delete(buf_id, { force = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, {
|
||||||
|
desc = "delete other buffers",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Insert a blank line below or above current line (do not move the cursor),
|
-- Insert a blank line below or above current line (do not move the cursor),
|
||||||
@@ -170,7 +183,7 @@ keymap.set("n", "<Down>", "<C-W>j")
|
|||||||
keymap.set({ "x", "o" }, "iu", "<cmd>call text_obj#URL()<cr>", { desc = "URL text object" })
|
keymap.set({ "x", "o" }, "iu", "<cmd>call text_obj#URL()<cr>", { desc = "URL text object" })
|
||||||
|
|
||||||
-- Text objects for entire buffer
|
-- Text objects for entire buffer
|
||||||
keymap.set({ "x", "o" }, "iB", "<cmd>call text_obj#Buffer()<cr>", { desc = "buffer text object" })
|
keymap.set({ "x", "o" }, "iB", ":<C-U>call text_obj#Buffer()<cr>", { desc = "buffer text object" })
|
||||||
|
|
||||||
-- Do not move my cursor when joining lines.
|
-- Do not move my cursor when joining lines.
|
||||||
keymap.set("n", "J", function()
|
keymap.set("n", "J", function()
|
||||||
@@ -179,17 +192,17 @@ keymap.set("n", "J", function()
|
|||||||
delmarks z
|
delmarks z
|
||||||
]])
|
]])
|
||||||
end, {
|
end, {
|
||||||
desc = "join line",
|
desc = "join lines without moving cursor",
|
||||||
})
|
})
|
||||||
|
|
||||||
keymap.set("n", "gJ", function()
|
keymap.set("n", "gJ", function()
|
||||||
-- we must use `normal!`, otherwise it will trigger recursive mapping
|
-- we must use `normal!`, otherwise it will trigger recursive mapping
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
normal! zmgJ`z
|
normal! mzgJ`z
|
||||||
delmarks z
|
delmarks z
|
||||||
]])
|
]])
|
||||||
end, {
|
end, {
|
||||||
desc = "join visual lines",
|
desc = "join lines without moving cursor",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Break inserted text into smaller undo units when we insert some punctuation chars.
|
-- Break inserted text into smaller undo units when we insert some punctuation chars.
|
||||||
@@ -201,20 +214,6 @@ end
|
|||||||
-- insert semicolon in the end
|
-- insert semicolon in the end
|
||||||
keymap.set("i", "<A-;>", "<Esc>miA;<Esc>`ii")
|
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
|
-- Go to the beginning and end of current line in insert mode quickly
|
||||||
keymap.set("i", "<C-A>", "<HOME>")
|
keymap.set("i", "<C-A>", "<HOME>")
|
||||||
keymap.set("i", "<C-E>", "<END>")
|
keymap.set("i", "<C-E>", "<END>")
|
||||||
@@ -229,17 +228,24 @@ keymap.set("n", "<leader>cb", function()
|
|||||||
local cnt = 0
|
local cnt = 0
|
||||||
local blink_times = 7
|
local blink_times = 7
|
||||||
local timer = uv.new_timer()
|
local timer = uv.new_timer()
|
||||||
|
if timer == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
timer:start(0, 100, vim.schedule_wrap(function()
|
timer:start(
|
||||||
vim.cmd[[
|
0,
|
||||||
|
100,
|
||||||
|
vim.schedule_wrap(function()
|
||||||
|
vim.cmd([[
|
||||||
set cursorcolumn!
|
set cursorcolumn!
|
||||||
set cursorline!
|
set cursorline!
|
||||||
]]
|
]])
|
||||||
|
|
||||||
if cnt == blink_times then
|
if cnt == blink_times then
|
||||||
timer:close()
|
timer:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
end))
|
end)
|
||||||
end)
|
)
|
||||||
|
end, { desc = "show cursor" })
|
||||||
|
|||||||
604
lua/plugin_specs.lua
Normal file
604
lua/plugin_specs.lua
Normal file
@@ -0,0 +1,604 @@
|
|||||||
|
local utils = require("utils")
|
||||||
|
|
||||||
|
local plugin_dir = vim.fn.stdpath("data") .. "/lazy"
|
||||||
|
local lazypath = plugin_dir .. "/lazy.nvim"
|
||||||
|
|
||||||
|
if not vim.uv.fs_stat(lazypath) then
|
||||||
|
vim.fn.system {
|
||||||
|
"git",
|
||||||
|
"clone",
|
||||||
|
"--filter=blob:none",
|
||||||
|
"https://github.com/folke/lazy.nvim.git",
|
||||||
|
"--branch=stable", -- latest stable release
|
||||||
|
lazypath,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
vim.opt.rtp:prepend(lazypath)
|
||||||
|
|
||||||
|
-- check if firenvim is active
|
||||||
|
local firenvim_not_active = function()
|
||||||
|
return not vim.g.started_by_firenvim
|
||||||
|
end
|
||||||
|
|
||||||
|
local plugin_specs = {
|
||||||
|
-- auto-completion engine
|
||||||
|
{
|
||||||
|
"iguanacucumber/magazine.nvim",
|
||||||
|
name = "nvim-cmp",
|
||||||
|
-- event = 'InsertEnter',
|
||||||
|
event = "VeryLazy",
|
||||||
|
dependencies = {
|
||||||
|
"hrsh7th/cmp-nvim-lsp",
|
||||||
|
"onsails/lspkind-nvim",
|
||||||
|
"hrsh7th/cmp-path",
|
||||||
|
"hrsh7th/cmp-buffer",
|
||||||
|
"hrsh7th/cmp-omni",
|
||||||
|
"quangnguyen30192/cmp-nvim-ultisnips",
|
||||||
|
},
|
||||||
|
config = function()
|
||||||
|
require("config.nvim-cmp")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"neovim/nvim-lspconfig",
|
||||||
|
event = { "BufRead", "BufNewFile" },
|
||||||
|
config = function()
|
||||||
|
require("config.lsp")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"nvim-treesitter/nvim-treesitter",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_mac then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
event = "VeryLazy",
|
||||||
|
build = ":TSUpdate",
|
||||||
|
config = function()
|
||||||
|
require("config.treesitter")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Python-related text object
|
||||||
|
{ "jeetsukumaran/vim-pythonsense", ft = { "python" } },
|
||||||
|
|
||||||
|
{ "machakann/vim-swap", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- IDE for Lisp
|
||||||
|
-- 'kovisoft/slimv'
|
||||||
|
{
|
||||||
|
"vlime/vlime",
|
||||||
|
enabled = function()
|
||||||
|
if utils.executable("sbcl") then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
config = function(plugin)
|
||||||
|
vim.opt.rtp:append(plugin.dir .. "/vim")
|
||||||
|
end,
|
||||||
|
ft = { "lisp" },
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Super fast buffer jump
|
||||||
|
{
|
||||||
|
"smoka7/hop.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
config = function()
|
||||||
|
require("config.nvim_hop")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Show match number and index for searching
|
||||||
|
{
|
||||||
|
"kevinhwang91/nvim-hlslens",
|
||||||
|
branch = "main",
|
||||||
|
keys = { "*", "#", "n", "N" },
|
||||||
|
config = function()
|
||||||
|
require("config.hlslens")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Yggdroot/LeaderF",
|
||||||
|
cmd = "Leaderf",
|
||||||
|
build = function()
|
||||||
|
local leaderf_path = plugin_dir .. "/LeaderF"
|
||||||
|
vim.opt.runtimepath:append(leaderf_path)
|
||||||
|
vim.cmd("runtime! plugin/leaderf.vim")
|
||||||
|
|
||||||
|
if not vim.g.is_win then
|
||||||
|
vim.cmd("LeaderfInstallCExtension")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
"nvim-lua/plenary.nvim",
|
||||||
|
{
|
||||||
|
"nvim-telescope/telescope.nvim",
|
||||||
|
cmd = "Telescope",
|
||||||
|
dependencies = {
|
||||||
|
"nvim-telescope/telescope-symbols.nvim",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ibhagwan/fzf-lua",
|
||||||
|
-- optional for icon support
|
||||||
|
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||||
|
config = function()
|
||||||
|
-- calling `setup` is optional for customization
|
||||||
|
require("fzf-lua").setup {}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"MeanderingProgrammer/markdown.nvim",
|
||||||
|
main = "render-markdown",
|
||||||
|
opts = {},
|
||||||
|
dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" },
|
||||||
|
},
|
||||||
|
-- A list of colorscheme plugin you may want to try. Find what suits you.
|
||||||
|
{ "navarasu/onedark.nvim", lazy = true },
|
||||||
|
{ "sainnhe/edge", lazy = true },
|
||||||
|
{ "sainnhe/sonokai", lazy = true },
|
||||||
|
{ "sainnhe/gruvbox-material", lazy = true },
|
||||||
|
{ "sainnhe/everforest", lazy = true },
|
||||||
|
{ "EdenEast/nightfox.nvim", lazy = true },
|
||||||
|
{ "catppuccin/nvim", name = "catppuccin", lazy = true },
|
||||||
|
{ "olimorris/onedarkpro.nvim", lazy = true },
|
||||||
|
{ "marko-cerovac/material.nvim", lazy = true },
|
||||||
|
{
|
||||||
|
"rockyzhang24/arctic.nvim",
|
||||||
|
dependencies = { "rktjmp/lush.nvim" },
|
||||||
|
name = "arctic",
|
||||||
|
branch = "v2",
|
||||||
|
},
|
||||||
|
{ "rebelot/kanagawa.nvim", lazy = true },
|
||||||
|
{ "nvim-tree/nvim-web-devicons", event = "VeryLazy" },
|
||||||
|
|
||||||
|
{
|
||||||
|
"nvim-lualine/lualine.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
cond = firenvim_not_active,
|
||||||
|
config = function()
|
||||||
|
require("config.lualine")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"akinsho/bufferline.nvim",
|
||||||
|
event = { "BufEnter" },
|
||||||
|
cond = firenvim_not_active,
|
||||||
|
config = function()
|
||||||
|
require("config.bufferline")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- fancy start screen
|
||||||
|
{
|
||||||
|
"nvimdev/dashboard-nvim",
|
||||||
|
cond = firenvim_not_active,
|
||||||
|
config = function()
|
||||||
|
require("config.dashboard-nvim")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"lukas-reineke/indent-blankline.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
main = "ibl",
|
||||||
|
config = function()
|
||||||
|
require("config.indent-blankline")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"luukvbaal/statuscol.nvim",
|
||||||
|
opts = {},
|
||||||
|
config = function()
|
||||||
|
require("config.nvim-statuscol")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kevinhwang91/nvim-ufo",
|
||||||
|
dependencies = "kevinhwang91/promise-async",
|
||||||
|
event = "VeryLazy",
|
||||||
|
opts = {},
|
||||||
|
init = function()
|
||||||
|
vim.o.foldcolumn = "1" -- '0' is not bad
|
||||||
|
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
|
||||||
|
vim.o.foldlevelstart = 99
|
||||||
|
vim.o.foldenable = true
|
||||||
|
end,
|
||||||
|
config = function()
|
||||||
|
require("config.nvim_ufo")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- Highlight URLs inside vim
|
||||||
|
{ "itchyny/vim-highlighturl", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- notification plugin
|
||||||
|
{
|
||||||
|
"rcarriga/nvim-notify",
|
||||||
|
event = "VeryLazy",
|
||||||
|
config = function()
|
||||||
|
require("config.nvim-notify")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- 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.
|
||||||
|
{
|
||||||
|
"chrishrb/gx.nvim",
|
||||||
|
keys = { { "gx", "<cmd>Browse<cr>", mode = { "n", "x" } } },
|
||||||
|
cmd = { "Browse" },
|
||||||
|
init = function()
|
||||||
|
vim.g.netrw_nogx = 1 -- disable netrw gx
|
||||||
|
end,
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_win or vim.g.is_mac then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
dependencies = { "nvim-lua/plenary.nvim" },
|
||||||
|
config = true, -- default settings
|
||||||
|
submodules = false, -- not needed, submodules are required only for tests
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Only install these plugins if ctags are installed on the system
|
||||||
|
-- show file tags in vim window
|
||||||
|
{
|
||||||
|
"liuchengxu/vista.vim",
|
||||||
|
enabled = function()
|
||||||
|
if utils.executable("ctags") then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
cmd = "Vista",
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Snippet engine and snippet template
|
||||||
|
{ "SirVer/ultisnips", dependencies = {
|
||||||
|
"honza/vim-snippets",
|
||||||
|
}, event = "InsertEnter" },
|
||||||
|
|
||||||
|
-- Automatic insertion and deletion of a pair of characters
|
||||||
|
{
|
||||||
|
"windwp/nvim-autopairs",
|
||||||
|
event = "InsertEnter",
|
||||||
|
config = true,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Comment plugin
|
||||||
|
{ "tpope/vim-commentary", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- Multiple cursor plugin like Sublime Text?
|
||||||
|
-- 'mg979/vim-visual-multi'
|
||||||
|
|
||||||
|
-- Autosave files on certain events
|
||||||
|
{ "907th/vim-auto-save", event = "InsertEnter" },
|
||||||
|
|
||||||
|
-- Show undo history visually
|
||||||
|
{ "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } },
|
||||||
|
|
||||||
|
-- better UI for some nvim actions
|
||||||
|
{ "stevearc/dressing.nvim" },
|
||||||
|
|
||||||
|
-- Manage your yank history
|
||||||
|
{
|
||||||
|
"gbprod/yanky.nvim",
|
||||||
|
config = function()
|
||||||
|
require("config.yanky")
|
||||||
|
end,
|
||||||
|
event = "VeryLazy",
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Handy unix command inside Vim (Rename, Move etc.)
|
||||||
|
{ "tpope/vim-eunuch", cmd = { "Rename", "Delete" } },
|
||||||
|
|
||||||
|
-- Repeat vim motions
|
||||||
|
{ "tpope/vim-repeat", event = "VeryLazy" },
|
||||||
|
|
||||||
|
{ "nvim-zh/better-escape.vim", event = { "InsertEnter" } },
|
||||||
|
|
||||||
|
{
|
||||||
|
"lyokha/vim-xkbswitch",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_mac and utils.executable("xkbswitch") then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
event = { "InsertEnter" },
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"Neur1n/neuims",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_win then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
event = { "InsertEnter" },
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Auto format tools
|
||||||
|
{ "sbdchd/neoformat", cmd = { "Neoformat" } },
|
||||||
|
|
||||||
|
-- Git command inside vim
|
||||||
|
{
|
||||||
|
"tpope/vim-fugitive",
|
||||||
|
event = "User InGitRepo",
|
||||||
|
config = function()
|
||||||
|
require("config.fugitive")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Better git log display
|
||||||
|
{ "rbong/vim-flog", cmd = { "Flog" } },
|
||||||
|
{ "akinsho/git-conflict.nvim", version = "*", config = true },
|
||||||
|
{
|
||||||
|
"ruifm/gitlinker.nvim",
|
||||||
|
event = "User InGitRepo",
|
||||||
|
config = function()
|
||||||
|
require("config.git-linker")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Show git change (change, delete, add) signs in vim sign column
|
||||||
|
{
|
||||||
|
"lewis6991/gitsigns.nvim",
|
||||||
|
config = function()
|
||||||
|
require("config.gitsigns")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"sindrets/diffview.nvim",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"kevinhwang91/nvim-bqf",
|
||||||
|
ft = "qf",
|
||||||
|
config = function()
|
||||||
|
require("config.bqf")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Another markdown plugin
|
||||||
|
{ "preservim/vim-markdown", ft = { "markdown" } },
|
||||||
|
|
||||||
|
-- Faster footnote generation
|
||||||
|
{ "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } },
|
||||||
|
|
||||||
|
-- Vim tabular plugin for manipulate tabular, required by markdown plugins
|
||||||
|
{ "godlygeek/tabular", cmd = { "Tabularize" } },
|
||||||
|
|
||||||
|
-- Markdown previewing (only for Mac and Windows)
|
||||||
|
{
|
||||||
|
"iamcco/markdown-preview.nvim",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_win or vim.g.is_mac then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
build = "cd app && npm install",
|
||||||
|
ft = { "markdown" },
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"rhysd/vim-grammarous",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_mac then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
ft = { "markdown" },
|
||||||
|
},
|
||||||
|
|
||||||
|
{ "chrisbra/unicode.vim", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- Additional powerful text object for vim, this plugin should be studied
|
||||||
|
-- carefully to use its full power
|
||||||
|
{ "wellle/targets.vim", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- Plugin to manipulate character pairs quickly
|
||||||
|
{ "machakann/vim-sandwich", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- Add indent object for vim (useful for languages like Python)
|
||||||
|
{ "michaeljsmith/vim-indent-object", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- Only use these plugin on Windows and Mac and when LaTeX is installed
|
||||||
|
{
|
||||||
|
"lervag/vimtex",
|
||||||
|
enabled = function()
|
||||||
|
if utils.executable("latex") then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
ft = { "tex" },
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Since tmux is only available on Linux and Mac, we only enable these plugins
|
||||||
|
-- for Linux and Mac
|
||||||
|
-- .tmux.conf syntax highlighting and setting check
|
||||||
|
{
|
||||||
|
"tmux-plugins/vim-tmux",
|
||||||
|
enabled = function()
|
||||||
|
if utils.executable("tmux") then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
ft = { "tmux" },
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Modern matchit implementation
|
||||||
|
{ "andymass/vim-matchup", event = "BufRead" },
|
||||||
|
{ "tpope/vim-scriptease", cmd = { "Scriptnames", "Messages", "Verbose" } },
|
||||||
|
|
||||||
|
-- Asynchronous command execution
|
||||||
|
{ "skywind3000/asyncrun.vim", lazy = true, cmd = { "AsyncRun" } },
|
||||||
|
{ "cespare/vim-toml", ft = { "toml" }, branch = "main" },
|
||||||
|
|
||||||
|
-- Edit text area in browser using nvim
|
||||||
|
{
|
||||||
|
"glacambre/firenvim",
|
||||||
|
enabled = function()
|
||||||
|
local result = vim.g.is_win or vim.g.is_mac
|
||||||
|
return result
|
||||||
|
end,
|
||||||
|
-- it seems that we can only call the firenvim function directly.
|
||||||
|
-- Using vim.fn or vim.cmd to call this function will fail.
|
||||||
|
build = function()
|
||||||
|
local firenvim_path = plugin_dir .. "/firenvim"
|
||||||
|
vim.opt.runtimepath:append(firenvim_path)
|
||||||
|
vim.cmd("runtime! firenvim.vim")
|
||||||
|
|
||||||
|
-- macOS will reset the PATH when firenvim starts a nvim process, causing the PATH variable to change unexpectedly.
|
||||||
|
-- Here we are trying to get the correct PATH and use it for firenvim.
|
||||||
|
-- See also https://github.com/glacambre/firenvim/blob/master/TROUBLESHOOTING.md#make-sure-firenvims-path-is-the-same-as-neovims
|
||||||
|
local path_env = vim.env.PATH
|
||||||
|
local prologue = string.format('export PATH="%s"', path_env)
|
||||||
|
-- local prologue = "echo"
|
||||||
|
local cmd_str = string.format(":call firenvim#install(0, '%s')", prologue)
|
||||||
|
vim.cmd(cmd_str)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
-- Debugger plugin
|
||||||
|
{
|
||||||
|
"sakhnik/nvim-gdb",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_win or vim.g.is_linux then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
build = { "bash install.sh" },
|
||||||
|
lazy = true,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Session management plugin
|
||||||
|
{ "tpope/vim-obsession", cmd = "Obsession" },
|
||||||
|
|
||||||
|
{
|
||||||
|
"ojroques/vim-oscyank",
|
||||||
|
enabled = function()
|
||||||
|
if vim.g.is_linux then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end,
|
||||||
|
cmd = { "OSCYank", "OSCYankReg" },
|
||||||
|
},
|
||||||
|
|
||||||
|
-- The missing auto-completion for cmdline!
|
||||||
|
{
|
||||||
|
"gelguy/wilder.nvim",
|
||||||
|
build = ":UpdateRemotePlugins",
|
||||||
|
},
|
||||||
|
|
||||||
|
-- showing keybindings
|
||||||
|
{
|
||||||
|
"folke/which-key.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
config = function()
|
||||||
|
require("config.which-key")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- show and trim trailing whitespaces
|
||||||
|
{ "jdhao/whitespace.nvim", event = "VeryLazy" },
|
||||||
|
|
||||||
|
-- file explorer
|
||||||
|
{
|
||||||
|
"nvim-tree/nvim-tree.lua",
|
||||||
|
event = "VeryLazy",
|
||||||
|
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||||
|
config = function()
|
||||||
|
require("config.nvim-tree")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"j-hui/fidget.nvim",
|
||||||
|
event = "VeryLazy",
|
||||||
|
tag = "legacy",
|
||||||
|
config = function()
|
||||||
|
require("config.fidget-nvim")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"folke/lazydev.nvim",
|
||||||
|
ft = "lua", -- only load on lua files
|
||||||
|
opts = {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"CopilotC-Nvim/CopilotChat.nvim",
|
||||||
|
dependencies = {
|
||||||
|
{ "zbirenbaum/copilot.lua" }, -- or github/copilot.vim
|
||||||
|
{ "nvim-lua/plenary.nvim" }, -- for curl, log wrapper
|
||||||
|
},
|
||||||
|
opts = {
|
||||||
|
debug = true, -- Enable debugging
|
||||||
|
-- See Configuration section for rest
|
||||||
|
},
|
||||||
|
-- See Commands section for default commands if you want to lazy load on them
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"zbirenbaum/copilot.lua",
|
||||||
|
cmd = "Copilot",
|
||||||
|
config = function()
|
||||||
|
require("copilot").setup {}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"smjonas/live-command.nvim",
|
||||||
|
-- live-command supports semantic versioning via Git tags
|
||||||
|
-- tag = "2.*",
|
||||||
|
cmd = "Preview",
|
||||||
|
config = function()
|
||||||
|
require("config.live-command")
|
||||||
|
end,
|
||||||
|
event = "VeryLazy",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
-- show hint for code actions, the user can also implement code actions themselves,
|
||||||
|
-- see discussion here: https://github.com/neovim/neovim/issues/14869
|
||||||
|
"kosayoda/nvim-lightbulb",
|
||||||
|
config = function()
|
||||||
|
require("nvim-lightbulb").setup { autocmd = { enabled = true } }
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Bekaboo/dropbar.nvim",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"vhyrro/luarocks.nvim",
|
||||||
|
priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config.
|
||||||
|
opts = {
|
||||||
|
rocks = { "lua-toml" }, -- specifies a list of rocks to install
|
||||||
|
-- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
require("lazy").setup {
|
||||||
|
spec = plugin_specs,
|
||||||
|
ui = {
|
||||||
|
border = "rounded",
|
||||||
|
title = "Plugin Manager",
|
||||||
|
title_pos = "center",
|
||||||
|
},
|
||||||
|
rocks = {
|
||||||
|
enabled = false,
|
||||||
|
hererocks = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
396
lua/plugins.lua
396
lua/plugins.lua
@@ -1,396 +0,0 @@
|
|||||||
local api = vim.api
|
|
||||||
local fn = vim.fn
|
|
||||||
|
|
||||||
local utils = require("utils")
|
|
||||||
|
|
||||||
-- 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"
|
|
||||||
|
|
||||||
--- Install packer if it has not been installed.
|
|
||||||
--- Return:
|
|
||||||
--- true: if this is a fresh install of packer
|
|
||||||
--- false: if packer has been installed
|
|
||||||
local function packer_ensure_install()
|
|
||||||
-- Where to install packer.nvim -- the package manager (we make it opt)
|
|
||||||
local packer_dir = vim.g.plugin_home .. "/opt/packer.nvim"
|
|
||||||
|
|
||||||
if fn.glob(packer_dir) ~= "" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Auto-install packer in case it hasn't been installed.
|
|
||||||
vim.api.nvim_echo({ { "Installing packer.nvim", "Type" } }, true, {})
|
|
||||||
|
|
||||||
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.cmd(install_cmd)
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local fresh_install = packer_ensure_install()
|
|
||||||
|
|
||||||
-- Load packer.nvim
|
|
||||||
vim.cmd("packadd packer.nvim")
|
|
||||||
|
|
||||||
local packer = require("packer")
|
|
||||||
local packer_util = require("packer.util")
|
|
||||||
|
|
||||||
-- check if firenvim is active
|
|
||||||
local firenvim_not_active = function()
|
|
||||||
return not vim.g.started_by_firenvim
|
|
||||||
end
|
|
||||||
|
|
||||||
packer.startup {
|
|
||||||
function(use)
|
|
||||||
use { "wbthomason/packer.nvim", opt = true }
|
|
||||||
|
|
||||||
use { "onsails/lspkind-nvim", event = "VimEnter" }
|
|
||||||
-- auto-completion engine
|
|
||||||
use { "hrsh7th/nvim-cmp", after = "lspkind-nvim", config = [[require('config.nvim-cmp')]] }
|
|
||||||
|
|
||||||
-- nvim-cmp completion sources
|
|
||||||
use { "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" }
|
|
||||||
use { "hrsh7th/cmp-path", after = "nvim-cmp" }
|
|
||||||
use { "hrsh7th/cmp-buffer", after = "nvim-cmp" }
|
|
||||||
use { "hrsh7th/cmp-omni", after = "nvim-cmp" }
|
|
||||||
use { "quangnguyen30192/cmp-nvim-ultisnips", after = { "nvim-cmp", "ultisnips" } }
|
|
||||||
if vim.g.is_mac then
|
|
||||||
use { "hrsh7th/cmp-emoji", after = "nvim-cmp" }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 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')]] }
|
|
||||||
|
|
||||||
if vim.g.is_mac then
|
|
||||||
use {
|
|
||||||
"nvim-treesitter/nvim-treesitter",
|
|
||||||
event = "BufEnter",
|
|
||||||
run = ":TSUpdate",
|
|
||||||
config = [[require('config.treesitter')]],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Python indent (follows the PEP8 style)
|
|
||||||
use { "Vimjas/vim-python-pep8-indent", ft = { "python" } }
|
|
||||||
|
|
||||||
-- Python-related text object
|
|
||||||
use { "jeetsukumaran/vim-pythonsense", ft = { "python" } }
|
|
||||||
|
|
||||||
use { "machakann/vim-swap", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- IDE for Lisp
|
|
||||||
if utils.executable("sbcl") then
|
|
||||||
-- use 'kovisoft/slimv'
|
|
||||||
use { "vlime/vlime", rtp = "vim/", ft = { "lisp" } }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Super fast buffer jump
|
|
||||||
use {
|
|
||||||
"phaazon/hop.nvim",
|
|
||||||
event = "VimEnter",
|
|
||||||
config = function()
|
|
||||||
vim.defer_fn(function()
|
|
||||||
require("config.nvim_hop")
|
|
||||||
end, 2000)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Show match number and index for searching
|
|
||||||
use {
|
|
||||||
"kevinhwang91/nvim-hlslens",
|
|
||||||
branch = "main",
|
|
||||||
keys = { { "n", "*" }, { "n", "#" }, { "n", "n" }, { "n", "N" } },
|
|
||||||
config = [[require('config.hlslens')]],
|
|
||||||
}
|
|
||||||
|
|
||||||
-- File search, tag search and more
|
|
||||||
if vim.g.is_win then
|
|
||||||
use { "Yggdroot/LeaderF", cmd = "Leaderf" }
|
|
||||||
else
|
|
||||||
use { "Yggdroot/LeaderF", cmd = "Leaderf", run = ":LeaderfInstallCExtension" }
|
|
||||||
end
|
|
||||||
|
|
||||||
use {
|
|
||||||
"nvim-telescope/telescope.nvim",
|
|
||||||
cmd = "Telescope",
|
|
||||||
requires = { { "nvim-lua/plenary.nvim" } },
|
|
||||||
}
|
|
||||||
-- search emoji and other symbols
|
|
||||||
use { "nvim-telescope/telescope-symbols.nvim", after = "telescope.nvim" }
|
|
||||||
|
|
||||||
-- A list of colorscheme plugin you may want to try. Find what suits you.
|
|
||||||
use { "navarasu/onedark.nvim", opt = true }
|
|
||||||
use { "sainnhe/edge", opt = true }
|
|
||||||
use { "sainnhe/sonokai", opt = true }
|
|
||||||
use { "sainnhe/gruvbox-material", opt = true }
|
|
||||||
use { "shaunsingh/nord.nvim", opt = true }
|
|
||||||
use { "sainnhe/everforest", opt = true }
|
|
||||||
use { "EdenEast/nightfox.nvim", opt = true }
|
|
||||||
use { "rebelot/kanagawa.nvim", opt = true }
|
|
||||||
use { "catppuccin/nvim", as = "catppuccin", opt = true }
|
|
||||||
use({ "rose-pine/neovim", as = 'rose-pine', opt = true })
|
|
||||||
use { "olimorris/onedarkpro.nvim", opt = true }
|
|
||||||
use { "tanvirtin/monokai.nvim", opt = true }
|
|
||||||
use { "marko-cerovac/material.nvim", opt = true }
|
|
||||||
|
|
||||||
use { "nvim-tree/nvim-web-devicons", event = "VimEnter" }
|
|
||||||
|
|
||||||
use {
|
|
||||||
"nvim-lualine/lualine.nvim",
|
|
||||||
event = "VimEnter",
|
|
||||||
cond = firenvim_not_active,
|
|
||||||
config = [[require('config.statusline')]],
|
|
||||||
}
|
|
||||||
|
|
||||||
use { "akinsho/bufferline.nvim", event = "VimEnter",
|
|
||||||
cond = firenvim_not_active,
|
|
||||||
config = [[require('config.bufferline')]] }
|
|
||||||
|
|
||||||
-- fancy start screen
|
|
||||||
use { "nvimdev/dashboard-nvim", event = "VimEnter",
|
|
||||||
cond = firenvim_not_active,
|
|
||||||
config = [[require('config.dashboard-nvim')]]
|
|
||||||
}
|
|
||||||
|
|
||||||
use {
|
|
||||||
"lukas-reineke/indent-blankline.nvim",
|
|
||||||
event = "VimEnter",
|
|
||||||
config = [[require('config.indent-blankline')]],
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Highlight URLs inside vim
|
|
||||||
use { "itchyny/vim-highlighturl", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- notification plugin
|
|
||||||
use {
|
|
||||||
"rcarriga/nvim-notify",
|
|
||||||
event = "BufEnter",
|
|
||||||
config = function()
|
|
||||||
vim.defer_fn(function()
|
|
||||||
require("config.nvim-notify")
|
|
||||||
end, 2000)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- 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.
|
|
||||||
if vim.g.is_win or vim.g.is_mac then
|
|
||||||
-- open URL in browser
|
|
||||||
use { "tyru/open-browser.vim", event = "VimEnter" }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Only install these plugins if ctags are installed on the system
|
|
||||||
if utils.executable("ctags") then
|
|
||||||
-- show file tags in vim window
|
|
||||||
use { "liuchengxu/vista.vim", cmd = "Vista" }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Snippet engine and snippet template
|
|
||||||
use { "SirVer/ultisnips", event = "InsertEnter" }
|
|
||||||
use { "honza/vim-snippets", after = "ultisnips" }
|
|
||||||
|
|
||||||
-- Automatic insertion and deletion of a pair of characters
|
|
||||||
use { "Raimondi/delimitMate", event = "InsertEnter" }
|
|
||||||
|
|
||||||
-- Comment plugin
|
|
||||||
use { "tpope/vim-commentary", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- Multiple cursor plugin like Sublime Text?
|
|
||||||
-- use 'mg979/vim-visual-multi'
|
|
||||||
|
|
||||||
-- Autosave files on certain events
|
|
||||||
use { "907th/vim-auto-save", event = "InsertEnter" }
|
|
||||||
|
|
||||||
-- Show undo history visually
|
|
||||||
use { "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } }
|
|
||||||
|
|
||||||
-- better UI for some nvim actions
|
|
||||||
use {'stevearc/dressing.nvim'}
|
|
||||||
|
|
||||||
-- Manage your yank history
|
|
||||||
use({
|
|
||||||
"gbprod/yanky.nvim",
|
|
||||||
config = [[require('config.yanky')]]
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Handy unix command inside Vim (Rename, Move etc.)
|
|
||||||
use { "tpope/vim-eunuch", cmd = { "Rename", "Delete" } }
|
|
||||||
|
|
||||||
-- Repeat vim motions
|
|
||||||
use { "tpope/vim-repeat", event = "VimEnter" }
|
|
||||||
|
|
||||||
use { "nvim-zh/better-escape.vim", event = { "InsertEnter" } }
|
|
||||||
|
|
||||||
if vim.g.is_mac then
|
|
||||||
use { "lyokha/vim-xkbswitch", event = { "InsertEnter" } }
|
|
||||||
elseif vim.g.is_win then
|
|
||||||
use { "Neur1n/neuims", event = { "InsertEnter" } }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Auto format tools
|
|
||||||
use { "sbdchd/neoformat", cmd = { "Neoformat" } }
|
|
||||||
|
|
||||||
-- Git command inside vim
|
|
||||||
use { "tpope/vim-fugitive", event = "User InGitRepo", config = [[require('config.fugitive')]] }
|
|
||||||
|
|
||||||
-- Better git log display
|
|
||||||
use { "rbong/vim-flog", requires = "tpope/vim-fugitive", cmd = { "Flog" } }
|
|
||||||
|
|
||||||
use { "christoomey/vim-conflicted", requires = "tpope/vim-fugitive", cmd = { "Conflicted" } }
|
|
||||||
|
|
||||||
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
|
|
||||||
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
|
|
||||||
use { "preservim/vim-markdown", ft = { "markdown" } }
|
|
||||||
|
|
||||||
-- Faster footnote generation
|
|
||||||
use { "vim-pandoc/vim-markdownfootnotes", ft = { "markdown" } }
|
|
||||||
|
|
||||||
-- Vim tabular plugin for manipulate tabular, required by markdown plugins
|
|
||||||
use { "godlygeek/tabular", cmd = { "Tabularize" } }
|
|
||||||
|
|
||||||
-- Markdown previewing (only for Mac and Windows)
|
|
||||||
if vim.g.is_win or vim.g.is_mac then
|
|
||||||
use {
|
|
||||||
"iamcco/markdown-preview.nvim",
|
|
||||||
run = "cd app && npm install",
|
|
||||||
ft = { "markdown" },
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
use { "folke/zen-mode.nvim", cmd = "ZenMode", config = [[require('config.zen-mode')]] }
|
|
||||||
|
|
||||||
if vim.g.is_mac then
|
|
||||||
use { "rhysd/vim-grammarous", ft = { "markdown" } }
|
|
||||||
end
|
|
||||||
|
|
||||||
use { "chrisbra/unicode.vim", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- Additional powerful text object for vim, this plugin should be studied
|
|
||||||
-- carefully to use its full power
|
|
||||||
use { "wellle/targets.vim", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- Plugin to manipulate character pairs quickly
|
|
||||||
use { "machakann/vim-sandwich", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- Add indent object for vim (useful for languages like Python)
|
|
||||||
use { "michaeljsmith/vim-indent-object", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- Only use these plugin on Windows and Mac and when LaTeX is installed
|
|
||||||
if utils.executable("latex") then
|
|
||||||
use { "lervag/vimtex", ft = { "tex" } }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Since tmux is only available on Linux and Mac, we only enable these plugins
|
|
||||||
-- for Linux and Mac
|
|
||||||
if utils.executable("tmux") then
|
|
||||||
-- .tmux.conf syntax highlighting and setting check
|
|
||||||
use { "tmux-plugins/vim-tmux", ft = { "tmux" } }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Modern matchit implementation
|
|
||||||
use { "andymass/vim-matchup", event = "VimEnter" }
|
|
||||||
|
|
||||||
use { "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } }
|
|
||||||
|
|
||||||
-- Asynchronous command execution
|
|
||||||
use { "skywind3000/asyncrun.vim", opt = true, cmd = { "AsyncRun" } }
|
|
||||||
|
|
||||||
use { "cespare/vim-toml", ft = { "toml" }, branch = "main" }
|
|
||||||
|
|
||||||
-- Edit text area in browser using nvim
|
|
||||||
if vim.g.is_win or vim.g.is_mac then
|
|
||||||
use {
|
|
||||||
"glacambre/firenvim",
|
|
||||||
run = function()
|
|
||||||
fn["firenvim#install"](0)
|
|
||||||
end,
|
|
||||||
opt = true,
|
|
||||||
setup = [[vim.cmd('packadd firenvim')]],
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Debugger plugin
|
|
||||||
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')]] }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Session management plugin
|
|
||||||
use { "tpope/vim-obsession", cmd = "Obsession" }
|
|
||||||
|
|
||||||
if vim.g.is_linux then
|
|
||||||
use { "ojroques/vim-oscyank", cmd = { "OSCYank", "OSCYankReg" } }
|
|
||||||
end
|
|
||||||
|
|
||||||
-- The missing auto-completion for cmdline!
|
|
||||||
use { "gelguy/wilder.nvim", opt = true, setup = [[vim.cmd('packadd wilder.nvim')]] }
|
|
||||||
|
|
||||||
-- showing keybindings
|
|
||||||
use {
|
|
||||||
"folke/which-key.nvim",
|
|
||||||
event = "VimEnter",
|
|
||||||
config = function()
|
|
||||||
vim.defer_fn(function()
|
|
||||||
require("config.which-key")
|
|
||||||
end, 2000)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- show and trim trailing whitespaces
|
|
||||||
use { "jdhao/whitespace.nvim", event = "VimEnter" }
|
|
||||||
|
|
||||||
-- file explorer
|
|
||||||
use {
|
|
||||||
"nvim-tree/nvim-tree.lua",
|
|
||||||
requires = { "nvim-tree/nvim-web-devicons" },
|
|
||||||
config = [[require('config.nvim-tree')]],
|
|
||||||
}
|
|
||||||
|
|
||||||
use { "ii14/emmylua-nvim", ft = "lua" }
|
|
||||||
|
|
||||||
use { "j-hui/fidget.nvim", after = "nvim-lspconfig", tag = "legacy", config = [[require('config.fidget-nvim')]] }
|
|
||||||
end,
|
|
||||||
config = {
|
|
||||||
max_jobs = 16,
|
|
||||||
compile_path = packer_util.join_paths(fn.stdpath("data"), "site", "lua", "packer_compiled.lua"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
|
|
||||||
-- 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")
|
|
||||||
vim.notify("PackerCompile done!", vim.log.levels.INFO, { title = "Nvim-config" })
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
local version = vim.version
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@@ -11,9 +12,8 @@ function M.executable(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- check whether a feature exists in Nvim
|
--- check whether a feature exists in Nvim
|
||||||
--- @feat: string
|
--- @param feat string the feature name, like `nvim-0.7` or `unix`.
|
||||||
--- the feature name, like `nvim-0.7` or `unix`.
|
--- @return boolean
|
||||||
--- return: bool
|
|
||||||
M.has = function(feat)
|
M.has = function(feat)
|
||||||
if fn.has(feat) == 1 then
|
if fn.has(feat) == 1 then
|
||||||
return true
|
return true
|
||||||
@@ -33,8 +33,9 @@ end
|
|||||||
|
|
||||||
--- Generate random integers in the range [Low, High], inclusive,
|
--- Generate random integers in the range [Low, High], inclusive,
|
||||||
--- adapted from https://stackoverflow.com/a/12739441/6064933
|
--- adapted from https://stackoverflow.com/a/12739441/6064933
|
||||||
--- @low: the lower value for this range
|
--- @param low integer the lower value for this range
|
||||||
--- @high: the upper value for this range
|
--- @param high integer the upper value for this range
|
||||||
|
--- @return integer
|
||||||
function M.rand_int(low, high)
|
function M.rand_int(low, high)
|
||||||
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
|
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
@@ -43,17 +44,39 @@ function M.rand_int(low, high)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Select a random element from a sequence/list.
|
--- Select a random element from a sequence/list.
|
||||||
--- @seq: the sequence to choose an element
|
--- @param seq any[] the sequence to choose an element
|
||||||
function M.rand_element(seq)
|
function M.rand_element(seq)
|
||||||
local idx = M.rand_int(1, #seq)
|
local idx = M.rand_int(1, #seq)
|
||||||
|
|
||||||
return seq[idx]
|
return seq[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.add_pack(name)
|
--- check if the current nvim version is compatible with the allowed version
|
||||||
local status, error = pcall(vim.cmd, "packadd " .. name)
|
--- @param expected_version string
|
||||||
|
--- @return boolean
|
||||||
|
function M.is_compatible_version(expected_version)
|
||||||
|
-- check if we have the latest stable version of nvim
|
||||||
|
local expect_ver = version.parse(expected_version)
|
||||||
|
local actual_ver = vim.version()
|
||||||
|
|
||||||
return status
|
if expect_ver == nil then
|
||||||
|
local msg = string.format("Unsupported version string: %s", expected_version)
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = version.cmp(expect_ver, actual_ver)
|
||||||
|
if result ~= 0 then
|
||||||
|
local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch)
|
||||||
|
local msg = string.format(
|
||||||
|
"Expect nvim version %s, but your current nvim version is %s. Use at your own risk!",
|
||||||
|
expected_version,
|
||||||
|
_ver
|
||||||
|
)
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
58
plugin/command.lua
Normal file
58
plugin/command.lua
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
-- Copy file path to clipboard
|
||||||
|
vim.api.nvim_create_user_command("CopyPath", function(context)
|
||||||
|
local full_path = vim.fn.glob("%:p")
|
||||||
|
|
||||||
|
local file_path = nil
|
||||||
|
if context["args"] == "nameonly" then
|
||||||
|
file_path = vim.fn.fnamemodify(full_path, ":t")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get the file path relative to project root
|
||||||
|
if context["args"] == "relative" then
|
||||||
|
local project_marker = { ".git", "pyproject.toml" }
|
||||||
|
local project_root = vim.fs.root(0, project_marker)
|
||||||
|
if project_root == nil then
|
||||||
|
vim.print("can not find project root")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
file_path = vim.fn.substitute(full_path, project_root, "<project-root>", "g")
|
||||||
|
end
|
||||||
|
|
||||||
|
if context["args"] == "absolute" then
|
||||||
|
file_path = full_path
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.fn.setreg("+", file_path)
|
||||||
|
vim.print("Filepath copied to clipboard!")
|
||||||
|
end, {
|
||||||
|
bang = false,
|
||||||
|
nargs = 1,
|
||||||
|
force = true,
|
||||||
|
desc = "Copy current file path to clipboard",
|
||||||
|
complete = function()
|
||||||
|
return { "nameonly", "relative", "absolute" }
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- JSON format part of or the whole file
|
||||||
|
vim.api.nvim_create_user_command("JSONFormat", function(context)
|
||||||
|
local range = context["range"]
|
||||||
|
local line1 = context["line1"]
|
||||||
|
local line2 = context["line2"]
|
||||||
|
|
||||||
|
if range == 0 then
|
||||||
|
-- the command is invoked without range, then we assume whole buffer
|
||||||
|
local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2)
|
||||||
|
vim.fn.execute(cmd_str)
|
||||||
|
elseif range == 2 then
|
||||||
|
-- the command is invoked with some range
|
||||||
|
local cmd_str = string.format("%s,%s!python -m json.tool", line1, line2)
|
||||||
|
vim.fn.execute(cmd_str)
|
||||||
|
else
|
||||||
|
vim.api.nvim_err_write(string.format("unsupported range: %s", range))
|
||||||
|
end
|
||||||
|
end, {
|
||||||
|
desc = "Format JSON string",
|
||||||
|
range = "%",
|
||||||
|
})
|
||||||
@@ -45,6 +45,3 @@ function! s:md_to_pdf() abort
|
|||||||
echoerr "Error running command"
|
echoerr "Error running command"
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" json format
|
|
||||||
command! -range JSONFormat <line1>,<line2>!python -m json.tool
|
|
||||||
|
|||||||
@@ -458,3 +458,21 @@ pyright
|
|||||||
stubgen
|
stubgen
|
||||||
pylance
|
pylance
|
||||||
variadic
|
variadic
|
||||||
|
Vimium
|
||||||
|
Databricks
|
||||||
|
Jira
|
||||||
|
databricks
|
||||||
|
FastAPI
|
||||||
|
pylintrc
|
||||||
|
PYTHONPATH
|
||||||
|
Uvicorn
|
||||||
|
qpdf
|
||||||
|
Elasticsearch
|
||||||
|
kibana
|
||||||
|
submodule
|
||||||
|
unix
|
||||||
|
GCP
|
||||||
|
Kubernetes
|
||||||
|
pubsub
|
||||||
|
Luarocks
|
||||||
|
luarocks
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
|
|
||||||
" change fillchars for folding, vertical split, end of buffer, and message separator
|
" change fillchars for folding, vertical split, end of buffer, and message separator
|
||||||
set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾
|
set fillchars=fold:\ ,foldsep:\ ,foldopen:,foldclose:,vert:\│,eob:\ ,msgsep:‾,diff:╱
|
||||||
|
|
||||||
" Split window below/right when creating horizontal/vertical windows
|
" Split window below/right when creating horizontal/vertical windows
|
||||||
set splitbelow splitright
|
set splitbelow splitright
|
||||||
|
|
||||||
|
" avoid the flickering when splitting window horizontal
|
||||||
|
set splitkeep=screen
|
||||||
|
|
||||||
" Time in milliseconds to wait for a mapped sequence to complete,
|
" Time in milliseconds to wait for a mapped sequence to complete,
|
||||||
" see https://unix.stackexchange.com/q/36882/221410 for more info
|
" see https://unix.stackexchange.com/q/36882/221410 for more info
|
||||||
set timeoutlen=500
|
set timeoutlen=500
|
||||||
@@ -69,9 +72,9 @@ set wildmode=list:longest
|
|||||||
set scrolloff=3
|
set scrolloff=3
|
||||||
|
|
||||||
" Use mouse to select and resize windows, etc.
|
" Use mouse to select and resize windows, etc.
|
||||||
set mouse=nic " Enable mouse in several mode
|
set mouse=
|
||||||
set mousemodel=popup " Set the behaviour of mouse
|
set mousemodel=popup " Set the behaviour of mouse
|
||||||
set mousescroll=ver:1,hor:6
|
set mousescroll=ver:1,hor:0
|
||||||
|
|
||||||
" Disable showing current mode on command line since statusline plugins can show it.
|
" Disable showing current mode on command line since statusline plugins can show it.
|
||||||
set noshowmode
|
set noshowmode
|
||||||
@@ -118,7 +121,7 @@ set completeopt+=menuone " Show menu even if there is only one item
|
|||||||
set completeopt-=preview " Disable the preview window
|
set completeopt-=preview " Disable the preview window
|
||||||
|
|
||||||
set pumheight=10 " Maximum number of items to show in popup menu
|
set pumheight=10 " Maximum number of items to show in popup menu
|
||||||
set pumblend=10 " pseudo transparency for completion menu
|
set pumblend=5 " pseudo transparency for completion menu
|
||||||
|
|
||||||
set winblend=0 " pseudo transparency for floating window
|
set winblend=0 " pseudo transparency for floating window
|
||||||
|
|
||||||
@@ -176,3 +179,5 @@ set diffopt+=linematch:60
|
|||||||
|
|
||||||
set nowrap " do no wrap
|
set nowrap " do no wrap
|
||||||
set noruler
|
set noruler
|
||||||
|
|
||||||
|
set showcmdloc=statusline
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
|
|
||||||
" Plugin specification and lua stuff
|
" Plugin specification and lua stuff
|
||||||
lua require('plugins')
|
lua require('plugin_specs')
|
||||||
|
|
||||||
" 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
|
||||||
" short alias, e.g., `pi`, then press <space>, the alias will be expanded to
|
" short alias, e.g., `pi`, then press <space>, the alias will be expanded to
|
||||||
" the full command automatically.
|
" the full command automatically.
|
||||||
call utils#Cabbrev('pi', 'PackerInstall')
|
call utils#Cabbrev('pi', 'Lazy install')
|
||||||
call utils#Cabbrev('pud', 'PackerUpdate')
|
call utils#Cabbrev('pud', 'Lazy update')
|
||||||
call utils#Cabbrev('pc', 'PackerClean')
|
call utils#Cabbrev('pc', 'Lazy clean')
|
||||||
call utils#Cabbrev('ps', 'PackerSync')
|
call utils#Cabbrev('ps', 'Lazy sync')
|
||||||
|
|
||||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" configurations for vim script plugin "
|
" configurations for vim script plugin "
|
||||||
@@ -58,16 +58,6 @@ endif
|
|||||||
" Only fuzzy-search files names
|
" Only fuzzy-search files names
|
||||||
let g:Lf_DefaultMode = 'FullPath'
|
let g:Lf_DefaultMode = 'FullPath'
|
||||||
|
|
||||||
" Popup window settings
|
|
||||||
let w = float2nr(&columns * 0.8)
|
|
||||||
if w > 140
|
|
||||||
let g:Lf_PopupWidth = 140
|
|
||||||
else
|
|
||||||
let g:Lf_PopupWidth = w
|
|
||||||
endif
|
|
||||||
|
|
||||||
let g:Lf_PopupPosition = [0, float2nr((&columns - g:Lf_PopupWidth)/2)]
|
|
||||||
|
|
||||||
" Do not use version control tool to list files under a directory since
|
" Do not use version control tool to list files under a directory since
|
||||||
" submodules are not searched by default.
|
" submodules are not searched by default.
|
||||||
let g:Lf_UseVersionControlTool = 0
|
let g:Lf_UseVersionControlTool = 0
|
||||||
@@ -89,7 +79,7 @@ let g:Lf_WorkingDirectoryMode = 'a'
|
|||||||
nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR>
|
nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR>
|
||||||
|
|
||||||
" Grep project files in popup window
|
" Grep project files in popup window
|
||||||
nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup<CR>
|
nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup --nameOnly<CR>
|
||||||
|
|
||||||
" Search vim help files
|
" Search vim help files
|
||||||
nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR>
|
nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR>
|
||||||
@@ -123,16 +113,6 @@ let g:Lf_PreviewResult = {
|
|||||||
\ 'Gtags': 0
|
\ 'Gtags': 0
|
||||||
\}
|
\}
|
||||||
|
|
||||||
""""""""""""""""""""""""""""open-browser.vim settings"""""""""""""""""""
|
|
||||||
if g:is_win || g:is_mac
|
|
||||||
" Disable netrw's gx mapping.
|
|
||||||
let g:netrw_nogx = 1
|
|
||||||
|
|
||||||
" Use another mapping for the open URL method
|
|
||||||
nmap ob <Plug>(openbrowser-smart-search)
|
|
||||||
xmap ob <Plug>(openbrowser-smart-search)
|
|
||||||
endif
|
|
||||||
|
|
||||||
""""""""""""""""""""""""""" vista settings """"""""""""""""""""""""""""""""""
|
""""""""""""""""""""""""""" vista settings """"""""""""""""""""""""""""""""""
|
||||||
let g:vista#renderer#icons = {
|
let g:vista#renderer#icons = {
|
||||||
\ 'member': '',
|
\ 'member': '',
|
||||||
@@ -401,7 +381,7 @@ function! s:wilder_init() abort
|
|||||||
\ 'apply_incsearch_fix': 0,
|
\ 'apply_incsearch_fix': 0,
|
||||||
\ }))
|
\ }))
|
||||||
catch /^Vim\%((\a\+)\)\=:E117/
|
catch /^Vim\%((\a\+)\)\=:E117/
|
||||||
echohl Error |echomsg "Wilder.nvim missing: run :PackerSync to fix."|echohl None
|
echohl Error |echomsg "Wilder.nvim missing"| echohl None
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
Reference in New Issue
Block a user