Skip to content

Commit

Permalink
Merge pull request #18 from TonyWu20/ayamir-main
Browse files Browse the repository at this point in the history
ayamir main
  • Loading branch information
TonyWu20 authored May 22, 2023
2 parents d399b60 + ae4c37e commit 8cecfb1
Show file tree
Hide file tree
Showing 26 changed files with 284 additions and 230 deletions.
4 changes: 2 additions & 2 deletions dots.tutor
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Back to the left window, the status line is showed at the bottom of the window.
You will see different content under different conditions. It will looks like
this if you switch to the right window and move cursor to the second line.
-------------------------------------------------------------------------------
|Normal|main| autocmd |~/.config/nvim|utf-8|LF|1%|2:1|
|Normal|main| 󰅩 autocmd |~/.config/nvim|utf-8|LF|1%|2:1|
-------------------------------------------------------------------------------
" autocmd" indicates this line has a variable named "autocmd". So this part of
"󰅩 autocmd" indicates this line has a variable named "autocmd". So this part of
status line will show you the context of your cursor position. This feature
is based on lsp, so it is disabled if corresponding lsp is not attach to current
buffer.
Expand Down
17 changes: 16 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
if not vim.g.vscode then
require("core")
print(vim.fn.expand("%"))
-- Release note
vim.schedule(function()
vim.notify_once(
[[
We've released version v3.0.0!
Visit https://github.com/ayamir/nvimdots/releases to see the release notes.
If you have icons that can't be rendered correctly (e.g., 𑨩 and � ) or icons with incorrect size, be sure to read this!
To silence this message, remove it from `init.lua` at the config's root directory.
To check the glyphs size, make sure the following icons are very close to the crosses but there is no overlap:
XXXXXXXXX
]],
vim.log.levels.WARN
)
end)
end
2 changes: 1 addition & 1 deletion lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@
"vim-pencil": { "branch": "master", "commit": "6d70438a8886eaf933c38a7a43a61adb0a7815ed" },
"which-key.nvim": { "branch": "main", "commit": "5a6c954a5a46023c19acc03a8b6d7c3e57964fc5" },
"wilder.nvim": { "branch": "master", "commit": "679f348dc90d80ff9ba0e7c470c40a4d038dcecf" }
}
}
8 changes: 8 additions & 0 deletions lua/core/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ function autocmd.nvim_create_augroups(definitions)
end
end

local mapping = require("keymap.completion")
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(event)
mapping.lsp(event.buf)
end,
})

-- auto close NvimTree
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("NvimTreeClose", { clear = true }),
Expand Down
16 changes: 8 additions & 8 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ local clipboard_config = function()
}
elseif global.is_wsl then
vim.g.clipboard = {
name = "win32yank-wsl",
name = "psyank-wsl",
copy = {
["+"] = "win32yank.exe -i --crlf",
["*"] = "win32yank.exe -i --crlf",
["+"] = "clip.exe",
["*"] = "clip.exe",
},
paste = {
["+"] = "win32yank.exe -o --lf",
["*"] = "win32yank.exe -o --lf",
["+"] = [[powershell.exe -NoProfile -NoLogo -NonInteractive -Command [console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))]],
["*"] = [[powershell.exe -NoProfile -NoLogo -NonInteractive -Command [console]::Out.Write($(Get-Clipboard -Raw).tostring().replace("`r", ""))]],
},
cache_enabled = 0,
}
Expand All @@ -182,7 +182,7 @@ end

