Created
December 21, 2023 04:53
-
-
Save jesseleite/a61c73757ea51b6ced1de6b61c568546 to your computer and use it in GitHub Desktop.
Toggle surrounding quote style mapping in Neovim (probably not perfect lol!)
This file contains 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
local toggle_surrounding_quote_style = function () | |
local current_line = vim.fn.line('.') | |
local next_single_quote = vim.fn.searchpos("'", 'cn') | |
local next_double_quote = vim.fn.searchpos('"', 'cn') | |
if next_single_quote[1] ~= current_line then | |
next_single_quote = false | |
end | |
if next_double_quote[1] ~= current_line then | |
next_double_quote = false | |
end | |
if next_single_quote == false and next_double_quote == false then | |
print('Could not find quotes on current line!') | |
elseif next_single_quote == false and next_double_quote ~= false then | |
vim.cmd.normal([[macs"'`a]]) | |
elseif next_single_quote ~= false and next_double_quote == false then | |
vim.cmd.normal([[macs'"`a]]) | |
elseif next_single_quote[2] > next_double_quote[2] then | |
vim.cmd.normal([[macs"'`a]]) | |
else | |
vim.cmd.normal([[macs'"`a]]) | |
end | |
end | |
vim.keymap.set('n', "<Leader>'", toggle_surrounding_quote_style) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loved this - I also wanted to give it support for backticks so tweaked it a lil bit