79 lines
2.2 KiB
Lua
79 lines
2.2 KiB
Lua
-- C# specific settings and commands
|
|
vim.opt_local.tabstop = 4
|
|
vim.opt_local.shiftwidth = 4
|
|
vim.opt_local.expandtab = true
|
|
vim.opt_local.softtabstop = 4
|
|
|
|
-- C# specific commands
|
|
vim.api.nvim_create_user_command("CSharpBuild", function()
|
|
vim.cmd("!dotnet build")
|
|
end, { desc = "Build C# project with dotnet" })
|
|
|
|
vim.api.nvim_create_user_command("CSharpRun", function()
|
|
vim.cmd("!dotnet run")
|
|
end, { desc = "Run C# project with dotnet" })
|
|
|
|
vim.api.nvim_create_user_command("CSharpTest", function()
|
|
vim.cmd("!dotnet test")
|
|
end, { desc = "Run C# tests with dotnet" })
|
|
|
|
vim.api.nvim_create_user_command("CSharpRestore", function()
|
|
vim.cmd("!dotnet restore")
|
|
end, { desc = "Restore C# project dependencies" })
|
|
|
|
vim.api.nvim_create_user_command("CSharpClean", function()
|
|
vim.cmd("!dotnet clean")
|
|
end, { desc = "Clean C# project build artifacts" })
|
|
|
|
-- New project templates
|
|
vim.api.nvim_create_user_command("CSharpNewConsole", function()
|
|
local name = vim.fn.input("Project name: ")
|
|
if name ~= "" then
|
|
vim.cmd("!dotnet new console -n " .. name)
|
|
end
|
|
end, { desc = "Create new C# console application" })
|
|
|
|
vim.api.nvim_create_user_command("CSharpNewClassLib", function()
|
|
local name = vim.fn.input("Project name: ")
|
|
if name ~= "" then
|
|
vim.cmd("!dotnet new classlib -n " .. name)
|
|
end
|
|
end, { desc = "Create new C# class library" })
|
|
|
|
-- Quick snippets
|
|
local opts = { noremap = true, silent = true, buffer = true }
|
|
|
|
-- Console.WriteLine snippet
|
|
vim.keymap.set("n", "<leader>cw", "oConsole.WriteLine();<Esc>hi", opts)
|
|
vim.keymap.set("i", "cw", "Console.WriteLine();<Esc>hi", opts)
|
|
|
|
-- Main method snippet
|
|
vim.keymap.set("n", "<leader>cm", function()
|
|
local lines = {
|
|
"static void Main(string[] args)",
|
|
"{",
|
|
" ",
|
|
"}",
|
|
}
|
|
vim.api.nvim_put(lines, "l", true, true)
|
|
vim.cmd("normal! 2j$")
|
|
end, opts)
|
|
|
|
-- Class template snippet
|
|
vim.keymap.set("n", "<leader>cc", function()
|
|
local filename = vim.fn.expand("%:t:r")
|
|
local class_name = filename:gsub("^%l", string.upper)
|
|
|
|
local lines = {
|
|
"namespace " .. vim.fn.fnamemodify(vim.fn.getcwd(), ":t"),
|
|
"{",
|
|
" public class " .. class_name,
|
|
" {",
|
|
" ",
|
|
" }",
|
|
"}",
|
|
}
|
|
vim.api.nvim_put(lines, "l", true, true)
|
|
vim.cmd("normal! 4j$")
|
|
end, opts)
|