Skip to content

Commit 0746f84

Browse files
committed
fix(event): fix Autojump to lat place event
1 parent 2f11d1e commit 0746f84

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

lua/core/event.lua

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,25 @@ vim.api.nvim_create_autocmd("LspAttach", {
5757
end,
5858
})
5959

60+
-- Create custom filetype for gitlab_ci_ls
61+
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
62+
pattern = "*.gitlab-ci*.{yml,yaml}",
63+
callback = function()
64+
vim.bo.filetype = "yaml.gitlab"
65+
end,
66+
})
67+
68+
-- Autojump to last place
69+
vim.api.nvim_create_autocmd("BufReadPost", {
70+
callback = function()
71+
local mark = vim.api.nvim_buf_get_mark(0, '"')
72+
local lcount = vim.api.nvim_buf_line_count(0)
73+
if mark[1] > 0 and mark[1] <= lcount then
74+
pcall(vim.api.nvim_win_set_cursor, 0, mark)
75+
end
76+
end,
77+
})
78+
6079
function autocmd.nvim_create_augroups(definitions)
6180
for group_name, definition in pairs(definitions) do
6281
-- Prepend an underscore to avoid name clashes
@@ -70,25 +89,6 @@ function autocmd.nvim_create_augroups(definitions)
7089
end
7190
end
7291

73-
-- Create custom filetype for gitlab_ci_ls
74-
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
75-
pattern = "*.gitlab-ci*.{yml,yaml}",
76-
callback = function()
77-
vim.bo.filetype = "yaml.gitlab"
78-
end,
79-
})
80-
81-
-- Autojump to last place
82-
-- vim.api.nvim_create_autocmd("BufReadPost", {
83-
-- callback = function()
84-
-- local mark = vim.api.nvim_buf_get_mark(0, '"')
85-
-- local lcount = vim.api.nvim_buf_line_count(0)
86-
-- if mark[1] > 0 and mark[1] <= lcount then
87-
-- pcall(vim.api.nvim_win_set_cursor, 0, mark)
88-
-- end
89-
-- end,
90-
-- })
91-
9292
function autocmd.load_autocmds()
9393
local definitions = {
9494
bufs = {
@@ -110,12 +110,6 @@ function autocmd.load_autocmds()
110110
{ "BufWritePre", "MERGE_MSG", "setlocal noundofile" },
111111
{ "BufWritePre", "description", "setlocal noundofile" },
112112
{ "BufWritePre", "COMMIT_EDITMSG", "setlocal noundofile" },
113-
-- Auto place to last edit
114-
{
115-
"BufReadPost",
116-
"*",
117-
[[if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif]],
118-
},
119113
-- Auto change directory
120114
-- { "BufEnter", "*", "silent! lcd %:p:h" },
121115
},

0 commit comments

Comments
 (0)