-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathautocommands.lua
193 lines (183 loc) Β· 5.9 KB
/
autocommands.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
local M = {}
local create_aucmd = vim.api.nvim_create_autocmd
M.config = function()
local user = vim.env.USER
vim.api.nvim_create_autocmd("ColorScheme", {
pattern = "*",
callback = function()
require("user.theme").telescope_theme {}
if lvim.builtin.dap.active then
require("user.dev_icons").define_dap_signs()
end
if lvim.use_icons == false and lvim.builtin.custom_web_devicons then
require("user.dev_icons").set_icon()
end
end,
})
vim.api.nvim_clear_autocmds { pattern = "lir", group = "_filetype_settings" }
vim.api.nvim_clear_autocmds { pattern = "*", group = "_lvim_colorscheme" }
vim.api.nvim_create_augroup("_lvim_user", {})
-- Autocommands
if lvim.builtin.nonumber_unfocus then
create_aucmd("WinEnter", { group = "_lvim_user", pattern = "*", command = "set relativenumber number cursorline" })
create_aucmd(
"WinLeave",
{ group = "_lvim_user", pattern = "*", command = "set norelativenumber nonumber nocursorline" }
)
end
if lvim.builtin.bigfile.active == false then
vim.cmd [[
" disable syntax highlighting in big files
function! DisableSyntaxTreesitter()
if exists(':TSBufDisable')
exec 'TSBufDisable autotag'
exec 'TSBufDisable highlight'
endif
set foldmethod=manual
syntax clear
syntax off
filetype off
set noundofile
set noswapfile
set noloadplugins
set lazyredraw
endfunction
augroup BigFileDisable
autocmd!
autocmd BufReadPre,FileReadPre * if getfsize(expand("%")) > 1024 * 1024 | exec DisableSyntaxTreesitter() | endif
augroup END
]]
end
if lvim.builtin.sql_integration.active then
-- Add vim-dadbod-completion in sql files
create_aucmd("FileType", {
group = "_lvim_user",
pattern = { "sql", "mysql", "plsql" },
command = "lua require('cmp').setup.buffer { sources = { { name = 'vim-dadbod-completion' } } }",
})
end
create_aucmd("TextYankPost", {
group = "_general_settings",
pattern = "*",
desc = "Highlight text on yank",
callback = function()
require("vim.highlight").on_yank { higroup = "Search", timeout = 40 }
end,
})
create_aucmd("BufWritePre", {
group = "_lvim_user",
pattern = { "/tmp/*", "COMMIT_EDITMSG", "MERGE_MSG", "*.tmp", "*.bak" },
callback = function()
vim.opt_local.undofile = false
end,
})
create_aucmd("TermOpen", {
group = "_lvim_user",
pattern = "term://*",
command = "lua require('user.keybindings').set_terminal_keymaps()",
})
if lvim.builtin.metals.active then
create_aucmd("Filetype", {
group = "_lvim_user",
pattern = { "scala", "sbt" },
callback = require("user.metals").start,
})
end
create_aucmd("FileType", {
group = "_lvim_user",
pattern = "toml",
command = "lua require('cmp').setup.buffer { sources = { { name = 'crates' } } }",
})
local codelens_viewer = "lua require('user.codelens').show_line_sign()"
-- NOTE: don't give corporate code to the devil
if user and user == "abz" then
if lvim.builtin.sell_your_soul_to_devil.active or lvim.builtin.tabnine.active then
create_aucmd("UIEnter", {
group = "_lvim_user",
pattern = { "*" },
callback = function()
local dirpath = vim.fn.expand "%:p:h"
if string.find(dirpath, user .. "/dev/src/git.") ~= nil then
if lvim.builtin.sell_your_soul_to_devil.active then
vim.cmd "Copilot disable"
end
if lvim.builtin.tabnine.active then
require("cmp_tabnine.config"):setup { ignored_file_types = { "*" }, run_on_every_keystroke = false }
lvim.builtin.cmp.sources = {
{ name = "nvim_lsp" },
{ name = "buffer", max_item_count = 5, keyword_length = 5 },
{ name = "path", max_item_count = 5 },
{ name = "luasnip", max_item_count = 3 },
{ name = "nvim_lua" },
{ name = "calc" },
{ name = "emoji" },
{ name = "treesitter" },
{ name = "latex_symbols" },
{ name = "crates" },
{ name = "orgmode" },
}
end
end
end,
})
end
create_aucmd("CursorHold", {
group = "_lvim_user",
pattern = { "*.rs", "*.go", "*.ts", "*.tsx" },
command = codelens_viewer,
})
end
end
M.make_run = function()
create_aucmd("FileType", {
group = "_lvim_user",
pattern = { "c", "cpp" },
callback = function()
vim.keymap.set(
"n",
"<leader>m",
"<cmd>lua require('lvim.core.terminal')._exec_toggle({cmd='make ;read',count=2,direction='float'})<CR>"
)
vim.keymap.set(
"n",
"<leader>r",
"<cmd>lua require('lvim.core.terminal')._exec_toggle({cmd='make run;read',count=3,direction='float'})<CR>"
)
end,
})
create_aucmd("FileType", {
group = "_lvim_user",
pattern = "go",
callback = function()
vim.keymap.set(
"n",
"<leader>m",
"<cmd>lua require('lvim.core.terminal')._exec_toggle({cmd='go build -v .;read',count=2,direction='float'})<CR>"
)
vim.keymap.set(
"n",
"<leader>r",
"<cmd>lua require('lvim.core.terminal')._exec_toggle({cmd='go run .;read',count=3,direction='float'})<CR>"
)
end,
})
create_aucmd("FileType", {
group = "_lvim_user",
pattern = "python",
callback = function()
vim.keymap.set(
"n",
"<leader>r",
"<cmd>lua require('lvim.core.terminal')._exec_toggle({cmd='python "
.. vim.fn.expand "%"
.. ";read',count=2,direction='float'})<CR>"
)
vim.keymap.set(
"n",
"<leader>m",
"<cmd>lua require('lvim.core.terminal')._exec_toggle({cmd='echo \"compile :pepelaugh:\";read',count=2,direction='float'})<cr>"
)
end,
})
end
return M