Last active
August 17, 2023 06:33
-
-
Save keaising/c90c3958ed43f8dad698a66355f65843 to your computer and use it in GitHub Desktop.
backtick.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Author
keaising
commented
Aug 17, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment