mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
32
README.md
32
README.md
@@ -13,7 +13,7 @@
|
||||
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
|
||||
</a>
|
||||
<a href="https://github.com/neovim/neovim/releases/tag/stable">
|
||||
<img src="https://img.shields.io/badge/Neovim-0.9.5-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
|
||||
<img src="https://img.shields.io/badge/Neovim-0.10.1-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
|
||||
</a>
|
||||
<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"/>
|
||||
@@ -21,8 +21,8 @@
|
||||
<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" />
|
||||
</a>
|
||||
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.9.5">
|
||||
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.9.5?style=flat-square" />
|
||||
<a href="https://github.com/jdhao/nvim-config/releases/tag/v0.10.0">
|
||||
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.0?style=flat-square" />
|
||||
</a>
|
||||
<a href="https://github.com/jdhao/nvim-config/graphs/contributors">
|
||||
<img src="https://img.shields.io/github/contributors/jdhao/nvim-config?style=flat-square" />
|
||||
@@ -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).
|
||||
+ Code formatting via [Neoformat](https://github.com/sbdchd/neoformat).
|
||||
+ 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
|
||||
@@ -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">
|
||||
</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
|
||||
|
||||
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) |
|
||||
| `<leader>gs` | Normal | Linux/macOS/Win | Show Git status result |
|
||||
| `<leader>gw` | Normal | Linux/macOS/Win | Run Git add for current file |
|
||||
| `<leader>gd` | Normal | Linux/macOS/Win | Run git diff for current file |
|
||||
| `<leader>gc` | Normal | Linux/macOS/Win | Run git commit |
|
||||
| `<leader>gpl` | Normal | Linux/macOS/Win | Run git pull |
|
||||
| `<leader>gpu` | Normal | Linux/macOS/Win | Run git push |
|
||||
| `<leader>gl` | Normal/Visual | Linux/macOS/Win | Get perm link for current/visually-select lines
|
||||
| `<leader>gb` | Normal | macOS | Browse current git repo in browser
|
||||
| `<leader>gbd` | Normal | Linux/macOS/Win | Delete a branch |
|
||||
| `<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) |
|
||||
| `<F11>` | Normal | Linux/macOS/Win | Toggle spell checking |
|
||||
| `<F12>` | Normal | Linux/macOS/Win | Toggle paste mode |
|
||||
@@ -191,11 +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.
|
||||
|
||||
| command | description | example |
|
||||
|------------|-------------------------------------------------------------------------|--------------------------------|
|
||||
| `Redir` | capture command output to a tabpage for easier inspection. | `Redir hi` |
|
||||
| `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` |
|
||||
| command | description | example |
|
||||
|--------------|-------------------------------------------------------------------------|--------------------------------|
|
||||
| `Redir` | capture command output to a tabpage for easier inspection. | `Redir hi` |
|
||||
| `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` |
|
||||
| `JSONFormat` | format a JSON file | `JSONFormat` |
|
||||
|
||||
# Contributing
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -3,7 +3,3 @@ set formatoptions-=o
|
||||
set formatoptions-=r
|
||||
|
||||
nnoremap <buffer><silent> <F9> :luafile %<CR>
|
||||
|
||||
" Use nvim-treesitter for folding
|
||||
set foldmethod=expr
|
||||
set foldexpr=nvim_treesitter#foldexpr()
|
||||
|
||||
@@ -12,7 +12,3 @@ set tabstop=4 " number of visual spaces per TAB
|
||||
set softtabstop=4 " number of spaces in tab when editing
|
||||
set shiftwidth=4 " number of spaces to use for autoindent
|
||||
set expandtab " expand tab to spaces so that tabs are spaces
|
||||
|
||||
" Use nvim-treesitter for folding
|
||||
set foldmethod=expr
|
||||
set foldexpr=nvim_treesitter#foldexpr()
|
||||
|
||||
@@ -118,16 +118,16 @@ The version of Git on the Linux system may be too old so that plugins may break.
|
||||
Check [here](https://jdhao.github.io/2021/03/27/upgrade_git_on_linux/) on how to install and set up the latest version of Git.
|
||||
For Windows, install [Git for Windows](https://git-scm.com/download/win) and make sure you can run `git` from command line.
|
||||
|
||||
### ctags
|
||||
### 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.
|
||||
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 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
|
||||
brew install ctags
|
||||
brew install universal-ctags
|
||||
```
|
||||
|
||||
To install it Windows, use [chocolatey](https://chocolatey.org/) or [scoop](https://scoop.sh/)
|
||||
@@ -166,35 +166,9 @@ 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.
|
||||
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).
|
||||
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.
|
||||
After installing Nvim, we need to set the PATH to nvim correctly.
|
||||
**Make sure that you can run `nvim` from the command line after all these setups**.
|
||||
|
||||
## Setting up Nvim
|
||||
|
||||
51
init.lua
51
init.lua
@@ -11,40 +11,23 @@
|
||||
-- StackOverflow: https://stackoverflow.com/users/6064933/jdhao
|
||||
vim.loader.enable()
|
||||
|
||||
local version = vim.version
|
||||
local utils = require("utils")
|
||||
|
||||
-- check if we have the latest stable version of nvim
|
||||
local expected_ver = "0.10.0"
|
||||
local ev = version.parse(expected_ver)
|
||||
local actual_ver = version()
|
||||
local expected_version = "0.10.1"
|
||||
utils.is_compatible_version(expected_version)
|
||||
|
||||
local result = version.cmp(ev, {actual_ver.major, actual_ver.minor, actual_ver.patch})
|
||||
local config_dir = vim.fn.stdpath("config")
|
||||
---@cast config_dir string
|
||||
|
||||
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 %s, but got %s instead. Use at your own risk!", expected_ver, _ver)
|
||||
vim.api.nvim_err_writeln(msg)
|
||||
end
|
||||
|
||||
local core_conf_files = {
|
||||
"globals.lua", -- some global settings
|
||||
"options.vim", -- setting options in nvim
|
||||
"autocommands.vim", -- various autocommands
|
||||
"mappings.lua", -- all the user-defined mappings
|
||||
"plugins.vim", -- all the plugins installed and their configurations
|
||||
"colorschemes.lua", -- colorscheme settings
|
||||
}
|
||||
|
||||
local viml_conf_dir = vim.fn.stdpath("config") .. "/viml_conf"
|
||||
-- source all the core config files
|
||||
for _, file_name in ipairs(core_conf_files) do
|
||||
if vim.endswith(file_name, 'vim') then
|
||||
local path = string.format("%s/%s", viml_conf_dir, 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
|
||||
-- some global settings
|
||||
require("globals")
|
||||
-- setting options in nvim
|
||||
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/options.vim"))
|
||||
-- various autocommands
|
||||
require("custom-autocmd")
|
||||
-- all the user-defined mappings
|
||||
require("mappings")
|
||||
-- all the plugins installed and their configurations
|
||||
vim.cmd("source ".. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
|
||||
-- colorscheme settings
|
||||
require("colorschemes")
|
||||
|
||||
@@ -24,9 +24,9 @@ M.colorscheme_conf = {
|
||||
end,
|
||||
gruvbox_material = function()
|
||||
-- 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
|
||||
vim.g.gruvbox_material_background = "soft"
|
||||
vim.g.gruvbox_material_background = "medium"
|
||||
vim.g.gruvbox_material_enable_italic = 1
|
||||
vim.g.gruvbox_material_better_performance = 1
|
||||
|
||||
@@ -56,6 +56,12 @@ M.colorscheme_conf = {
|
||||
vim.g.material_style = "oceanic"
|
||||
vim.cmd('colorscheme material')
|
||||
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.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require("bufferline").setup {
|
||||
options = {
|
||||
numbers = "buffer_id",
|
||||
numbers = "none",
|
||||
close_command = "bdelete! %d",
|
||||
right_mouse_command = nil,
|
||||
left_mouse_command = "buffer %d",
|
||||
@@ -44,3 +44,7 @@ require("bufferline").setup {
|
||||
sort_by = "id",
|
||||
},
|
||||
}
|
||||
|
||||
vim.keymap.set("n", "<space>bp", "<cmd>BufferLinePick<CR>", {
|
||||
desc = "pick a buffer",
|
||||
})
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
local keymap = vim.keymap
|
||||
|
||||
keymap.set("n", "<leader>gs", "<cmd>Git<cr>", { desc = "Git status" })
|
||||
keymap.set("n", "<leader>gw", "<cmd>Gwrite<cr>", { desc = "Git add" })
|
||||
keymap.set("n", "<leader>gc", "<cmd>Git commit<cr>", { desc = "Git commit" })
|
||||
keymap.set("n", "<leader>gd", "<cmd>Gdiffsplit<cr>", { desc = "Git diff" })
|
||||
keymap.set("n", "<leader>gpl", "<cmd>Git pull<cr>", { desc = "Git pull" })
|
||||
keymap.set("n", "<leader>gpu", "<cmd>15 split|term git push<cr>", { desc = "Git push" })
|
||||
keymap.set("n", "<leader>gs", "<cmd>Git<cr>", { desc = "Git: show status" })
|
||||
keymap.set("n", "<leader>gw", "<cmd>Gwrite<cr>", { desc = "Git: add file" })
|
||||
keymap.set("n", "<leader>gc", "<cmd>Git commit<cr>", { desc = "Git: commit changes" })
|
||||
keymap.set("n", "<leader>gpl", "<cmd>Git pull<cr>", { desc = "Git: pull changes" })
|
||||
keymap.set("n", "<leader>gpu", "<cmd>15 split|term git push<cr>", { desc = "Git: push changes" })
|
||||
keymap.set("v", "<leader>gb", ":Git blame<cr>", { desc = "Git: blame selected line" })
|
||||
|
||||
-- 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" })
|
||||
|
||||
@@ -24,14 +24,14 @@ keymap.set({ "n", "v" }, "<leader>gl", function()
|
||||
gitlinker.get_buf_range_url(mode)
|
||||
end, {
|
||||
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({
|
||||
action_callback = gitlinker.actions.open_in_browser
|
||||
})
|
||||
end, {
|
||||
silent = true,
|
||||
desc = "browse repo in browser",
|
||||
desc = "Git: browse repo in browser",
|
||||
})
|
||||
|
||||
@@ -35,15 +35,48 @@ keymap.set("n", "N", "", {
|
||||
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", "*", "", {
|
||||
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()
|
||||
end,
|
||||
})
|
||||
keymap.set("n", "#", "", {
|
||||
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()
|
||||
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,
|
||||
}
|
||||
@@ -43,7 +43,7 @@ local custom_attach = function(client, bufnr)
|
||||
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
|
||||
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
|
||||
map("n", "<space>wl", function()
|
||||
inspect(vim.lsp.buf.list_workspace_folders())
|
||||
vim.print(vim.lsp.buf.list_workspace_folders())
|
||||
end, { desc = "list workspace folder" })
|
||||
|
||||
-- Set some key bindings conditional on server capabilities
|
||||
@@ -110,6 +110,11 @@ local custom_attach = function(client, bufnr)
|
||||
end
|
||||
|
||||
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||
-- required by nvim-ufo
|
||||
capabilities.textDocument.foldingRange = {
|
||||
dynamicRegistration = false,
|
||||
lineFoldingOnly = true
|
||||
}
|
||||
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
@@ -225,21 +230,6 @@ 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)
|
||||
version = "LuaJIT",
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
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 = {
|
||||
vim.env.VIMRUNTIME,
|
||||
fn.stdpath("config"),
|
||||
},
|
||||
maxPreload = 2000,
|
||||
preloadFileSize = 50000,
|
||||
},
|
||||
},
|
||||
},
|
||||
capabilities = capabilities,
|
||||
|
||||
@@ -99,12 +99,12 @@ end
|
||||
|
||||
local virtual_env = function()
|
||||
-- only show virtual env for Python
|
||||
if vim.bo.filetype ~= 'python' then
|
||||
if vim.bo.filetype ~= "python" then
|
||||
return ""
|
||||
end
|
||||
|
||||
local conda_env = os.getenv('CONDA_DEFAULT_ENV')
|
||||
local venv_path = os.getenv('VIRTUAL_ENV')
|
||||
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
|
||||
@@ -113,17 +113,33 @@ local virtual_env = function()
|
||||
return string.format(" %s (conda)", conda_env)
|
||||
end
|
||||
else
|
||||
local venv_name = vim.fn.fnamemodify(venv_path, ':t')
|
||||
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 {
|
||||
options = {
|
||||
icons_enabled = true,
|
||||
theme = "auto",
|
||||
-- component_separators = { left = "", right = "" },
|
||||
-- section_separators = { left = "", right = "" },
|
||||
section_separators = "",
|
||||
component_separators = "",
|
||||
disabled_filetypes = {},
|
||||
@@ -132,18 +148,29 @@ require("lualine").setup {
|
||||
sections = {
|
||||
lualine_a = { "mode" },
|
||||
lualine_b = {
|
||||
"branch",
|
||||
{
|
||||
"branch",
|
||||
fmt = function(name, _)
|
||||
-- truncate branch name in case the name is too long
|
||||
return string.sub(name, 1, 20)
|
||||
end,
|
||||
},
|
||||
{
|
||||
virtual_env,
|
||||
color = { fg = "black", bg = "#F1CA81" },
|
||||
},
|
||||
},
|
||||
lualine_c = {
|
||||
{
|
||||
"filename",
|
||||
symbols = {
|
||||
readonly = "[🔒]",
|
||||
},
|
||||
},
|
||||
{
|
||||
"diff",
|
||||
source = diff,
|
||||
},
|
||||
{
|
||||
virtual_env,
|
||||
color = { fg = 'black', bg = "#F1CA81" }
|
||||
}
|
||||
},
|
||||
lualine_c = {
|
||||
"filename",
|
||||
{
|
||||
ime_state,
|
||||
color = { fg = "black", bg = "#f46868" },
|
||||
@@ -152,13 +179,19 @@ require("lualine").setup {
|
||||
spell,
|
||||
color = { fg = "black", bg = "#a7c080" },
|
||||
},
|
||||
},
|
||||
lualine_x = {
|
||||
{
|
||||
get_active_lsp,
|
||||
icon = " LSP:",
|
||||
},
|
||||
{
|
||||
"diagnostics",
|
||||
sources = { "nvim_diagnostic" },
|
||||
symbols = {error = '🆇 ', warn = '⚠️ ', info = 'ℹ️ ', hint = ' '},
|
||||
symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " },
|
||||
},
|
||||
},
|
||||
lualine_x = {
|
||||
lualine_y = {
|
||||
"encoding",
|
||||
{
|
||||
"fileformat",
|
||||
@@ -170,9 +203,6 @@ require("lualine").setup {
|
||||
},
|
||||
"filetype",
|
||||
},
|
||||
lualine_y = {
|
||||
"location",
|
||||
},
|
||||
lualine_z = {
|
||||
{
|
||||
trailing_space,
|
||||
@@ -182,6 +212,7 @@ require("lualine").setup {
|
||||
mixed_indent,
|
||||
color = "WarningMsg",
|
||||
},
|
||||
"progress"
|
||||
},
|
||||
},
|
||||
inactive_sections = {
|
||||
@@ -35,7 +35,6 @@ cmp.setup {
|
||||
{ name = "ultisnips" }, -- For ultisnips user.
|
||||
{ name = "path" }, -- for path completion
|
||||
{ name = "buffer", keyword_length = 2 }, -- for buffer word completion
|
||||
{ name = "emoji", insert = true }, -- emoji completion
|
||||
},
|
||||
completion = {
|
||||
keyword_length = 1,
|
||||
@@ -50,12 +49,14 @@ cmp.setup {
|
||||
menu = {
|
||||
nvim_lsp = "[LSP]",
|
||||
ultisnips = "[US]",
|
||||
nvim_lua = "[Lua]",
|
||||
path = "[Path]",
|
||||
buffer = "[Buffer]",
|
||||
emoji = "[Emoji]",
|
||||
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 = 2
|
||||
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" },
|
||||
},
|
||||
}
|
||||
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",
|
||||
})
|
||||
@@ -1,13 +1,17 @@
|
||||
require("yanky").setup({
|
||||
ring = {
|
||||
history_length = 50,
|
||||
storage = "memory",
|
||||
},
|
||||
require("yanky").setup {
|
||||
preserve_cursor_position = {
|
||||
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
|
||||
vim.keymap.set("n", "[y", "<Plug>(YankyCycleForward)")
|
||||
vim.keymap.set("n", "]y", "<Plug>(YankyCycleBackward)")
|
||||
vim.keymap.set("n", "[y", "<Plug>(YankyPreviousEntry)")
|
||||
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
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -38,8 +38,8 @@ 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)
|
||||
if vim.v.event.operator == "y" then
|
||||
vim.fn.setpos(".", vim.g.current_cursor_pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
@@ -102,4 +102,174 @@ local function open_nvim_tree(data)
|
||||
require("nvim-tree.api").tree.open()
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })
|
||||
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()
|
||||
vim.cmd([[
|
||||
" 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
|
||||
]])
|
||||
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
|
||||
})
|
||||
|
||||
@@ -3,11 +3,6 @@ local api = vim.api
|
||||
|
||||
local utils = require('utils')
|
||||
|
||||
-- Inspect something
|
||||
function _G.inspect(item)
|
||||
vim.print(item)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- custom variables --
|
||||
------------------------------------------------------------------------
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
local keymap = vim.keymap
|
||||
local api = vim.api
|
||||
local uv = vim.uv
|
||||
|
||||
-- Save key strokes (now we do not need to press shift to enter command mode).
|
||||
@@ -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
|
||||
keymap.set("n", [[\d]], "<cmd>bprevious <bar> bdelete #<cr>", {
|
||||
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),
|
||||
@@ -215,19 +228,24 @@ keymap.set("n", "<leader>cb", function()
|
||||
local cnt = 0
|
||||
local blink_times = 7
|
||||
local timer = uv.new_timer()
|
||||
if timer == nil then
|
||||
return
|
||||
end
|
||||
|
||||
timer:start(0, 100, vim.schedule_wrap(function()
|
||||
vim.cmd [[
|
||||
timer:start(
|
||||
0,
|
||||
100,
|
||||
vim.schedule_wrap(function()
|
||||
vim.cmd([[
|
||||
set cursorcolumn!
|
||||
set cursorline!
|
||||
]]
|
||||
]])
|
||||
|
||||
if cnt == blink_times then
|
||||
timer:close()
|
||||
end
|
||||
if cnt == blink_times then
|
||||
timer:close()
|
||||
end
|
||||
|
||||
cnt = cnt + 1
|
||||
end)
|
||||
cnt = cnt + 1
|
||||
end)
|
||||
)
|
||||
end,
|
||||
{ desc = "show cursor" })
|
||||
end, { desc = "show cursor" })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local utils = require("utils")
|
||||
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
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 {
|
||||
@@ -22,7 +23,8 @@ end
|
||||
local plugin_specs = {
|
||||
-- auto-completion engine
|
||||
{
|
||||
"hrsh7th/nvim-cmp",
|
||||
"iguanacucumber/magazine.nvim",
|
||||
name = "nvim-cmp",
|
||||
-- event = 'InsertEnter',
|
||||
event = "VeryLazy",
|
||||
dependencies = {
|
||||
@@ -31,14 +33,12 @@ local plugin_specs = {
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-omni",
|
||||
"hrsh7th/cmp-emoji",
|
||||
"quangnguyen30192/cmp-nvim-ultisnips",
|
||||
},
|
||||
config = function()
|
||||
require("config.nvim-cmp")
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
@@ -62,9 +62,6 @@ local plugin_specs = {
|
||||
end,
|
||||
},
|
||||
|
||||
-- Python indent (follows the PEP8 style)
|
||||
{ "Vimjas/vim-python-pep8-indent", ft = { "python" } },
|
||||
|
||||
-- Python-related text object
|
||||
{ "jeetsukumaran/vim-pythonsense", ft = { "python" } },
|
||||
|
||||
@@ -108,8 +105,12 @@ local plugin_specs = {
|
||||
"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")
|
||||
vim.cmd("LeaderfInstallCExtension")
|
||||
end
|
||||
end,
|
||||
},
|
||||
@@ -122,9 +123,19 @@ local plugin_specs = {
|
||||
},
|
||||
},
|
||||
{
|
||||
"lukas-reineke/headlines.nvim",
|
||||
dependencies = "nvim-treesitter/nvim-treesitter",
|
||||
config = true, -- or `opts = {}`
|
||||
"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 },
|
||||
@@ -136,7 +147,13 @@ local plugin_specs = {
|
||||
{ "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" },
|
||||
|
||||
{
|
||||
@@ -144,7 +161,7 @@ local plugin_specs = {
|
||||
event = "VeryLazy",
|
||||
cond = firenvim_not_active,
|
||||
config = function()
|
||||
require("config.statusline")
|
||||
require("config.lualine")
|
||||
end,
|
||||
},
|
||||
|
||||
@@ -169,12 +186,33 @@ local plugin_specs = {
|
||||
{
|
||||
"lukas-reineke/indent-blankline.nvim",
|
||||
event = "VeryLazy",
|
||||
main = 'ibl',
|
||||
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" },
|
||||
|
||||
@@ -190,7 +228,12 @@ local plugin_specs = {
|
||||
-- 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.
|
||||
{
|
||||
"tyru/open-browser.vim",
|
||||
"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
|
||||
@@ -198,7 +241,9 @@ local plugin_specs = {
|
||||
return false
|
||||
end
|
||||
end,
|
||||
event = "VeryLazy",
|
||||
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
|
||||
@@ -222,9 +267,9 @@ local plugin_specs = {
|
||||
|
||||
-- Automatic insertion and deletion of a pair of characters
|
||||
{
|
||||
'windwp/nvim-autopairs',
|
||||
event = "InsertEnter",
|
||||
config = true
|
||||
"windwp/nvim-autopairs",
|
||||
event = "InsertEnter",
|
||||
config = true,
|
||||
},
|
||||
|
||||
-- Comment plugin
|
||||
@@ -245,10 +290,10 @@ local plugin_specs = {
|
||||
-- Manage your yank history
|
||||
{
|
||||
"gbprod/yanky.nvim",
|
||||
cmd = { "YankyRingHistory" },
|
||||
config = function()
|
||||
require("config.yanky")
|
||||
end,
|
||||
event = "VeryLazy",
|
||||
},
|
||||
|
||||
-- Handy unix command inside Vim (Rename, Move etc.)
|
||||
@@ -316,7 +361,7 @@ local plugin_specs = {
|
||||
{ "rhysd/committia.vim", lazy = true },
|
||||
|
||||
{
|
||||
"sindrets/diffview.nvim"
|
||||
"sindrets/diffview.nvim",
|
||||
},
|
||||
|
||||
{
|
||||
@@ -349,14 +394,6 @@ local plugin_specs = {
|
||||
ft = { "markdown" },
|
||||
},
|
||||
|
||||
{
|
||||
"folke/zen-mode.nvim",
|
||||
cmd = "ZenMode",
|
||||
config = function()
|
||||
require("config.zen-mode")
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"rhysd/vim-grammarous",
|
||||
enabled = function()
|
||||
@@ -408,7 +445,7 @@ local plugin_specs = {
|
||||
|
||||
-- Modern matchit implementation
|
||||
{ "andymass/vim-matchup", event = "BufRead" },
|
||||
{ "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } },
|
||||
{ "tpope/vim-scriptease", cmd = { "Scriptnames", "Messages", "Verbose" } },
|
||||
|
||||
-- Asynchronous command execution
|
||||
{ "skywind3000/asyncrun.vim", lazy = true, cmd = { "AsyncRun" } },
|
||||
@@ -418,17 +455,26 @@ local plugin_specs = {
|
||||
{
|
||||
"glacambre/firenvim",
|
||||
enabled = function()
|
||||
if vim.g.is_win or vim.g.is_mac then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
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()
|
||||
vim.fn["firenvim#install"](0)
|
||||
end,
|
||||
lazy = true,
|
||||
},
|
||||
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",
|
||||
@@ -477,7 +523,7 @@ local plugin_specs = {
|
||||
-- file explorer
|
||||
{
|
||||
"nvim-tree/nvim-tree.lua",
|
||||
keys = { "<space>s" },
|
||||
event = "VeryLazy",
|
||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||
config = function()
|
||||
require("config.nvim-tree")
|
||||
@@ -492,15 +538,51 @@ local plugin_specs = {
|
||||
require("config.fidget-nvim")
|
||||
end,
|
||||
},
|
||||
{
|
||||
"folke/lazydev.nvim",
|
||||
ft = "lua", -- only load on lua files
|
||||
opts = {},
|
||||
},
|
||||
{
|
||||
"CopilotC-Nvim/CopilotChat.nvim",
|
||||
branch = "canary",
|
||||
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",
|
||||
},
|
||||
}
|
||||
|
||||
-- configuration for lazy itself.
|
||||
local lazy_opts = {
|
||||
require("lazy").setup {
|
||||
spec = plugin_specs,
|
||||
ui = {
|
||||
border = "rounded",
|
||||
title = "Plugin Manager",
|
||||
title_pos = "center",
|
||||
},
|
||||
rocks = {
|
||||
enabled = false,
|
||||
},
|
||||
}
|
||||
|
||||
require("lazy").setup(plugin_specs, lazy_opts)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local fn = vim.fn
|
||||
local version = vim.version
|
||||
|
||||
local M = {}
|
||||
|
||||
@@ -11,9 +12,8 @@ function M.executable(name)
|
||||
end
|
||||
|
||||
--- check whether a feature exists in Nvim
|
||||
--- @feat: string
|
||||
--- the feature name, like `nvim-0.7` or `unix`.
|
||||
--- return: bool
|
||||
--- @param feat string the feature name, like `nvim-0.7` or `unix`.
|
||||
--- @return boolean
|
||||
M.has = function(feat)
|
||||
if fn.has(feat) == 1 then
|
||||
return true
|
||||
@@ -33,8 +33,9 @@ end
|
||||
|
||||
--- Generate random integers in the range [Low, High], inclusive,
|
||||
--- adapted from https://stackoverflow.com/a/12739441/6064933
|
||||
--- @low: the lower value for this range
|
||||
--- @high: the upper value for this range
|
||||
--- @param low integer the lower value for this range
|
||||
--- @param high integer the upper value for this range
|
||||
--- @return integer
|
||||
function M.rand_int(low, high)
|
||||
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
|
||||
math.randomseed(os.time())
|
||||
@@ -43,17 +44,39 @@ function M.rand_int(low, high)
|
||||
end
|
||||
|
||||
--- 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)
|
||||
local idx = M.rand_int(1, #seq)
|
||||
|
||||
return seq[idx]
|
||||
end
|
||||
|
||||
function M.add_pack(name)
|
||||
local status, error = pcall(vim.cmd, "packadd " .. name)
|
||||
--- check if the current nvim version is compatible with the allowed version
|
||||
--- @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
|
||||
|
||||
return M
|
||||
|
||||
@@ -467,3 +467,6 @@ pylintrc
|
||||
PYTHONPATH
|
||||
Uvicorn
|
||||
qpdf
|
||||
Elasticsearch
|
||||
kibana
|
||||
submodule
|
||||
|
||||
@@ -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")
|
||||
@@ -1,11 +1,14 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
" change fillchars for folding, vertical split, end of buffer, and message separator
|
||||
set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾,diff:╱
|
||||
set fillchars=fold:\ ,foldsep:\ ,foldopen:,foldclose:,vert:\│,eob:\ ,msgsep:‾,diff:╱
|
||||
|
||||
" Split window below/right when creating horizontal/vertical windows
|
||||
set splitbelow splitright
|
||||
|
||||
" avoid the flickering when splitting window horizontal
|
||||
set splitkeep=screen
|
||||
|
||||
" Time in milliseconds to wait for a mapped sequence to complete,
|
||||
" see https://unix.stackexchange.com/q/36882/221410 for more info
|
||||
set timeoutlen=500
|
||||
@@ -118,7 +121,7 @@ set completeopt+=menuone " Show menu even if there is only one item
|
||||
set completeopt-=preview " Disable the preview window
|
||||
|
||||
set pumheight=10 " Maximum number of items to show in popup menu
|
||||
set pumblend=10 " pseudo transparency for completion menu
|
||||
set pumblend=5 " pseudo transparency for completion menu
|
||||
|
||||
set winblend=0 " pseudo transparency for floating window
|
||||
|
||||
|
||||
@@ -58,16 +58,6 @@ endif
|
||||
" Only fuzzy-search files names
|
||||
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
|
||||
" submodules are not searched by default.
|
||||
let g:Lf_UseVersionControlTool = 0
|
||||
@@ -123,16 +113,6 @@ let g:Lf_PreviewResult = {
|
||||
\ '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 """"""""""""""""""""""""""""""""""
|
||||
let g:vista#renderer#icons = {
|
||||
\ 'member': '',
|
||||
|
||||
Reference in New Issue
Block a user