Skip to content

Instantly share code, notes, and snippets.

@keaising
Last active August 17, 2023 06:33
Show Gist options
  • Select an option

  • Save keaising/c90c3958ed43f8dad698a66355f65843 to your computer and use it in GitHub Desktop.

Select an option

Save keaising/c90c3958ed43f8dad698a66355f65843 to your computer and use it in GitHub Desktop.
backtick.lua
function SearchBackticksInside(include)
-- search back for start `
vim.fn.search("`", "b")
if not include then
-- search 1st non-empty char
vim.fn.search("\\S")
end
vim.api.nvim_command("normal! m<")
-- search forward for end `
vim.fn.search("`")
if not include then
-- search back for lastet non-empty char
vim.fn.search("\\S", "b")
end
-- local end_pos = vim.fn.getcurpos()
vim.api.nvim_command("normal! m>")
vim.api.nvim_command("normal! `<v`>")
end
local opt = { silent = true, desc = "in backticks" }
vim.keymap.set("x", "i`", function()
SearchBackticksInside(false)
end, opt)
vim.keymap.set("o", "i`", function()
SearchBackticksInside(false)
end, opt)
opt = { silent = true, desc = "around backticks" }
vim.keymap.set("x", "a`", function()
SearchBackticksInside(true)
end, opt)
vim.keymap.set("o", "a`", function()
SearchBackticksInside(true)
end, opt)
@keaising
Copy link
Author

func main() {
	const str = `

some 

random content
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment