summaryrefslogtreecommitdiff
path: root/after/ftplugin/c.lua
blob: a33d4e57f26bc86035e89d003af3ad02e6f35005 (plain)
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
local function mapcmd(command)
	return function()
		vim.cmd(command)
	end
end

local map = vim.keymap.set
map("n", ",p", [[<cmd>s/\(\s*\)\(.\+\)/\1printf("\2: %d\\n", \2);<cr>]], { desc = "Surround var with printf" })
map("n", ",i", function()
	local word = vim.fn.expand("<cword>")
	vim.cmd([[
	normal m'
	0
	normal O
	.!include.sh ]] .. word)
	vim.cmd("normal ''")
end, { desc = "Include header for word under cursor" })
map("n", ",f", mapcmd("CF"), { desc = "Toggle formatting" })
map("i", "<M-1>", "#if 1<cr>#endif<esc>O", { desc = "Insert `#if 1` block" })

vim.opt.commentstring = "// %s"
-- disable indent in switch statement
vim.opt.cinoptions = "l1"
local projects = require("config.projects")
if projects and not projects.IsInProject then
	vim.bo.makeprg = "./build.sh"
end

vim.cmd("TSDisable indent")