config for working without LSP server
added some helper keybindings to efficiently search recursively for cwords and set makeprg and errorformat for C# projects and make a go-to-definition search for odin files
This commit is contained in:
+32
-16
@@ -102,29 +102,41 @@ vim.keymap.set('n', ',ct', function()
|
|||||||
vim.fn.system('ctags -R . &')
|
vim.fn.system('ctags -R . &')
|
||||||
end)
|
end)
|
||||||
do
|
do
|
||||||
-- ---@param keymap string
|
local function escaped(text)
|
||||||
-- ---@param search_for fun(): string
|
local _escaped = vim.fn.escape(text, "\\/.*$^~[]")
|
||||||
-- local function search_for_in_same_filetype(keymap, search_for)
|
local pattern = "\\V" .. _escaped
|
||||||
-- vim.keymap.set('n', keymap, function()
|
return pattern
|
||||||
-- local extension = vim.fn.expand("%:e")
|
end
|
||||||
-- vim.cmd("vimgrep \""..search_for().."\" */**."..extension)
|
---@param pattern string
|
||||||
-- end)
|
local function recursive_literal_vimgrep_in_same_filetype(pattern)
|
||||||
-- end
|
local extension = vim.fn.expand("%:e")
|
||||||
-- search_for_in_same_filetype( ',vs', function() return vim.fn.expand("<cword>") end)
|
vim.cmd("vimgrep /" .. pattern .. "/ **/*." .. extension)
|
||||||
-- search_for_in_same_filetype( ',vS', function() return vim.fn.expand("<cWORD>") end)
|
end
|
||||||
---@param keymap string
|
---@param keymap string
|
||||||
---@param search_for fun(): string
|
---@param search_for fun(): string
|
||||||
local function search_for_in_same_filetype(keymap, search_for)
|
local function search_for_in_same_filetype(keymap, search_for)
|
||||||
vim.keymap.set('n', keymap, function()
|
vim.keymap.set('n', keymap, function()
|
||||||
local extension = vim.fn.expand("%:e")
|
recursive_literal_vimgrep_in_same_filetype(search_for())
|
||||||
local escaped = vim.fn.escape(search_for(), "\\/.*$^~[]")
|
|
||||||
local pattern = "\\V" .. escaped
|
|
||||||
vim.cmd("vimgrep /" .. pattern .. "/ **/*." .. extension)
|
|
||||||
end, { desc = "Search for word under cursor in same filetype" })
|
end, { desc = "Search for word under cursor in same filetype" })
|
||||||
end
|
end
|
||||||
|
|
||||||
search_for_in_same_filetype(',vs', function() return vim.fn.expand("<cword>") end)
|
search_for_in_same_filetype(',vs', function() return escaped(vim.fn.expand("<cword>")) end)
|
||||||
search_for_in_same_filetype(',vS', function() return vim.fn.expand("<cWORD>") end)
|
search_for_in_same_filetype(',vS', function() return escaped(vim.fn.expand("<cWORD>")) end)
|
||||||
|
local file_specific = {
|
||||||
|
odin=function()
|
||||||
|
search_for_in_same_filetype(',vd', function()
|
||||||
|
local word = vim.fn.expand("<cword>")
|
||||||
|
local pattern = "\\v"..word.." *: *[:=]"
|
||||||
|
return pattern
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
callback=function()
|
||||||
|
local conf = file_specific[vim.bo.filetype]
|
||||||
|
if conf then conf() end
|
||||||
|
end
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({
|
vim.api.nvim_create_autocmd({
|
||||||
@@ -162,6 +174,10 @@ local file_specific = {
|
|||||||
vim.bo.makeprg = 'tcc -run %'
|
vim.bo.makeprg = 'tcc -run %'
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
cs = function()
|
||||||
|
vim.bo.makeprg = "dotnet build"
|
||||||
|
vim.bo.errorformat = "%f(%l\\,%c):\\ %t%*[^:]:\\ %m"
|
||||||
|
end,
|
||||||
python = function()
|
python = function()
|
||||||
vim.bo.makeprg = 'basedpyright && python3.13 %'
|
vim.bo.makeprg = 'basedpyright && python3.13 %'
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user