local shell_config = function()
if global.is_windows then
if not (vim.fn.executable("pwsh") or vim.fn.executable("powershell")) then
if not (vim.fn.executable("pwsh") == 1 or vim.fn.executable("powershell") == 1) then
vim.notify(
[[
Failed to setup terminal config
Expand All @@ -192,14 +192,14 @@ 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" }
{ title = "[core] Runtime Warning" }
)
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("shell", vim.fn.executable("pwsh") == 1 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", {})
Expand Down
7 changes: 2 additions & 5 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,9 @@ local function load_options()
if not isempty(conda_prefix) then
vim.g.python_host_prog = conda_prefix .. "/bin/python"
vim.g.python3_host_prog = conda_prefix .. "/bin/python"
elseif global.is_mac then
vim.g.python_host_prog = "/usr/bin/python"
vim.g.python3_host_prog = "/usr/local/bin/python3"
else
vim.g.python_host_prog = "/usr/bin/python"
vim.g.python3_host_prog = "/usr/bin/python3"
vim.g.python_host_prog = "python"
vim.g.python3_host_prog = "python3"
end

for name, value in pairs(global_local) do
Expand Down
7 changes: 6 additions & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ 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"] = {
Expand Down Expand Up @@ -59,6 +63,7 @@ settings["server_formatting_block_list"] = {
lua_ls = true,
tsserver = true,
clangd = true,
pylsp = true,
}

-- Set the language servers that will be installed during bootstrap here
Expand All @@ -71,7 +76,7 @@ settings["lsp_deps"] = {
"html",
"jsonls",
"lua_ls",
"pyright",
"pylsp",
-- "gopls",
}

Expand Down
67 changes: 31 additions & 36 deletions lua/keymap/completion.lua
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
local map_cu = bind.map_cu
-- local map_cmd = bind.map_cmd
local map_cmd = bind.map_cmd
local map_callback = bind.map_callback

local plug_map = {
-- LSP-related keymaps, work only when event = { "InsertEnter", "LspStart" }
["n|<leader>li"] = map_cr("LspInfo"):with_noremap():with_silent():with_nowait():with_desc("lsp: Info"),
["n|<leader>lr"] = map_cr("LspRestart"):with_noremap():with_silent():with_nowait():with_desc("lsp: Restart"),
["n|go"] = map_cr("Lspsaga outline"):with_noremap():with_silent():with_desc("lsp: Toggle outline"),
["n|g["] = map_cr("Lspsaga diagnostic_jump_prev"):with_noremap():with_silent():with_desc("lsp: Prev diagnostic"),
["n|g]"] = map_cr("Lspsaga diagnostic_jump_next"):with_noremap():with_silent():with_desc("lsp: Next diagnostic"),
["n|<leader>ld"] = map_cr("Lspsaga show_line_diagnostics")
:with_noremap()
:with_silent()
:with_desc("lsp: Line diagnostic"),
["n|gs"] = map_callback(function()
vim.lsp.buf.signature_help()
end)
:with_noremap()
:with_silent()
:with_desc("lsp: Signature help"),
["n|gr"] = map_cr("Lspsaga rename"):with_noremap():with_silent():with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project")
:with_noremap()
:with_silent()
:with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_noremap():with_silent():with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action"):with_noremap():with_silent():with_desc("lsp: Code action"),
["n|gd"] = map_cr("Lspsaga peek_definition"):with_noremap():with_silent():with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_noremap():with_silent():with_desc("lsp: Goto definition"),
["n|gh"] = map_cr("Lspsaga lsp_finder"):with_noremap():with_silent():with_desc("lsp: Show reference"),
["n|<leader>ci"] = map_cr("Lspsaga incoming_calls")
:with_noremap()
:with_silent()
:with_desc("lsp: Show incoming calls"),
["n|<leader>co"] = map_cr("Lspsaga outgoing_calls")
:with_noremap()
:with_silent()
:with_desc("lsp: Show outgoing calls"),
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("Formater: Toggle format on save"),
}

bind.nvim_load_mapping(plug_map)

local mapping = {}

function mapping.lsp(buf)
local map = {
-- LSP-related keymaps, work only when event = { "InsertEnter", "LspStart" }
["n|<leader>li"] = map_cr("LspInfo"):with_buffer(buf):with_desc("lsp: Info"),
["n|<leader>lr"] = map_cr("LspRestart"):with_buffer(buf):with_nowait():with_desc("lsp: Restart"),
["n|go"] = map_cr("Lspsaga outline"):with_buffer(buf):with_desc("lsp: Toggle outline"),
["n|g["] = map_cr("Lspsaga diagnostic_jump_prev"):with_buffer(buf):with_desc("lsp: Prev diagnostic"),
["n|g]"] = map_cr("Lspsaga diagnostic_jump_next"):with_buffer(buf):with_desc("lsp: Next diagnostic"),
["n|<leader>ld"] = map_cr("Lspsaga show_line_diagnostics"):with_buffer(buf):with_desc("lsp: Line diagnostic"),
["n|gs"] = map_callback(function()
vim.lsp.buf.signature_help()
end):with_desc("lsp: Signature help"),
["n|gr"] = map_cr("Lspsaga rename"):with_buffer(buf):with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project"):with_buffer(buf):with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_buffer(buf):with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action"):with_buffer(buf):with_desc("lsp: Code action for cursor"),
["n|gd"] = map_cr("Lspsaga peek_definition"):with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_buffer(buf):with_desc("lsp: Goto definition"),
["n|gh"] = map_cr("Lspsaga lsp_finder"):with_buffer(buf):with_desc("lsp: Show reference"),
["n|<leader>ci"] = map_cr("Lspsaga incoming_calls"):with_buffer(buf):with_desc("lsp: Show incoming calls"),
["n|<leader>co"] = map_cr("Lspsaga outgoing_calls"):with_buffer(buf):with_desc("lsp: Show outgoing calls"),
}
bind.nvim_load_mapping(map)
end

return mapping
6 changes: 3 additions & 3 deletions lua/keymap/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ local plug_map = {
end):with_expr(),

-- Plugin: auto_session
["n|<leader>ss"] = map_cu("SaveSession"):with_noremap():with_silent():with_desc("session: Save"),
["n|<leader>sr"] = map_cu("RestoreSession"):with_noremap():with_silent():with_desc("session: Restore"),
["n|<leader>sd"] = map_cu("DeleteSession"):with_noremap():with_silent():with_desc("session: Delete"),
["n|<leader>ss"] = map_cu("SessionSave"):with_noremap():with_silent():with_desc("session: Save"),
["n|<leader>sr"] = map_cu("SessionRestore"):with_noremap():with_silent():with_desc("session: Restore"),
["n|<leader>sd"] = map_cu("SessionDelete"):with_noremap():with_silent():with_desc("session: Delete"),

-- Plugin: nvim-bufdel
["n|<A-q>"] = map_cr("BufDel"):with_noremap():with_silent():with_desc("buffer: Close current"),
Expand Down
2 changes: 1 addition & 1 deletion lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

local _lazygit = nil
_G._toggle_lazygit = function()
if vim.fn.executable("lazygit") then
if vim.fn.executable("lazygit") == 1 then
if not _lazygit then
_lazygit = require("toggleterm.terminal").Terminal:new({
cmd = "lazygit",
Expand Down
79 changes: 79 additions & 0 deletions lua/keymap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,82 @@ local plug_map = {
}

bind.nvim_load_mapping(plug_map)

local mapping = {}

function mapping.gitsigns(buf)
local actions = require("gitsigns.actions")
local map = {
["n|]g"] = bind.map_callback(function()
if vim.wo.diff then
return "]g"
end
vim.schedule(function()
actions.next_hunk()
end)
return "<Ignore>"
end)
:with_buffer(buf)
:with_expr()
:with_desc("git: Goto next hunk"),
["n|[g"] = bind.map_callback(function()
if vim.wo.diff then
return "[g"
end
vim.schedule(function()
actions.prev_hunk()
end)
return "<Ignore>"
end)
:with_buffer(buf)
:with_expr()
:with_desc("git: Goto prev hunk"),
["n|<leader>hs"] = bind.map_callback(function()
actions.stage_hunk()
end)
:with_buffer(buf)
:with_desc("git: Stage hunk"),
["v|<leader>hs"] = bind.map_callback(function()
actions.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
:with_buffer(buf)
:with_desc("git: Stage hunk"),
["n|<leader>hu"] = bind.map_callback(function()
actions.undo_stage_hunk()
end)
:with_buffer(buf)
:with_desc("git: Undo stage hunk"),
["n|<leader>hr"] = bind.map_callback(function()
actions.reset_hunk()
end)
:with_buffer(buf)
:with_desc("git: Reset hunk"),
["v|<leader>hr"] = bind.map_callback(function()
actions.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
:with_buffer(buf)
:with_desc("git: Reset hunk"),
["n|<leader>hR"] = bind.map_callback(function()
actions.reset_buffer()
end)
:with_buffer(buf)
:with_desc("git: Reset buffer"),
["n|<leader>hp"] = bind.map_callback(function()
actions.preview_hunk()
end)
:with_buffer(buf)
:with_desc("git: Preview hunk"),
["n|<leader>hb"] = bind.map_callback(function()
actions.blame_line({ full = true })
end)
:with_buffer(buf)
:with_desc("git: Blame line"),
-- Text objects
["ox|ih"] = bind.map_callback(function()
actions.text_object()
end):with_buffer(buf),
}
bind.nvim_load_mapping(map)
end

return mapping
Loading

0 comments on commit 8cecfb1

Please sign in to comment.