mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
1 Commits
ad40e54076
...
5cedd32ba3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cedd32ba3 |
@ -10,6 +10,23 @@ function! s:Single_quote(str) abort
|
|||||||
return "'" . substitute(copy(a:str), "'", "''", 'g') . "'"
|
return "'" . substitute(copy(a:str), "'", "''", 'g') . "'"
|
||||||
endfunction
|
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
|
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
|
||||||
function! utils#VimFolds(lnum) abort
|
function! utils#VimFolds(lnum) abort
|
||||||
" get content of current line and the line below
|
" get content of current line and the line below
|
||||||
@ -129,6 +146,27 @@ function! utils#iso_time(timestamp) abort
|
|||||||
|
|
||||||
endfunction
|
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.
|
" Redirect command output to a register for later processing.
|
||||||
" Ref: https://stackoverflow.com/q/2573021/6064933 and https://unix.stackexchange.com/q/8101/221410 .
|
" Ref: https://stackoverflow.com/q/2573021/6064933 and https://unix.stackexchange.com/q/8101/221410 .
|
||||||
function! utils#CaptureCommandOutput(command) abort
|
function! utils#CaptureCommandOutput(command) abort
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
--- This module will load a random colorscheme on nvim startup process.
|
--- This module will load a random colorscheme on nvim startup process.
|
||||||
|
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -7,14 +8,9 @@ local M = {}
|
|||||||
-- the same as the colorscheme name itself.
|
-- the same as the colorscheme name itself.
|
||||||
M.colorscheme_conf = {
|
M.colorscheme_conf = {
|
||||||
onedark = function()
|
onedark = function()
|
||||||
-- Lua
|
vim.cmd([[colorscheme onedark]])
|
||||||
require("onedark").setup {
|
|
||||||
style = "darker",
|
|
||||||
}
|
|
||||||
require("onedark").load()
|
|
||||||
end,
|
end,
|
||||||
edge = function()
|
edge = function()
|
||||||
vim.g.edge_style = "default"
|
|
||||||
vim.g.edge_enable_italic = 1
|
vim.g.edge_enable_italic = 1
|
||||||
vim.g.edge_better_performance = 1
|
vim.g.edge_better_performance = 1
|
||||||
|
|
||||||
@ -30,14 +26,13 @@ M.colorscheme_conf = {
|
|||||||
-- foreground option can be material, mix, or original
|
-- foreground option can be material, mix, or original
|
||||||
vim.g.gruvbox_material_foreground = "original"
|
vim.g.gruvbox_material_foreground = "original"
|
||||||
--background option can be hard, medium, soft
|
--background option can be hard, medium, soft
|
||||||
vim.g.gruvbox_material_background = "hard"
|
vim.g.gruvbox_material_background = "medium"
|
||||||
vim.g.gruvbox_material_enable_italic = 1
|
vim.g.gruvbox_material_enable_italic = 1
|
||||||
vim.g.gruvbox_material_better_performance = 1
|
vim.g.gruvbox_material_better_performance = 1
|
||||||
|
|
||||||
vim.cmd([[colorscheme gruvbox-material]])
|
vim.cmd([[colorscheme gruvbox-material]])
|
||||||
end,
|
end,
|
||||||
everforest = function()
|
everforest = function()
|
||||||
vim.g.everforest_background = "hard"
|
|
||||||
vim.g.everforest_enable_italic = 1
|
vim.g.everforest_enable_italic = 1
|
||||||
vim.g.everforest_better_performance = 1
|
vim.g.everforest_better_performance = 1
|
||||||
|
|
||||||
@ -55,11 +50,10 @@ M.colorscheme_conf = {
|
|||||||
end,
|
end,
|
||||||
onedarkpro = function()
|
onedarkpro = function()
|
||||||
-- set colorscheme after options
|
-- set colorscheme after options
|
||||||
-- onedark_vivid does not enough contrast
|
vim.cmd("colorscheme onedark_vivid")
|
||||||
vim.cmd("colorscheme onedark_dark")
|
|
||||||
end,
|
end,
|
||||||
material = function()
|
material = function()
|
||||||
vim.g.material_style = "darker"
|
vim.g.material_style = "oceanic"
|
||||||
vim.cmd("colorscheme material")
|
vim.cmd("colorscheme material")
|
||||||
end,
|
end,
|
||||||
arctic = function()
|
arctic = function()
|
||||||
@ -73,7 +67,6 @@ M.colorscheme_conf = {
|
|||||||
--- Use a random colorscheme from the pre-defined list of colorschemes.
|
--- Use a random colorscheme from the pre-defined list of colorschemes.
|
||||||
M.rand_colorscheme = function()
|
M.rand_colorscheme = function()
|
||||||
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
|
local colorscheme = utils.rand_element(vim.tbl_keys(M.colorscheme_conf))
|
||||||
colorscheme = "gruvbox_material"
|
|
||||||
|
|
||||||
if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then
|
if not vim.tbl_contains(vim.tbl_keys(M.colorscheme_conf), colorscheme) then
|
||||||
local msg = "Invalid colorscheme: " .. colorscheme
|
local msg = "Invalid colorscheme: " .. colorscheme
|
||||||
|
|||||||
@ -8,7 +8,7 @@ gs.setup {
|
|||||||
topdelete = { text = "‾" },
|
topdelete = { text = "‾" },
|
||||||
changedelete = { text = "│" },
|
changedelete = { text = "│" },
|
||||||
},
|
},
|
||||||
word_diff = false,
|
word_diff = true,
|
||||||
on_attach = function(bufnr)
|
on_attach = function(bufnr)
|
||||||
local function map(mode, l, r, opts)
|
local function map(mode, l, r, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
@ -38,10 +38,10 @@ gs.setup {
|
|||||||
end, { expr = true, desc = "previous hunk" })
|
end, { expr = true, desc = "previous hunk" })
|
||||||
|
|
||||||
-- Actions
|
-- Actions
|
||||||
map("n", "<leader>hp", gs.preview_hunk, { desc = "preview hunk" })
|
map("n", "<leader>hp", gs.preview_hunk)
|
||||||
map("n", "<leader>hb", function()
|
map("n", "<leader>hb", function()
|
||||||
gs.blame_line { full = true }
|
gs.blame_line { full = true }
|
||||||
end, { desc = "blame hunk" })
|
end)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -117,7 +117,7 @@ local custom_attach = function(client, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
|
|
||||||
-- required by nvim-ufo
|
-- required by nvim-ufo
|
||||||
capabilities.textDocument.foldingRange = {
|
capabilities.textDocument.foldingRange = {
|
||||||
|
|||||||
@ -42,9 +42,7 @@ local async_git_status_update = function()
|
|||||||
async_cmd(ahead_cmd_str, handle_numeric_result("ahead_count"))
|
async_cmd(ahead_cmd_str, handle_numeric_result("ahead_count"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_git_ahead_behind_info()
|
local function get_ahead_behind_info()
|
||||||
async_git_status_update()
|
|
||||||
|
|
||||||
local status = git_status_cache
|
local status = git_status_cache
|
||||||
if not status then
|
if not status then
|
||||||
return ""
|
return ""
|
||||||
@ -65,6 +63,9 @@ local function get_git_ahead_behind_info()
|
|||||||
return msg
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local timer = vim.loop.new_timer()
|
||||||
|
timer:start(0, 1000, async_git_status_update)
|
||||||
|
|
||||||
local function spell()
|
local function spell()
|
||||||
if vim.o.spell then
|
if vim.o.spell then
|
||||||
return string.format("[SPELL]")
|
return string.format("[SPELL]")
|
||||||
@ -209,9 +210,6 @@ require("lualine").setup {
|
|||||||
section_separators = "",
|
section_separators = "",
|
||||||
disabled_filetypes = {},
|
disabled_filetypes = {},
|
||||||
always_divide_middle = true,
|
always_divide_middle = true,
|
||||||
refresh = {
|
|
||||||
statusline = 500,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
sections = {
|
sections = {
|
||||||
lualine_a = {
|
lualine_a = {
|
||||||
@ -232,7 +230,7 @@ require("lualine").setup {
|
|||||||
color = { gui = "italic,bold" },
|
color = { gui = "italic,bold" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
get_git_ahead_behind_info,
|
get_ahead_behind_info,
|
||||||
color = { fg = "#E0C479" },
|
color = { fg = "#E0C479" },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@ -213,16 +213,14 @@ api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, {
|
|||||||
group = api.nvim_create_augroup("git_repo_check", { clear = true }),
|
group = api.nvim_create_augroup("git_repo_check", { clear = true }),
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
desc = "check if we are inside Git repo",
|
desc = "check if we are inside Git repo",
|
||||||
callback = function()
|
command = "call utils#Inside_git_repo()",
|
||||||
utils.inside_git_repo()
|
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- ref: https://vi.stackexchange.com/a/169/15292
|
-- ref: https://vi.stackexchange.com/a/169/15292
|
||||||
api.nvim_create_autocmd("BufReadPre", {
|
api.nvim_create_autocmd("BufReadPre", {
|
||||||
group = api.nvim_create_augroup("large_file", { clear = true }),
|
group = api.nvim_create_augroup("large_file", { clear = true }),
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
desc = "optimize for large file",
|
desc = "check if we are inside Git repo",
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
local file_size_limit = 524288 -- 0.5MB
|
local file_size_limit = 524288 -- 0.5MB
|
||||||
local f = ev.file
|
local f = ev.file
|
||||||
|
|||||||
@ -143,6 +143,9 @@ keymap.set("x", "c", '"_c')
|
|||||||
-- Remove trailing whitespace characters
|
-- Remove trailing whitespace characters
|
||||||
keymap.set("n", "<leader><space>", "<cmd>StripTrailingWhitespace<cr>", { desc = "remove trailing space" })
|
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.
|
-- Copy entire buffer.
|
||||||
keymap.set("n", "<leader>y", "<cmd>%yank<cr>", { desc = "yank entire buffer" })
|
keymap.set("n", "<leader>y", "<cmd>%yank<cr>", { desc = "yank entire buffer" })
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ end
|
|||||||
local plugin_specs = {
|
local plugin_specs = {
|
||||||
-- auto-completion engine
|
-- auto-completion engine
|
||||||
{
|
{
|
||||||
"hrsh7th/nvim-cmp",
|
"iguanacucumber/magazine.nvim",
|
||||||
name = "nvim-cmp",
|
name = "nvim-cmp",
|
||||||
-- event = 'InsertEnter',
|
-- event = 'InsertEnter',
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
@ -39,7 +39,6 @@ local plugin_specs = {
|
|||||||
require("config.nvim-cmp")
|
require("config.nvim-cmp")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
event = { "BufRead", "BufNewFile" },
|
event = { "BufRead", "BufNewFile" },
|
||||||
@ -62,14 +61,10 @@ local plugin_specs = {
|
|||||||
require("config.treesitter")
|
require("config.treesitter")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
-- Python-related text object
|
||||||
event = "VeryLazy",
|
{ "jeetsukumaran/vim-pythonsense", ft = { "python" } },
|
||||||
branch = "master",
|
|
||||||
config = function()
|
|
||||||
require("config.treesitter-textobjects")
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
{ "machakann/vim-swap", event = "VeryLazy" },
|
{ "machakann/vim-swap", event = "VeryLazy" },
|
||||||
|
|
||||||
-- IDE for Lisp
|
-- IDE for Lisp
|
||||||
@ -386,7 +381,7 @@ local plugin_specs = {
|
|||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
build = "cd app && npm install && git restore .",
|
build = "cd app && npm install",
|
||||||
ft = { "markdown" },
|
ft = { "markdown" },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -79,18 +79,4 @@ function M.is_compatible_version(expected_version)
|
|||||||
return true
|
return true
|
||||||
end
|
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
|
return M
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user