M.toggle_boolean_value_on_line=function()-- https://github.com/sagarrakshe/toggle-bool/blob/master/plugin/toggle_bool.pylocalvalues={["true"]="false",["false"]="true",["on"]="off",["off"]="on",["yes"]="no",["no"]="yes",["1"]="0",["0"]="1",["enable"]="disable",["disable"]="enable",["enabled"]="disabled",["disabled"]="enabled",["before"]="after",["after"]="before",["first"]="last",["last"]="first",["up"]="down",["down"]="up",}localfunctiontoggle_bool_value(word)localtoggleWord=values[word]iftoggleWord==nilthen-- Check if the word ends with a commalocalwordWithoutComma=word:match("^(.-),$")ifwordWithoutCommaandvalues[wordWithoutComma]thenreturnvalues[wordWithoutComma]..","endreturnwordendreturntoggleWordendlocalcurrent_line=vim.api.nvim_get_current_line()localindent=current_line:match("^%s*")-- Get the leading whitespacelocalline_words={}localbool_count=0forwordincurrent_line:gmatch("[%w_'\"=]+[,]?")doifvalues[word]~=nilorvalues[word:sub(1,-2)]~=nilthenbool_count=bool_count+1endtable.insert(line_words,word)endlocalcursor_word=vim.fn.expand("<cword>")ifbool_count==1thenfori,wordinipairs(line_words)doifvalues[word]~=nilorvalues[word:sub(1,-2)]~=nilorword:match("^.+,$")thenline_words[i]=toggle_bool_value(word)endendelsefori,wordinipairs(line_words)doifword==cursor_wordorword:match("^.+,$")thenline_words[i]=toggle_bool_value(word)breakendendendlocalnew_line=indent..table.concat(line_words," ")vim.api.nvim_set_current_line(new_line)end
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.