make replaceword safer
This commit is contained in:
parent
985b065925
commit
3ebe12e99d
1 changed files with 3 additions and 0 deletions
|
|
@ -14,9 +14,12 @@ end
|
||||||
function M.replaceword(old, new)
|
function M.replaceword(old, new)
|
||||||
local conf = vim.fn.stdpath("config").."/lua/conf/".."opts.lua"
|
local conf = vim.fn.stdpath("config").."/lua/conf/".."opts.lua"
|
||||||
local f = io.open(conf, "r")
|
local f = io.open(conf, "r")
|
||||||
|
if not f then return end
|
||||||
local new_content = f:read("*all"):gsub(old, new)
|
local new_content = f:read("*all"):gsub(old, new)
|
||||||
|
f:close()
|
||||||
|
|
||||||
f = io.open(conf, "w")
|
f = io.open(conf, "w")
|
||||||
|
if not f then return end
|
||||||
f:write(new_content)
|
f:write(new_content)
|
||||||
f:close()
|
f:close()
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue