Krolyxon
Commit bcf3d26

Branches

Refs →

aurora.confignvimluaconfigautocmds.lua

113 lines · 3.0 KB · Lua

1-- Autocmds are automatically loaded on the VeryLazy event
2-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
3--
4-- Add any additional autocmds here
5-- with `vim.api.nvim_create_autocmd`
6--
7-- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults)
8-- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell")
9
10local autocmd = vim.api.nvim_create_autocmd
11
12-- remove trailing whitespaces on :w
13autocmd({ "bufwritepre" }, {
14 pattern = "*",
15 command = [[%s/\s\+$//e]],
16})
17
18-- spell check markdown and tex files
19vim.cmd([[
20 augroup spellCheck
21 autocmd!
22 autocmd Filetype plaintext setlocal spell
23 autocmd FileType markdown setlocal spell
24 autocmd BufRead,BufNewFile *.md setlocal spell
25 autocmd BufRead,BufNewFile *.rmd setlocal spell
26 autocmd BufRead,BufNewFile *.Rmd setlocal spell
27 autocmd BufRead,BufNewFile *.tex setlocal spell
28 augroup END
29]])
30
31local build_commands = {
32 c = "!g++ -std=c++17 -o %:p:r.o %",
33 cpp = "!g++ -std=c++17 -Wall -O2 -o %:p:r.o %",
34 rust = "!cargo build --release",
35 go = "!go build",
36 -- tex = "pdflatex %",
37 tex = "VimtexCompile",
38 javascript = "",
39 java = "!jrun %",
40}
41
42local debug_build_commands = {
43 c = "!g++ -std=c++17 -g -o %:p:r.o %",
44 cpp = "!g++ -std=c++17 -g -o %:p:r.o %",
45 rust = "!cargo build",
46 go = "!go build",
47}
48
49local run_commands = {
50 c = "%:p:r.o",
51 cpp = "%:p:r.o",
52 rust = "cargo run --release",
53 go = "go run .",
54 tex = "",
55 javascript = "node %",
56 python = "python3 %",
57}
58
59vim.api.nvim_create_user_command("Build", function()
60 local filetype = vim.bo.filetype
61
62 for file, command in pairs(build_commands) do
63 if filetype == file then
64 vim.cmd(command)
65 break
66 end
67 end
68end, {})
69
70vim.api.nvim_create_user_command("DebugBuild", function()
71 local filetype = vim.bo.filetype
72
73 for file, command in pairs(debug_build_commands) do
74 if filetype == file then
75 vim.cmd(command)
76 break
77 end
78 end
79end, {})
80
81vim.api.nvim_create_user_command("Run", function()
82 local filetype = vim.bo.filetype
83
84 for file, command in pairs(run_commands) do
85 if filetype == file then
86 vim.cmd("sp") -- Vertical split
87 -- vim.cmd("vs") -- Horizontal split
88 vim.cmd("term " .. command)
89 vim.cmd("resize 20N") -- Comment this if horizontal
90 local keys = vim.api.nvim_replace_termcodes("i", true, false, true)
91 vim.api.nvim_feedkeys(keys, "n", false)
92 break
93 end
94 end
95end, {})
96
97vim.api.nvim_create_user_command("Ha", function()
98 vim.cmd([[Build]])
99 vim.cmd([[Run]])
100end, {})
101
102vim.api.nvim_create_user_command("Config", function()
103 vim.cmd([[cd ~/.config/nvim]])
104end, {})
105
106
107-- Treat Arduino files (.ino) files as .cpp files
108vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
109 pattern = "*.ino",
110 callback = function()
111 vim.bo.filetype = "cpp"
112 end,
113})