Skip to content

Commit

Permalink
feat!: cherry-picked applicable updates from master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jint-lzxy committed May 7, 2023
1 parent 0caead5 commit 0bda97c
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-cn.json",
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema-zh-tw.json",
"diagnostics": {
"globals": ["vim"],
"disable": ["different-requires"]
Expand Down
6 changes: 0 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
if not vim.g.vscode then
require("core")
end

--[[
Support sematic token once 0.9 is released!
]]
12 changes: 4 additions & 8 deletions lua/core/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,16 @@ function autocmd.load_autocmds()
{ "BufWritePre", "MERGE_MSG", "setlocal noundofile" },
{ "BufWritePre", "*.tmp", "setlocal noundofile" },
{ "BufWritePre", "*.bak", "setlocal noundofile" },
-- auto change directory
{ "BufEnter", "*", "silent! lcd %:p:h" },
-- change cursor to vertical bar after leaving neovim.
{ "VimLeave", "*", "set guicursor=a:ver2" },
-- auto place to last edit
{
"BufReadPost",
"*",
[[if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif]],
},
-- Change cursor to vertical bar after leaving neovim.
{
"VimLeave",
"*",
"set guicursor=a:ver2",
},
-- auto change directory
-- { "BufEnter", "*", "silent! lcd %:p:h" },
-- Auto toggle fcitx5
-- {"InsertLeave", "* :silent", "!fcitx5-remote -c"},
-- {"BufCreate", "*", ":silent !fcitx5-remote -c"},
Expand Down
27 changes: 27 additions & 0 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,40 @@ local clipboard_config = function()
end
end

local shell_config = function()
if global.is_windows then
if not (vim.fn.executable("pwsh") or vim.fn.executable("powershell")) then
vim.notify(
[[
Failed to setup terminal config
PowerShell is either not installed, missing from PATH, or not executable;
cmd.exe will be used instead for `:!` (shell bang) and toggleterm.nvim.
You're recommended to install PowerShell for better experience.]],
vim.log.levels.WARN,
{ title = "[core] Runtime error" }
)
return
end

local basecmd = "-NoLogo -MTA -ExecutionPolicy RemoteSigned"
local ctrlcmd = "-Command [console]::InputEncoding = [console]::OutputEncoding = [System.Text.Encoding]::UTF8"
vim.api.nvim_set_option_value("shell", vim.fn.executable("pwsh") and "pwsh" or "powershell", {})
vim.api.nvim_set_option_value("shellcmdflag", string.format("%s %s;", basecmd, ctrlcmd), {})
vim.api.nvim_set_option_value("shellredir", "-RedirectStandardOutput %s -NoNewWindow -Wait", {})
vim.api.nvim_set_option_value("shellpipe", "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode", {})
vim.api.nvim_set_option_value("shellquote", nil, {})
vim.api.nvim_set_option_value("shellxquote", nil, {})
end
end

local load_core = function()
createdir()
disable_distribution_plugins()
leader_map()

neovide_config()
clipboard_config()
shell_config()

require("core.options")
require("core.mapping")
Expand Down
15 changes: 11 additions & 4 deletions lua/core/mapping.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local core_map = {
-- Vim map
["n|<S-Tab>"] = map_cr("normal za"):with_noremap():with_silent(),
["n|<C-s>"] = map_cu("write"):with_noremap():with_silent(),
["n|<C-S-s>"] = map_cmd("execute 'silent! write !sudo tee % >/dev/null' <bar> edit!"):with_silent():with_noremap(),
["n|Y"] = map_cmd("y$"),
["n|D"] = map_cmd("d$"),
["n|n"] = map_cmd("nzzzv"):with_noremap(),
Expand All @@ -24,14 +23,22 @@ local core_map = {
["n|‘"] = map_cr("vertical resize +5"):with_silent(),
["n|…"] = map_cr("resize -2"):with_silent(),
["n|æ"] = map_cr("resize +2"):with_silent(),
["n|<C-q>"] = map_cmd(":wq<CR>"),
["n|Œ"] = map_cmd(":q!<CR>"),
["n|<C-q>"] = map_cr("wq"),
["n|Œ"] = map_cr("q!"),
["n|<leader>o"] = map_cr("setlocal spell! spelllang=en_us"),
["x|<leader>p"] = map_cmd('"_dP'):with_silent():with_noremap(),
["n|+"] = map_cmd("<C-a>"):with_noremap():with_silent(),
["n|-"] = map_cmd("<C-x>"):with_noremap():with_silent(),
["n|<C-a>"] = map_cmd("gg0vG$"):with_noremap():with_silent(),
["x|<C-a>"] = map_cmd("<Esc>gg0vG$"):with_noremap():with_silent(),
["n|tn"] = map_cr("tabnew"):with_noremap():with_silent(),
["n|tk"] = map_cr("tabnext"):with_noremap():with_silent(),
["n|tj"] = map_cr("tabprevious"):with_noremap():with_silent(),
["n|to"] = map_cr("tabonly"):with_noremap():with_silent(),
-- Insert mode
["i|<C-u>"] = map_cmd("<C-G>u<C-U>"):with_noremap(),
["i|<C-b>"] = map_cmd("<Left>"):with_noremap(),
["i|<C-a>"] = map_cmd("<ESC>^i"):with_noremap(),
["i|<C-a>"] = map_cmd("<Esc>^i"):with_noremap(),
["i|<C-s>"] = map_cmd("<Esc>:w<CR>"),
["i|<C-q>"] = map_cmd("<Esc>:wq<CR>"),
-- Command mode
Expand Down
4 changes: 2 additions & 2 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local function load_options()
cmdwinheight = 5,
complete = ".,w,b,k",
completeopt = "menuone,noselect",
cursorcolumn = false, --目前不是很喜欢竖直的线w
cursorcolumn = false,
cursorline = true,
diffopt = "filler,iwhite,internal,algorithm:patience",
display = "lastline",
Expand Down Expand Up @@ -47,7 +47,7 @@ local function load_options()
redrawtime = 1500,
ruler = true,
scrolloff = 3,
sessionoptions = "curdir,help,tabpages,winsize",
sessionoptions = "buffers,curdir,help,tabpages,winsize",
shada = "!,'300,<50,@100,s10,h",
shiftround = true,
shortmess = "aoOTIcF",
Expand Down
13 changes: 12 additions & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local settings = {}
local home = require("core.global").home

-- Set it to false if you want to use https to update plugins and treesitter parsers.
---@type boolean
Expand All @@ -8,9 +9,15 @@ settings["use_ssh"] = true
---@type boolean
settings["format_on_save"] = true

-- Set it to false if diagnostics virtual text is annoying for you
---@type boolean
settings["diagnostics_virtual_text"] = true

-- Set the format disabled directories here, files under these dirs won't be formatted on save.
---@type string[]
settings["format_disabled_dirs"] = {}
settings["format_disabled_dirs"] = {
home .. "/Library/Rime",
}

-- Set it to false if you don't use nvim to open big files.
---@type boolean
Expand All @@ -28,6 +35,10 @@ settings["palette_overwrite"] = {}
---@type string
settings["colorscheme"] = "catppuccin"

-- Set it to true if your terminal has transparent background.
---@type boolean
settings["transparent_background"] = false

-- Set background color to use here.
-- Useful if you would like to use a colorscheme that has a light and dark variant like `edge`.
-- Valid values are: `dark`, `light`.
Expand Down
2 changes: 2 additions & 0 deletions lua/keymap/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ local plug_map = {
["n|<F5>"] = map_cr([[execute v:count . "ToggleTerm direction=vertical"]]):with_noremap():with_silent(),
["i|<F5>"] = map_cmd("<Esc><Cmd>ToggleTerm direction=vertical<CR>"):with_noremap():with_silent(),
["t|<F5>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent(),
-- Plugin suda.vim
["n|<C-S-s>"] = map_cu("SudaWrite"):with_silent():with_noremap(),
-- Plugin trouble
["n|gt"] = map_cr("TroubleToggle"):with_noremap():with_silent(),
["n|<leader>cr"] = map_cr("TroubleToggle lsp_references"):with_noremap():with_silent(),
Expand Down
23 changes: 14 additions & 9 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vim.api.nvim_create_user_command("FormatterToggleFt", function(opts)
vim.notify(
string.format("[LSP] Formatter for [%s] has been recorded in list and disabled.", opts.args),
vim.log.levels.WARN,
{ title = "LSP Formatter Warning!" }
{ title = "LSP Formatter Warning" }
)
block_list[opts.args] = true
else
Expand Down Expand Up @@ -49,7 +49,7 @@ function M.enable_format_on_save(is_configured)
vim.notify(
"Successfully enabled format-on-save",
vim.log.levels.INFO,
{ title = "Settings modification success!" }
{ title = "Settings modification success" }
)
end
end
Expand All @@ -60,7 +60,7 @@ function M.disable_format_on_save()
vim.notify(
"Successfully disabled format-on-save",
vim.log.levels.INFO,
{ title = "Settings modification success!" }
{ title = "Settings modification success" }
)
end
end
Expand Down Expand Up @@ -102,6 +102,11 @@ function M.format(opts)
local cwd = vim.fn.getcwd()
for i = 1, #disabled_workspaces do
if cwd.find(cwd, disabled_workspaces[i]) ~= nil then
vim.notify(
string.format("[LSP] Formatting support for all files under [%s] is disabled.", disabled_workspaces[i]),
vim.log.levels.WARN,
{ title = "LSP Formatter Warning" }
)
return
end
end
Expand Down Expand Up @@ -129,7 +134,7 @@ function M.format(opts)
vim.notify(
"[LSP] Format request failed, no matching language servers.",
vim.log.levels.WARN,
{ title = "Formatting Failed!" }
{ title = "Formatting Failed" }
)
end

Expand All @@ -143,7 +148,7 @@ function M.format(opts)
vim.bo.filetype
),
vim.log.levels.WARN,
{ title = "LSP Formatter Warning!" }
{ title = "LSP Formatter Warning" }
)
return
end
Expand All @@ -152,15 +157,15 @@ function M.format(opts)
if result and result.result then
vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding)
vim.notify(
string.format("Format successfully with %s!", client.name),
string.format("[LSP] Format successfully with %s!", client.name),
vim.log.levels.INFO,
{ title = "LSP Format Success!" }
{ title = "LSP Format Success" }
)
elseif err then
vim.notify(
string.format("[LSP][%s] %s", client.name, err),
vim.log.levels.WARN,
{ title = "LSP Format Warning!" }
vim.log.levels.ERROR,
{ title = "LSP Format Error" }
)
end
end
Expand Down
7 changes: 7 additions & 0 deletions lua/modules/configs/completion/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ mason_lspconfig.setup({
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)

vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
signs = true,
underline = true,
virtual_text = require("core.settings").diagnostics_virtual_text,
update_in_insert = false,
})

local opts = {
on_attach = function()
require("lsp_signature").on_attach({
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/lspsaga.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ return function()
keys = {
exec_action = "r",
quit = "q",
go_action = "g",
expand_or_jump = "<CR>",
quit_in_show = { "q", "<ESC>" },
},
Expand Down Expand Up @@ -119,6 +118,7 @@ return function()
frequency = 12,
},
ui = {
title = false,
border = "single", -- Can be single, double, rounded, solid, shadow.
winblend = 0,
actionfix = icons.ui.Spell,
Expand Down
3 changes: 3 additions & 0 deletions lua/modules/configs/editor/suda.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return function()
vim.g["suda#prompt"] = "Enter administrator password: "
end
8 changes: 4 additions & 4 deletions lua/modules/configs/tool/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ return function()
git = true,
},
padding = " ",
symlink_arrow = " ",
symlink_arrow = " 󰁔 ",
glyphs = {
default = icons.documents.Default, --
symlink = icons.documents.Symlink, --
bookmark = icons.ui.Bookmark,
git = {
unstaged = icons.git.Mod_alt,
staged = icons.git.Add, --
staged = icons.git.Add, --󰄬
unmerged = icons.git.Unmerged,
renamed = icons.git.Rename, --
untracked = icons.git.Untracked, -- ""
renamed = icons.git.Rename, --󰁔
untracked = icons.git.Untracked, -- "󰞋"
deleted = icons.git.Remove, --
ignored = icons.git.Ignore, --
},
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/tool/project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ return function()
manual_mode = false,
detection_methods = { "lsp", "pattern" },
patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json" },
ignore_lsp = { "efm", "copilot" },
ignore_lsp = { "null-ls", "copilot" },
exclude_dirs = {},
show_hidden = false,
silent_chdir = true,
Expand Down
19 changes: 10 additions & 9 deletions lua/modules/configs/ui/alpha.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
return function()
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
require("modules.utils").gen_alpha_hl()

dashboard.section.header.val = {
[[ ██╗██╗███╗ ██╗████████╗ ██╗ ███████╗██╗ ██╗██╗ ██╗ ]],
Expand All @@ -12,7 +13,7 @@ return function()
[[ ]],
[[ Configuration By 冷酔閑吟 ver ]] .. os.date("%Y.%m") .. [[ ]],
}
dashboard.section.header.opts.hl = "Type"
dashboard.section.header.opts.hl = "AlphaHeader"

local function button(sc, txt, leader_txt, keybind, keybind_opts)
local sc_after = sc:gsub("%s", ""):gsub(leader_txt, "<leader>")
Expand All @@ -23,8 +24,8 @@ return function()
cursor = 5,
width = 50,
align_shortcut = "right",
hl = "String",
hl_shortcut = "Keyword",
hl = "AlphaButton",
hl_shortcut = "AlphaAttr",
}

if keybind == nil then
Expand All @@ -51,32 +52,32 @@ return function()
dashboard.section.buttons.val = {
button("[leader] f c", " Scheme change", leader, "<Cmd>Telescope colorscheme<CR>"),
button("[leader] f r", " File frecency", leader, "<Cmd>Telescope frecency<CR>"),
button("[leader] f e", " File history", leader, "<Cmd>Telescope oldfiles<CR>"),
button("[leader] f e", "󰋚 File history", leader, "<Cmd>Telescope oldfiles<CR>"),
button("[leader] f p", " Project find", leader, "<Cmd>Telescope projects<CR>"),
button("[leader] f f", " File find", leader, "<Cmd>Telescope find_files<CR>"),
button("[leader] f f", "󰈞 File find", leader, "<Cmd>Telescope find_files<CR>"),
button("[leader] f n", " File new", leader, "<Cmd>enew<CR>"),
button("[leader] f w", " Word find", leader, "<Cmd>Telescope live_grep<CR>"),
}
dashboard.section.buttons.opts.hl = "String"
dashboard.section.buttons.opts.hl = "AlphaButton"

local function footer()
local stats = require("lazy").stats()
local greet = " 💝 Have Fun with neovim"
.. " v"
.. " 󰀨 v"
.. vim.version().major
.. "."
.. vim.version().minor
.. "."
.. vim.version().patch
.. " "
.. " 󰂖 "
.. stats.count
.. " plugins"
local quote = table.concat(require("alpha.fortune")(), "\n")
return greet .. "\n" .. quote
end

dashboard.section.footer.val = footer()
dashboard.section.footer.opts.hl = "Typedef"
dashboard.section.footer.opts.hl = "AlphaFooter"

local head_butt_padding = 2
local occu_height = #dashboard.section.header.val + 2 * #dashboard.section.buttons.val + head_butt_padding
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/ui/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ return function()
highlights = {},
}

if vim.g.colors_name == "catppuccin" then
if vim.g.colors_name:find("catppuccin") then
local cp = require("modules.utils").get_palette() -- Get the palette.

local catppuccin_hl_overwrite = {
Expand Down
Loading

0 comments on commit 0bda97c

Please sign in to comment.