mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
20 Commits
v0.10.3
...
265f171172
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
265f171172 | ||
|
|
b82c1c112f | ||
|
|
0816faee76 | ||
|
|
12147bec86 | ||
|
|
a8a1b92921 | ||
|
|
5f662f143b | ||
|
|
f005a8303d | ||
|
|
8cba1ba234 | ||
|
|
a00e1fd92a | ||
|
|
2383eb7075 | ||
|
|
ab059bbb6d | ||
|
|
93166c65a5 | ||
|
|
4b8c490abd | ||
|
|
2242961925 | ||
|
|
ac421715d3 | ||
|
|
28bda349e8 | ||
|
|
ee4bce4671 | ||
|
|
7f53743255 | ||
|
|
94497c0a73 | ||
|
|
70e9943aac |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ en.utf-8.add.spl
|
||||
.netrwhist
|
||||
*.log
|
||||
.DS_Store
|
||||
lazy-lock.json
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img alt="Windows" src="https://img.shields.io/badge/Windows-%23.svg?style=flat-square&logo=windows&color=0078D6&logoColor=white" />
|
||||
</a>
|
||||
<a href="https://github.com/neovim/neovim/releases/tag/stable">
|
||||
<img src="https://img.shields.io/badge/Neovim-0.10.3-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
|
||||
<img src="https://img.shields.io/badge/Neovim-0.11.0-blueviolet.svg?style=flat-square&logo=Neovim&logoColor=green" alt="Neovim minimum version"/>
|
||||
</a>
|
||||
<a href="https://github.com/jdhao/nvim-config/releases/latest">
|
||||
<img alt="Latest release" src="https://img.shields.io/github/v/release/jdhao/nvim-config" />
|
||||
@@ -21,9 +21,6 @@
|
||||
<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.10.2">
|
||||
<img src="https://img.shields.io/github/commits-since/jdhao/nvim-config/v0.10.2?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" />
|
||||
</a>
|
||||
|
||||
@@ -10,23 +10,6 @@ function! s:Single_quote(str) abort
|
||||
return "'" . substitute(copy(a:str), "'", "''", 'g') . "'"
|
||||
endfunction
|
||||
|
||||
" Check the syntax group in the current cursor position, see
|
||||
" https://stackoverflow.com/q/9464844/6064933 and
|
||||
" https://jordanelver.co.uk/blog/2015/05/27/working-with-vim-colorschemes/
|
||||
function! utils#SynGroup() abort
|
||||
if !exists('*synstack')
|
||||
return
|
||||
endif
|
||||
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
|
||||
endfunction
|
||||
|
||||
" Check if a colorscheme exists in runtimepath.
|
||||
" The following two functions are inspired by https://stackoverflow.com/a/5703164/6064933.
|
||||
function! utils#HasColorscheme(name) abort
|
||||
let l:pat = printf('colors/%s.vim', a:name)
|
||||
return !empty(globpath(&runtimepath, l:pat))
|
||||
endfunction
|
||||
|
||||
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
|
||||
function! utils#VimFolds(lnum) abort
|
||||
" get content of current line and the line below
|
||||
@@ -146,27 +129,6 @@ function! utils#iso_time(timestamp) abort
|
||||
|
||||
endfunction
|
||||
|
||||
" Check if we are inside a Git repo.
|
||||
function! utils#Inside_git_repo() abort
|
||||
let res = system('git rev-parse --is-inside-work-tree')
|
||||
if match(res, 'true') == -1
|
||||
return v:false
|
||||
else
|
||||
" Manually trigger a special user autocmd InGitRepo (used lazyloading.
|
||||
doautocmd User InGitRepo
|
||||
return v:true
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! utils#GetGitBranch()
|
||||
let l:res = systemlist('git rev-parse --abbrev-ref HEAD')[0]
|
||||
if match(l:res, 'fatal') != -1
|
||||
return ''
|
||||
else
|
||||
return l:res
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Redirect command output to a register for later processing.
|
||||
" Ref: https://stackoverflow.com/q/2573021/6064933 and https://unix.stackexchange.com/q/8101/221410 .
|
||||
function! utils#CaptureCommandOutput(command) abort
|
||||
|
||||
11
init.lua
11
init.lua
@@ -13,7 +13,7 @@ vim.loader.enable()
|
||||
|
||||
local utils = require("utils")
|
||||
|
||||
local expected_version = "0.10.3"
|
||||
local expected_version = "0.11.0"
|
||||
utils.is_compatible_version(expected_version)
|
||||
|
||||
local config_dir = vim.fn.stdpath("config")
|
||||
@@ -29,5 +29,12 @@ require("custom-autocmd")
|
||||
require("mappings")
|
||||
-- all the plugins installed and their configurations
|
||||
vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
|
||||
|
||||
-- diagnostic related config
|
||||
require("diagnostic-conf")
|
||||
|
||||
-- colorscheme settings
|
||||
require("colorschemes")
|
||||
local color_scheme = require("colorschemes")
|
||||
|
||||
-- Load a random colorscheme
|
||||
color_scheme.rand_colorscheme()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
--- This module will load a random colorscheme on nvim startup process.
|
||||
|
||||
local utils = require("utils")
|
||||
|
||||
local M = {}
|
||||
@@ -8,9 +7,14 @@ local M = {}
|
||||
-- the same as the colorscheme name itself.
|
||||
M.colorscheme_conf = {
|
||||
onedark = function()
|
||||
vim.cmd([[colorscheme onedark]])
|
||||
-- Lua
|
||||
require("onedark").setup {
|
||||
style = "darker",
|
||||
}
|
||||
require("onedark").load()
|
||||
end,
|
||||
edge = function()
|
||||
vim.g.edge_style = "default"
|
||||
vim.g.edge_enable_italic = 1
|
||||
vim.g.edge_better_performance = 1
|
||||
|
||||
@@ -26,34 +30,29 @@ M.colorscheme_conf = {
|
||||
-- foreground option can be material, mix, or original
|
||||
vim.g.gruvbox_material_foreground = "original"
|
||||
--background option can be hard, medium, soft
|
||||
vim.g.gruvbox_material_background = "medium"
|
||||
vim.g.gruvbox_material_background = "hard"
|
||||
vim.g.gruvbox_material_enable_italic = 1
|
||||
vim.g.gruvbox_material_better_performance = 1
|
||||
|
||||
vim.cmd([[colorscheme gruvbox-material]])
|
||||
end,
|
||||
everforest = function()
|
||||
vim.g.everforest_background = "hard"
|
||||
vim.g.everforest_enable_italic = 1
|
||||
vim.g.everforest_better_performance = 1
|
||||
|
||||
vim.cmd([[colorscheme everforest]])
|
||||
end,
|
||||
nightfox = function()
|
||||
vim.cmd([[colorscheme nordfox]])
|
||||
end,
|
||||
catppuccin = function()
|
||||
-- available option: latte, frappe, macchiato, mocha
|
||||
vim.g.catppuccin_flavour = "frappe"
|
||||
require("catppuccin").setup()
|
||||
|
||||
vim.cmd([[colorscheme catppuccin]])
|
||||
vim.cmd([[colorscheme carbonfox]])
|
||||
end,
|
||||
onedarkpro = function()
|
||||
-- set colorscheme after options
|
||||
vim.cmd("colorscheme onedark_vivid")
|
||||
-- onedark_vivid does not enough contrast
|
||||
vim.cmd("colorscheme onedark_dark")
|
||||
end,
|
||||
material = function()
|
||||
vim.g.material_style = "oceanic"
|
||||
vim.g.material_style = "darker"
|
||||
vim.cmd("colorscheme material")
|
||||
end,
|
||||
arctic = function()
|
||||
@@ -68,13 +67,6 @@ M.colorscheme_conf = {
|
||||
M.rand_colorscheme = function()
|
||||
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
|
||||
|
||||
if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then
|
||||
local msg = "Invalid colorscheme: " .. colorscheme
|
||||
vim.notify(msg, vim.log.levels.ERROR, { title = "nvim-config" })
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
-- Load the colorscheme and its settings
|
||||
M.colorscheme_conf[colorscheme]()
|
||||
|
||||
@@ -85,5 +77,4 @@ M.rand_colorscheme = function()
|
||||
end
|
||||
end
|
||||
|
||||
-- Load a random colorscheme
|
||||
M.rand_colorscheme()
|
||||
return M
|
||||
|
||||
@@ -8,7 +8,7 @@ gs.setup {
|
||||
topdelete = { text = "‾" },
|
||||
changedelete = { text = "│" },
|
||||
},
|
||||
word_diff = true,
|
||||
word_diff = false,
|
||||
on_attach = function(bufnr)
|
||||
local function map(mode, l, r, opts)
|
||||
opts = opts or {}
|
||||
@@ -38,10 +38,10 @@ gs.setup {
|
||||
end, { expr = true, desc = "previous hunk" })
|
||||
|
||||
-- Actions
|
||||
map("n", "<leader>hp", gs.preview_hunk)
|
||||
map("n", "<leader>hp", gs.preview_hunk, { desc = "preview hunk" })
|
||||
map("n", "<leader>hb", function()
|
||||
gs.blame_line { full = true }
|
||||
end)
|
||||
end, { desc = "blame hunk" })
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
12
lua/config/glance.lua
Normal file
12
lua/config/glance.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local glance = require("glance")
|
||||
|
||||
glance.setup {
|
||||
height = 25,
|
||||
border = {
|
||||
enable = true,
|
||||
},
|
||||
}
|
||||
|
||||
vim.keymap.set("n", "<space>gd", "<cmd>Glance definitions<cr>")
|
||||
vim.keymap.set("n", "<space>gr", "<cmd>Glance references<cr>")
|
||||
vim.keymap.set("n", "<space>gi", "<cmd>Glance implementations<cr>")
|
||||
@@ -16,7 +16,7 @@ local activate_hlslens = function(direction)
|
||||
if not status then
|
||||
local start_idx, _ = string.find(msg, "E486", 1, true)
|
||||
local msg_part = string.sub(msg, start_idx)
|
||||
api.nvim_err_writeln(msg_part)
|
||||
api.nvim_echo({ { msg_part } }, true, { err = true })
|
||||
return
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ local check_cursor_word = function()
|
||||
local result = cursor_word == ""
|
||||
if result then
|
||||
local msg = "E348: No string under cursor"
|
||||
api.nvim_err_writeln(msg)
|
||||
api.nvim_echo({ { msg } }, true, { err = true })
|
||||
end
|
||||
|
||||
return result, cursor_word
|
||||
|
||||
@@ -1,24 +1,10 @@
|
||||
local fn = vim.fn
|
||||
local api = vim.api
|
||||
local keymap = vim.keymap
|
||||
local lsp = vim.lsp
|
||||
local diagnostic = vim.diagnostic
|
||||
local lspconfig = require("lspconfig")
|
||||
|
||||
local utils = require("utils")
|
||||
|
||||
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
|
||||
local set_qflist = function(buf_num, severity)
|
||||
local diagnostics = nil
|
||||
diagnostics = diagnostic.get(buf_num, { severity = severity })
|
||||
|
||||
local qf_items = diagnostic.toqflist(diagnostics)
|
||||
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
|
||||
|
||||
-- open quickfix by default
|
||||
vim.cmd([[copen]])
|
||||
end
|
||||
|
||||
local custom_attach = function(client, bufnr)
|
||||
-- Mappings.
|
||||
local map = function(mode, l, r, opts)
|
||||
@@ -30,18 +16,11 @@ local custom_attach = function(client, bufnr)
|
||||
|
||||
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
|
||||
map("n", "<C-]>", vim.lsp.buf.definition)
|
||||
map("n", "K", vim.lsp.buf.hover)
|
||||
map("n", "K", function()
|
||||
vim.lsp.buf.hover { border = "single", max_height = 25, max_width = 120 }
|
||||
end)
|
||||
map("n", "<C-k>", vim.lsp.buf.signature_help)
|
||||
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
|
||||
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
|
||||
map("n", "[d", diagnostic.goto_prev, { desc = "previous diagnostic" })
|
||||
map("n", "]d", diagnostic.goto_next, { desc = "next diagnostic" })
|
||||
-- this puts diagnostics from opened files to quickfix
|
||||
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
||||
-- 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>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
|
||||
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
|
||||
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
|
||||
@@ -58,41 +37,8 @@ local custom_attach = function(client, bufnr)
|
||||
-- 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", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
local float_opts = {
|
||||
focusable = false,
|
||||
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
|
||||
border = "rounded",
|
||||
source = "always", -- show source in diagnostic popup window
|
||||
prefix = " ",
|
||||
}
|
||||
|
||||
if not vim.b.diagnostics_pos then
|
||||
vim.b.diagnostics_pos = { nil, nil }
|
||||
end
|
||||
|
||||
local cursor_pos = api.nvim_win_get_cursor(0)
|
||||
if
|
||||
(cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
|
||||
and #diagnostic.get() > 0
|
||||
then
|
||||
diagnostic.open_float(nil, float_opts)
|
||||
end
|
||||
|
||||
vim.b.diagnostics_pos = cursor_pos
|
||||
end,
|
||||
})
|
||||
|
||||
-- The blow command will highlight the current variable and its usages in the buffer.
|
||||
if client.server_capabilities.documentHighlightProvider then
|
||||
vim.cmd([[
|
||||
hi! link LspReferenceRead Visual
|
||||
hi! link LspReferenceText Visual
|
||||
hi! link LspReferenceWrite Visual
|
||||
]])
|
||||
|
||||
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||
api.nvim_create_autocmd("CursorHold", {
|
||||
group = gid,
|
||||
@@ -117,7 +63,7 @@ local custom_attach = function(client, bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
-- required by nvim-ufo
|
||||
capabilities.textDocument.foldingRange = {
|
||||
@@ -277,29 +223,3 @@ if utils.executable("lua-language-server") then
|
||||
capabilities = capabilities,
|
||||
}
|
||||
end
|
||||
|
||||
-- Change diagnostic signs.
|
||||
fn.sign_define("DiagnosticSignError", { text = "🆇", texthl = "DiagnosticSignError" })
|
||||
fn.sign_define("DiagnosticSignWarn", { text = "⚠️", texthl = "DiagnosticSignWarn" })
|
||||
fn.sign_define("DiagnosticSignInfo", { text = "ℹ️", texthl = "DiagnosticSignInfo" })
|
||||
fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
|
||||
|
||||
-- global config for diagnostic
|
||||
diagnostic.config {
|
||||
underline = false,
|
||||
virtual_text = false,
|
||||
signs = true,
|
||||
severity_sort = true,
|
||||
}
|
||||
|
||||
-- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, {
|
||||
-- underline = false,
|
||||
-- virtual_text = false,
|
||||
-- signs = true,
|
||||
-- update_in_insert = false,
|
||||
-- })
|
||||
|
||||
-- Change border of documentation hover window, See https://github.com/neovim/neovim/pull/13998.
|
||||
lsp.handlers["textDocument/hover"] = lsp.with(vim.lsp.handlers.hover, {
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
@@ -1,5 +1,70 @@
|
||||
local fn = vim.fn
|
||||
|
||||
local git_status_cache = {}
|
||||
|
||||
local on_exit_fetch = function(result)
|
||||
if result.code == 0 then
|
||||
git_status_cache.fetch_success = true
|
||||
end
|
||||
end
|
||||
|
||||
local function handle_numeric_result(cache_key)
|
||||
return function(result)
|
||||
if result.code == 0 then
|
||||
git_status_cache[cache_key] = tonumber(result.stdout:match("(%d+)")) or 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local async_cmd = function(cmd_str, on_exit)
|
||||
local cmd = vim.tbl_filter(function(element)
|
||||
return element ~= ""
|
||||
end, vim.split(cmd_str, " "))
|
||||
|
||||
vim.system(cmd, { text = true }, on_exit)
|
||||
end
|
||||
|
||||
local async_git_status_update = function()
|
||||
-- Fetch the latest changes from the remote repository (replace 'origin' if needed)
|
||||
async_cmd("git fetch origin", on_exit_fetch)
|
||||
if not git_status_cache.fetch_success then
|
||||
return
|
||||
end
|
||||
|
||||
-- Get the number of commits behind
|
||||
-- the @{upstream} notation is inspired by post: https://www.reddit.com/r/neovim/comments/t48x5i/git_branch_aheadbehind_info_status_line_component/
|
||||
-- note that here we should use double dots instead of triple dots
|
||||
local behind_cmd_str = "git rev-list --count HEAD..@{upstream}"
|
||||
async_cmd(behind_cmd_str, handle_numeric_result("behind_count"))
|
||||
|
||||
-- Get the number of commits ahead
|
||||
local ahead_cmd_str = "git rev-list --count @{upstream}..HEAD"
|
||||
async_cmd(ahead_cmd_str, handle_numeric_result("ahead_count"))
|
||||
end
|
||||
|
||||
local function get_git_ahead_behind_info()
|
||||
async_git_status_update()
|
||||
|
||||
local status = git_status_cache
|
||||
if not status then
|
||||
return ""
|
||||
end
|
||||
|
||||
local msg = ""
|
||||
|
||||
if type(status.ahead_count) == "number" and status.ahead_count > 0 then
|
||||
local ahead_str = string.format("↑[%d] ", status.ahead_count)
|
||||
msg = msg .. ahead_str
|
||||
end
|
||||
|
||||
if type(status.behind_count) == "number" and status.behind_count > 0 then
|
||||
local behind_str = string.format("↓[%d] ", status.behind_count)
|
||||
msg = msg .. behind_str
|
||||
end
|
||||
|
||||
return msg
|
||||
end
|
||||
|
||||
local function spell()
|
||||
if vim.o.spell then
|
||||
return string.format("[SPELL]")
|
||||
@@ -119,7 +184,7 @@ local virtual_env = function()
|
||||
end
|
||||
|
||||
local get_active_lsp = function()
|
||||
local msg = "No Active Lsp"
|
||||
local msg = "🚫"
|
||||
local buf_ft = vim.api.nvim_get_option_value("filetype", {})
|
||||
local clients = vim.lsp.get_clients { bufnr = 0 }
|
||||
if next(clients) == nil then
|
||||
@@ -144,10 +209,18 @@ require("lualine").setup {
|
||||
section_separators = "",
|
||||
disabled_filetypes = {},
|
||||
always_divide_middle = true,
|
||||
refresh = {
|
||||
statusline = 500,
|
||||
},
|
||||
},
|
||||
sections = {
|
||||
lualine_a = {
|
||||
"mode",
|
||||
{
|
||||
"filename",
|
||||
symbols = {
|
||||
readonly = "[🔒]",
|
||||
},
|
||||
},
|
||||
},
|
||||
lualine_b = {
|
||||
{
|
||||
@@ -159,21 +232,19 @@ require("lualine").setup {
|
||||
color = { gui = "italic,bold" },
|
||||
},
|
||||
{
|
||||
virtual_env,
|
||||
color = { fg = "black", bg = "#F1CA81" },
|
||||
},
|
||||
},
|
||||
lualine_c = {
|
||||
{
|
||||
"filename",
|
||||
symbols = {
|
||||
readonly = "[🔒]",
|
||||
},
|
||||
get_git_ahead_behind_info,
|
||||
color = { fg = "#E0C479" },
|
||||
},
|
||||
{
|
||||
"diff",
|
||||
source = diff,
|
||||
},
|
||||
{
|
||||
virtual_env,
|
||||
color = { fg = "black", bg = "#F1CA81" },
|
||||
},
|
||||
},
|
||||
lualine_c = {
|
||||
{
|
||||
"%S",
|
||||
color = { gui = "bold", fg = "cyan" },
|
||||
@@ -184,22 +255,29 @@ require("lualine").setup {
|
||||
},
|
||||
},
|
||||
lualine_x = {
|
||||
{
|
||||
ime_state,
|
||||
color = { fg = "black", bg = "#f46868" },
|
||||
},
|
||||
{
|
||||
get_active_lsp,
|
||||
icon = " LSP:",
|
||||
icon = "📡",
|
||||
},
|
||||
{
|
||||
"diagnostics",
|
||||
sources = { "nvim_diagnostic" },
|
||||
symbols = { error = "🆇 ", warn = "⚠️ ", info = "ℹ️ ", hint = " " },
|
||||
},
|
||||
{
|
||||
trailing_space,
|
||||
color = "WarningMsg",
|
||||
},
|
||||
{
|
||||
mixed_indent,
|
||||
color = "WarningMsg",
|
||||
},
|
||||
},
|
||||
lualine_y = {
|
||||
{ "encoding", fmt = string.upper },
|
||||
{
|
||||
"encoding",
|
||||
fmt = string.upper,
|
||||
},
|
||||
{
|
||||
"fileformat",
|
||||
symbols = {
|
||||
@@ -209,16 +287,12 @@ require("lualine").setup {
|
||||
},
|
||||
},
|
||||
"filetype",
|
||||
{
|
||||
ime_state,
|
||||
color = { fg = "black", bg = "#f46868" },
|
||||
},
|
||||
},
|
||||
lualine_z = {
|
||||
{
|
||||
trailing_space,
|
||||
color = "WarningMsg",
|
||||
},
|
||||
{
|
||||
mixed_indent,
|
||||
color = "WarningMsg",
|
||||
},
|
||||
"location",
|
||||
"progress",
|
||||
},
|
||||
|
||||
44
lua/config/treesitter-textobjects.lua
Normal file
44
lua/config/treesitter-textobjects.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
require("nvim-treesitter.configs").setup {
|
||||
textobjects = {
|
||||
select = {
|
||||
enable = true,
|
||||
|
||||
-- Automatically jump forward to textobj, similar to targets.vim
|
||||
lookahead = true,
|
||||
|
||||
keymaps = {
|
||||
-- You can use the capture groups defined in textobjects.scm
|
||||
["af"] = "@function.outer",
|
||||
["if"] = "@function.inner",
|
||||
["ac"] = "@class.outer",
|
||||
-- You can optionally set descriptions to the mappings (used in the desc parameter of
|
||||
-- nvim_buf_set_keymap) which plugins like which-key display
|
||||
["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
|
||||
},
|
||||
-- You can choose the select mode (default is charwise 'v')
|
||||
--
|
||||
-- Can also be a function which gets passed a table with the keys
|
||||
-- * query_string: eg '@function.inner'
|
||||
-- * method: eg 'v' or 'o'
|
||||
-- and should return the mode ('v', 'V', or '<c-v>') or a table
|
||||
-- mapping query_strings to modes.
|
||||
selection_modes = {
|
||||
["@function.inner"] = "V", -- linewise
|
||||
["@function.outer"] = "V", -- linewise
|
||||
["@class.outer"] = "V", -- linewise
|
||||
["@class.inner"] = "V", -- linewise
|
||||
["@parameter.outer"] = "v", -- charwise
|
||||
},
|
||||
-- If you set this to `true` (default is `false`) then any textobject is
|
||||
-- extended to include preceding or succeeding whitespace. Succeeding
|
||||
-- whitespace has priority in order to act similarly to eg the built-in
|
||||
-- `ap`.
|
||||
--
|
||||
-- Can also be a function which gets passed a table with the keys
|
||||
-- * query_string: eg '@function.inner'
|
||||
-- * selection_mode: eg 'v'
|
||||
-- and should return true or false
|
||||
include_surrounding_whitespace = false,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -22,7 +22,7 @@ api.nvim_create_autocmd({ "TextYankPost" }, {
|
||||
pattern = "*",
|
||||
group = yank_group,
|
||||
callback = function()
|
||||
vim.highlight.on_yank { higroup = "YankColor", timeout = 300 }
|
||||
vim.hl.on_yank { higroup = "YankColor", timeout = 300 }
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -135,49 +135,6 @@ api.nvim_create_autocmd("TermOpen", {
|
||||
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 = "*",
|
||||
@@ -213,7 +170,11 @@ api.nvim_create_autocmd("ColorScheme", {
|
||||
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" })
|
||||
vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen", bg = "None", bold = true })
|
||||
|
||||
local hl = vim.api.nvim_get_hl(0, { name = "NormalFloat" })
|
||||
-- change the background color of floating window to None, so it blenders better
|
||||
vim.api.nvim_set_hl(0, "NormalFloat", { fg = hl.fg, bg = "None" })
|
||||
|
||||
-- highlight for matching parentheses
|
||||
vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true })
|
||||
@@ -249,14 +210,16 @@ 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()",
|
||||
callback = function()
|
||||
utils.inside_git_repo()
|
||||
end,
|
||||
})
|
||||
|
||||
-- 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",
|
||||
desc = "optimize for large file",
|
||||
callback = function(ev)
|
||||
local file_size_limit = 524288 -- 0.5MB
|
||||
local f = ev.file
|
||||
|
||||
66
lua/diagnostic-conf.lua
Normal file
66
lua/diagnostic-conf.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
local diagnostic = vim.diagnostic
|
||||
local api = vim.api
|
||||
|
||||
-- global config for diagnostic
|
||||
diagnostic.config {
|
||||
underline = false,
|
||||
virtual_text = false,
|
||||
virtual_lines = false,
|
||||
signs = {
|
||||
text = {
|
||||
[diagnostic.severity.ERROR] = "🆇",
|
||||
[diagnostic.severity.WARN] = "⚠️",
|
||||
[diagnostic.severity.INFO] = "ℹ️",
|
||||
[diagnostic.severity.HINT] = "",
|
||||
},
|
||||
},
|
||||
severity_sort = true,
|
||||
float = {
|
||||
source = true,
|
||||
header = "Diagnostics:",
|
||||
prefix = " ",
|
||||
border = "single",
|
||||
},
|
||||
}
|
||||
|
||||
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
|
||||
local set_qflist = function(buf_num, severity)
|
||||
local diagnostics = nil
|
||||
diagnostics = diagnostic.get(buf_num, { severity = severity })
|
||||
|
||||
local qf_items = diagnostic.toqflist(diagnostics)
|
||||
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
|
||||
|
||||
-- open quickfix by default
|
||||
vim.cmd([[copen]])
|
||||
end
|
||||
|
||||
-- this puts diagnostics from opened files to quickfix
|
||||
vim.keymap.set("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
|
||||
|
||||
-- this puts diagnostics from current buffer to quickfix
|
||||
vim.keymap.set("n", "<space>qb", function()
|
||||
set_qflist(0)
|
||||
end, { desc = "put buffer diagnostics to qf" })
|
||||
|
||||
-- automatically show diagnostic in float win for current line
|
||||
api.nvim_create_autocmd("CursorHold", {
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
if #vim.diagnostic.get(0) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
if not vim.b.diagnostics_pos then
|
||||
vim.b.diagnostics_pos = { nil, nil }
|
||||
end
|
||||
|
||||
local cursor_pos = api.nvim_win_get_cursor(0)
|
||||
|
||||
if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then
|
||||
diagnostic.open_float { width = 100 }
|
||||
end
|
||||
|
||||
vim.b.diagnostics_pos = cursor_pos
|
||||
end,
|
||||
})
|
||||
@@ -27,7 +27,8 @@ if utils.executable("python3") then
|
||||
vim.g.python3_host_prog = fn.exepath("python3")
|
||||
end
|
||||
else
|
||||
api.nvim_err_writeln("Python3 executable not found! You must install Python3 and set its PATH correctly!")
|
||||
local msg = "Python3 executable not found! You must install Python3 and set its PATH correctly!"
|
||||
api.nvim_echo({ { msg } }, true, { err = true })
|
||||
return
|
||||
end
|
||||
|
||||
@@ -68,3 +69,6 @@ vim.g.loaded_matchparen = 1
|
||||
|
||||
-- Disable sql omni completion, it is broken.
|
||||
vim.g.loaded_sql_completion = 1
|
||||
|
||||
-- control how to show health check window
|
||||
vim.g.health = { style = nil }
|
||||
|
||||
@@ -23,19 +23,6 @@ keymap.set("n", "<leader>q", "<cmd>x<cr>", { silent = true, desc = "quit current
|
||||
-- Quit all opened buffers
|
||||
keymap.set("n", "<leader>Q", "<cmd>qa!<cr>", { silent = true, desc = "quit nvim" })
|
||||
|
||||
-- Navigation in the location and quickfix list
|
||||
keymap.set("n", "[l", "<cmd>lprevious<cr>zv", { silent = true, desc = "previous location item" })
|
||||
keymap.set("n", "]l", "<cmd>lnext<cr>zv", { silent = true, desc = "next location item" })
|
||||
|
||||
keymap.set("n", "[L", "<cmd>lfirst<cr>zv", { silent = true, desc = "first location item" })
|
||||
keymap.set("n", "]L", "<cmd>llast<cr>zv", { silent = true, desc = "last location item" })
|
||||
|
||||
keymap.set("n", "[q", "<cmd>cprevious<cr>zv", { silent = true, desc = "previous qf item" })
|
||||
keymap.set("n", "]q", "<cmd>cnext<cr>zv", { silent = true, desc = "next qf item" })
|
||||
|
||||
keymap.set("n", "[Q", "<cmd>cfirst<cr>zv", { silent = true, desc = "first qf item" })
|
||||
keymap.set("n", "]Q", "<cmd>clast<cr>zv", { silent = true, desc = "last qf item" })
|
||||
|
||||
-- Close location list or quickfix list if they are present, see https://superuser.com/q/355325/736190
|
||||
keymap.set("n", [[\x]], "<cmd>windo lclose <bar> cclose <cr>", {
|
||||
silent = true,
|
||||
@@ -143,9 +130,6 @@ keymap.set("x", "c", '"_c')
|
||||
-- Remove trailing whitespace characters
|
||||
keymap.set("n", "<leader><space>", "<cmd>StripTrailingWhitespace<cr>", { desc = "remove trailing space" })
|
||||
|
||||
-- check the syntax group of current cursor position
|
||||
keymap.set("n", "<leader>st", "<cmd>call utils#SynGroup()<cr>", { desc = "check syntax group" })
|
||||
|
||||
-- Copy entire buffer.
|
||||
keymap.set("n", "<leader>y", "<cmd>%yank<cr>", { desc = "yank entire buffer" })
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ end
|
||||
local plugin_specs = {
|
||||
-- auto-completion engine
|
||||
{
|
||||
"iguanacucumber/magazine.nvim",
|
||||
"hrsh7th/nvim-cmp",
|
||||
name = "nvim-cmp",
|
||||
-- event = 'InsertEnter',
|
||||
event = "VeryLazy",
|
||||
@@ -39,6 +39,7 @@ local plugin_specs = {
|
||||
require("config.nvim-cmp")
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufRead", "BufNewFile" },
|
||||
@@ -46,25 +47,29 @@ local plugin_specs = {
|
||||
require("config.lsp")
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"dnlhc/glance.nvim",
|
||||
config = function()
|
||||
require("config.glance")
|
||||
end,
|
||||
envnt = "VeryLazy",
|
||||
},
|
||||
{
|
||||
"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" } },
|
||||
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||
event = "VeryLazy",
|
||||
branch = "master",
|
||||
config = function()
|
||||
require("config.treesitter-textobjects")
|
||||
end,
|
||||
},
|
||||
{ "machakann/vim-swap", event = "VeryLazy" },
|
||||
|
||||
-- IDE for Lisp
|
||||
@@ -278,15 +283,9 @@ local plugin_specs = {
|
||||
-- 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",
|
||||
@@ -387,7 +386,7 @@ local plugin_specs = {
|
||||
end
|
||||
return false
|
||||
end,
|
||||
build = "cd app && npm install",
|
||||
build = "cd app && npm install && git restore .",
|
||||
ft = { "markdown" },
|
||||
},
|
||||
|
||||
@@ -513,7 +512,23 @@ local plugin_specs = {
|
||||
require("config.which-key")
|
||||
end,
|
||||
},
|
||||
|
||||
{
|
||||
"folke/snacks.nvim",
|
||||
priority = 1000,
|
||||
lazy = false,
|
||||
opts = {
|
||||
-- more beautiful vim.ui.input
|
||||
input = {
|
||||
enabled = true,
|
||||
win = {
|
||||
relative = "cursor",
|
||||
backdrop = true,
|
||||
},
|
||||
},
|
||||
-- more beautiful vim.ui.select
|
||||
picker = { enabled = true },
|
||||
},
|
||||
},
|
||||
-- show and trim trailing whitespaces
|
||||
{ "jdhao/whitespace.nvim", event = "VeryLazy" },
|
||||
|
||||
@@ -580,14 +595,6 @@ local plugin_specs = {
|
||||
{
|
||||
"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
|
||||
},
|
||||
},
|
||||
{
|
||||
"catgoose/nvim-colorizer.lua",
|
||||
event = "BufReadPre",
|
||||
|
||||
@@ -61,7 +61,7 @@ function M.is_compatible_version(expected_version)
|
||||
|
||||
if expect_ver == nil then
|
||||
local msg = string.format("Unsupported version string: %s", expected_version)
|
||||
vim.api.nvim_err_writeln(msg)
|
||||
vim.api.nvim_echo({ { msg } }, true, { err = true })
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -73,10 +73,24 @@ function M.is_compatible_version(expected_version)
|
||||
expected_version,
|
||||
_ver
|
||||
)
|
||||
vim.api.nvim_err_writeln(msg)
|
||||
vim.api.nvim_echo({ { msg } }, true, { err = true })
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- check if we are inside a git repo
|
||||
--- @return boolean
|
||||
function M.inside_git_repo()
|
||||
local result = vim.system({ "git", "rev-parse", "--is-inside-work-tree" }, { text = true }):wait()
|
||||
if result.code ~= 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Manually trigger a special user autocmd InGitRepo (used lazyloading.
|
||||
vim.cmd([[doautocmd User InGitRepo]])
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -50,7 +50,8 @@ vim.api.nvim_create_user_command("JSONFormat", function(context)
|
||||
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))
|
||||
local msg = string.format("unsupported range: %s", range)
|
||||
vim.api.nvim_echo({ { msg } }, true, { err = true })
|
||||
end
|
||||
end, {
|
||||
desc = "Format JSON string",
|
||||
|
||||
@@ -72,7 +72,7 @@ set wildmode=list:longest
|
||||
set scrolloff=3
|
||||
|
||||
" Use mouse to select and resize windows, etc.
|
||||
set mouse=
|
||||
set mouse=n
|
||||
set mousemodel=popup " Set the behaviour of mouse
|
||||
set mousescroll=ver:1,hor:0
|
||||
|
||||
@@ -115,6 +115,8 @@ set shortmess+=S
|
||||
" Disable showing intro message (:intro)
|
||||
set shortmess+=I
|
||||
|
||||
set messagesopt=wait:5000,history:500
|
||||
|
||||
" Completion behaviour
|
||||
" set completeopt+=noinsert " Auto select the first completion entry
|
||||
set completeopt+=menuone " Show menu even if there is only one item
|
||||
@@ -124,6 +126,7 @@ set pumheight=10 " Maximum number of items to show in popup menu
|
||||
set pumblend=5 " pseudo transparency for completion menu
|
||||
|
||||
set winblend=0 " pseudo transparency for floating window
|
||||
set winborder=none
|
||||
|
||||
" Insert mode key word completion setting
|
||||
set complete+=kspell complete-=w complete-=b complete-=u complete-=t
|
||||
|
||||
@@ -384,6 +384,3 @@ function! s:wilder_init() abort
|
||||
echohl Error |echomsg "Wilder.nvim missing"| echohl None
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
""""""""""""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""""""""""
|
||||
let g:auto_save = 1 " enable AutoSave on Vim startup
|
||||
|
||||
Reference in New Issue
Block a user