Skip to content

Instantly share code, notes, and snippets.

@titouancreach
Created September 6, 2023 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titouancreach/7a30acb1e2f43955d8e6ef92e72beba1 to your computer and use it in GitHub Desktop.
Save titouancreach/7a30acb1e2f43955d8e6ef92e72beba1 to your computer and use it in GitHub Desktop.
interpolated string C#
{
"InsertCharPre",
{
pattern = { "*.cs" },
--- @param opts AutoCmdCallbackOpts
--- @return nil
callback = function(opts)
-- Only run if f-string escape character is typed
if vim.v.char ~= "{" then return end
-- Get node and return early if not in a string
local node = vim.treesitter.get_node()
if not node then return end
if node:type() ~= "string_literal" then node = node:parent() end
if not node or node:type() ~= "string_literal" then return end
local row, col, _, _ = vim.treesitter.get_node_range(node)
vim.api.nvim_input("<Esc>m'" .. row + 1 .. "gg" .. col + 1 .. "|i$<Esc>`'la")
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment