mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
7 Commits
fe95658319
...
b30cc9ed78
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b30cc9ed78 | ||
|
|
b3a26e4226 | ||
|
|
794b098090 | ||
|
|
b728b39784 | ||
|
|
acc3ed7829 | ||
|
|
44e9e5a1ce | ||
|
|
5502d29f40 |
@ -3,7 +3,3 @@ set formatoptions-=o
|
|||||||
set formatoptions-=r
|
set formatoptions-=r
|
||||||
|
|
||||||
nnoremap <buffer><silent> <F9> :luafile %<CR>
|
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 softtabstop=4 " number of spaces in tab when editing
|
||||||
set shiftwidth=4 " number of spaces to use for autoindent
|
set shiftwidth=4 " number of spaces to use for autoindent
|
||||||
set expandtab " expand tab to spaces so that tabs are spaces
|
set expandtab " expand tab to spaces so that tabs are spaces
|
||||||
|
|
||||||
" Use nvim-treesitter for folding
|
|
||||||
set foldmethod=expr
|
|
||||||
set foldexpr=nvim_treesitter#foldexpr()
|
|
||||||
|
|||||||
14
init.lua
14
init.lua
@ -14,15 +14,21 @@ vim.loader.enable()
|
|||||||
local version = vim.version
|
local version = vim.version
|
||||||
|
|
||||||
-- check if we have the latest stable version of nvim
|
-- check if we have the latest stable version of nvim
|
||||||
local expected_ver = "0.10.1"
|
local expected_ver_str = "0.10.1"
|
||||||
local expect_ver = version.parse(expected_ver)
|
local expect_ver = version.parse(expected_ver_str)
|
||||||
local actual_ver = version()
|
local actual_ver = vim.version()
|
||||||
|
|
||||||
|
if expect_ver == nil then
|
||||||
|
local msg = string.format("Unsupported version string: %s", expected_ver_str)
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local result = version.cmp(expect_ver, actual_ver)
|
local result = version.cmp(expect_ver, actual_ver)
|
||||||
|
|
||||||
if result ~= 0 then
|
if result ~= 0 then
|
||||||
local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch)
|
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)
|
local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver_str, _ver)
|
||||||
vim.api.nvim_err_writeln(msg)
|
vim.api.nvim_err_writeln(msg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ 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>gd", "<cmd>Gdiffsplit<cr>", { desc = "Git diff" })
|
||||||
keymap.set("n", "<leader>gpl", "<cmd>Git pull<cr>", { desc = "Git pull" })
|
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>gpu", "<cmd>15 split|term git push<cr>", { desc = "Git push" })
|
||||||
|
keymap.set("v", "<leader>gb", ":Git blame<cr>", { desc = "Git blame line" })
|
||||||
|
|
||||||
-- convert git to Git in command line mode
|
-- convert git to Git in command line mode
|
||||||
vim.fn['utils#Cabbrev']('git', 'Git')
|
vim.fn["utils#Cabbrev"]("git", "Git")
|
||||||
|
|||||||
@ -36,11 +36,15 @@ keymap.set("n", "N", "", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
local no_word_under_cursor = function()
|
local no_word_under_cursor = function()
|
||||||
local word_under_cursor = vim.fn.expand("<cword>")
|
local cursor_word = vim.fn.expand("<cword>")
|
||||||
|
|
||||||
|
local result = cursor_word == ""
|
||||||
|
if result then
|
||||||
local msg = "E348: No string under cursor"
|
local msg = "E348: No string under cursor"
|
||||||
api.nvim_err_writeln(msg)
|
api.nvim_err_writeln(msg)
|
||||||
return word_under_cursor == ""
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
keymap.set("n", "*", "", {
|
keymap.set("n", "*", "", {
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
local handler = function(virtText, lnum, endLnum, width, truncate)
|
local handler = function(virtText, lnum, endLnum, width, truncate)
|
||||||
local newVirtText = {}
|
local newVirtText = {}
|
||||||
local totalLines = vim.api.nvim_buf_line_count(0)
|
|
||||||
local foldedLines = endLnum - lnum
|
local foldedLines = endLnum - lnum
|
||||||
local suffix = (" %d"):format(foldedLines)
|
local suffix = (" %d"):format(foldedLines)
|
||||||
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
||||||
|
|||||||
@ -127,6 +127,7 @@ local get_active_lsp = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
local filetypes = client.config.filetypes
|
local filetypes = client.config.filetypes
|
||||||
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
|
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
|
||||||
return client.name
|
return client.name
|
||||||
@ -149,7 +150,7 @@ require("lualine").setup {
|
|||||||
lualine_b = {
|
lualine_b = {
|
||||||
{
|
{
|
||||||
"branch",
|
"branch",
|
||||||
fmt = function(name, context)
|
fmt = function(name, _)
|
||||||
-- truncate branch name in case the name is too long
|
-- truncate branch name in case the name is too long
|
||||||
return string.sub(name, 1, 20)
|
return string.sub(name, 1, 20)
|
||||||
end,
|
end,
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
local keymap = vim.keymap
|
local keymap = vim.keymap
|
||||||
local api = vim.api
|
|
||||||
local uv = vim.uv
|
local uv = vim.uv
|
||||||
|
|
||||||
-- Save key strokes (now we do not need to press shift to enter command mode).
|
-- Save key strokes (now we do not need to press shift to enter command mode).
|
||||||
@ -215,6 +214,9 @@ keymap.set("n", "<leader>cb", function()
|
|||||||
local cnt = 0
|
local cnt = 0
|
||||||
local blink_times = 7
|
local blink_times = 7
|
||||||
local timer = uv.new_timer()
|
local timer = uv.new_timer()
|
||||||
|
if timer == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
timer:start(0, 100, vim.schedule_wrap(function()
|
timer:start(0, 100, vim.schedule_wrap(function()
|
||||||
vim.cmd [[
|
vim.cmd [[
|
||||||
|
|||||||
@ -194,9 +194,9 @@ local plugin_specs = {
|
|||||||
require("statuscol").setup {
|
require("statuscol").setup {
|
||||||
relculright = true,
|
relculright = true,
|
||||||
segments = {
|
segments = {
|
||||||
{ text = { builtin.foldfunc }, click = "v:lua.ScFa" },
|
|
||||||
{ text = { "%s" }, click = "v:lua.ScSa" },
|
{ text = { "%s" }, click = "v:lua.ScSa" },
|
||||||
{ text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
|
{ text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
|
||||||
|
{ text = { builtin.foldfunc, " " }, condition = {true, builtin.not_empty}, click = "v:lua.ScFa" },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
@ -527,7 +527,7 @@ local plugin_specs = {
|
|||||||
-- file explorer
|
-- file explorer
|
||||||
{
|
{
|
||||||
"nvim-tree/nvim-tree.lua",
|
"nvim-tree/nvim-tree.lua",
|
||||||
keys = { "<space>s" },
|
event = "VeryLazy",
|
||||||
dependencies = { "nvim-tree/nvim-web-devicons" },
|
dependencies = { "nvim-tree/nvim-web-devicons" },
|
||||||
config = function()
|
config = function()
|
||||||
require("config.nvim-tree")
|
require("config.nvim-tree")
|
||||||
|
|||||||
@ -11,9 +11,8 @@ function M.executable(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- check whether a feature exists in Nvim
|
--- check whether a feature exists in Nvim
|
||||||
--- @feat: string
|
--- @param feat string the feature name, like `nvim-0.7` or `unix`.
|
||||||
--- the feature name, like `nvim-0.7` or `unix`.
|
--- @return boolean
|
||||||
--- return: bool
|
|
||||||
M.has = function(feat)
|
M.has = function(feat)
|
||||||
if fn.has(feat) == 1 then
|
if fn.has(feat) == 1 then
|
||||||
return true
|
return true
|
||||||
@ -33,8 +32,9 @@ end
|
|||||||
|
|
||||||
--- Generate random integers in the range [Low, High], inclusive,
|
--- Generate random integers in the range [Low, High], inclusive,
|
||||||
--- adapted from https://stackoverflow.com/a/12739441/6064933
|
--- adapted from https://stackoverflow.com/a/12739441/6064933
|
||||||
--- @low: the lower value for this range
|
--- @param low integer the lower value for this range
|
||||||
--- @high: the upper value for this range
|
--- @param high integer the upper value for this range
|
||||||
|
--- @return integer
|
||||||
function M.rand_int(low, high)
|
function M.rand_int(low, high)
|
||||||
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
|
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
@ -43,17 +43,11 @@ function M.rand_int(low, high)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Select a random element from a sequence/list.
|
--- Select a random element from a sequence/list.
|
||||||
--- @seq: the sequence to choose an element
|
--- @param seq any[] the sequence to choose an element
|
||||||
function M.rand_element(seq)
|
function M.rand_element(seq)
|
||||||
local idx = M.rand_int(1, #seq)
|
local idx = M.rand_int(1, #seq)
|
||||||
|
|
||||||
return seq[idx]
|
return seq[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.add_pack(name)
|
|
||||||
local status, error = pcall(vim.cmd, "packadd " .. name)
|
|
||||||
|
|
||||||
return status
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@ -467,3 +467,6 @@ pylintrc
|
|||||||
PYTHONPATH
|
PYTHONPATH
|
||||||
Uvicorn
|
Uvicorn
|
||||||
qpdf
|
qpdf
|
||||||
|
Elasticsearch
|
||||||
|
kibana
|
||||||
|
submodule
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user