mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
use native lua api instead of vim.cmd
This commit is contained in:
parent
d941be482b
commit
64b41fbd58
@ -165,8 +165,9 @@ api.nvim_create_autocmd("FileType", {
|
|||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
|
local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
|
||||||
if not status then
|
if not status then
|
||||||
api.nvim_err_writeln(string.format("Failed to resume cursor position. Context %s, error: %s",
|
api.nvim_err_writeln(
|
||||||
vim.inspect(ev), result))
|
string.format("Failed to resume cursor position. Context %s, error: %s", vim.inspect(ev), result)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
-- the following two ways also seem to work,
|
-- the following two ways also seem to work,
|
||||||
@ -204,20 +205,18 @@ api.nvim_create_autocmd("ColorScheme", {
|
|||||||
pattern = "*",
|
pattern = "*",
|
||||||
desc = "Define or overrride some highlight groups",
|
desc = "Define or overrride some highlight groups",
|
||||||
callback = function()
|
callback = function()
|
||||||
vim.cmd([[
|
-- For yank highlight
|
||||||
" For yank highlight
|
vim.api.nvim_set_hl(0, "YankColor", { fg = "#34495E", bg = "#2ECC71", ctermfg = 59, ctermbg = 41 })
|
||||||
highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71
|
|
||||||
|
|
||||||
" For cursor colors
|
-- For cursor colors
|
||||||
highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black
|
vim.api.nvim_set_hl(0, "Cursor", { fg = "black", bg = "#00c918", bold = true })
|
||||||
highlight Cursor2 guifg=red guibg=red
|
vim.api.nvim_set_hl(0, "Cursor2", { fg = "red", bg = "red" })
|
||||||
|
|
||||||
" For floating windows border highlight
|
-- For floating windows border highlight
|
||||||
highlight FloatBorder guifg=LightGreen guibg=NONE
|
vim.api.nvim_set_hl(0, "FloatBorder", { fg = "LightGreen" })
|
||||||
|
|
||||||
" highlight for matching parentheses
|
-- highlight for matching parentheses
|
||||||
highlight MatchParen cterm=bold,underline gui=bold,underline
|
vim.api.nvim_set_hl(0, "MatchParen", { bold = true, underline = true })
|
||||||
]])
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -226,14 +225,14 @@ api.nvim_create_autocmd("BufEnter", {
|
|||||||
group = api.nvim_create_augroup("auto_close_win", { clear = true }),
|
group = api.nvim_create_augroup("auto_close_win", { clear = true }),
|
||||||
desc = "Quit Nvim if we have only one window, and its filetype match our pattern",
|
desc = "Quit Nvim if we have only one window, and its filetype match our pattern",
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
local quit_filetypes = {'qf', 'vista', 'NvimTree'}
|
local quit_filetypes = { "qf", "vista", "NvimTree" }
|
||||||
|
|
||||||
local should_quit = true
|
local should_quit = true
|
||||||
local tabwins = api.nvim_tabpage_list_wins(0)
|
local tabwins = api.nvim_tabpage_list_wins(0)
|
||||||
|
|
||||||
for _, win in pairs(tabwins) do
|
for _, win in pairs(tabwins) do
|
||||||
local buf = api.nvim_win_get_buf(win)
|
local buf = api.nvim_win_get_buf(win)
|
||||||
local bf = fn.getbufvar(buf, '&filetype')
|
local bf = fn.getbufvar(buf, "&filetype")
|
||||||
|
|
||||||
if fn.index(quit_filetypes, bf) == -1 then
|
if fn.index(quit_filetypes, bf) == -1 then
|
||||||
should_quit = false
|
should_quit = false
|
||||||
@ -243,14 +242,14 @@ api.nvim_create_autocmd("BufEnter", {
|
|||||||
if should_quit then
|
if should_quit then
|
||||||
vim.cmd("qall")
|
vim.cmd("qall")
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, {
|
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",
|
||||||
command = "call utils#Inside_git_repo()"
|
command = "call utils#Inside_git_repo()",
|
||||||
})
|
})
|
||||||
|
|
||||||
-- ref: https://vi.stackexchange.com/a/169/15292
|
-- ref: https://vi.stackexchange.com/a/169/15292
|
||||||
@ -271,5 +270,5 @@ api.nvim_create_autocmd("BufReadPre", {
|
|||||||
vim.bo.bufhidden = "unload"
|
vim.bo.bufhidden = "unload"
|
||||||
vim.bo.undolevels = -1
|
vim.bo.undolevels = -1
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user