diff --git a/lua/spectre/config.lua b/lua/spectre/config.lua index cf61145..c9f735f 100644 --- a/lua/spectre/config.lua +++ b/lua/spectre/config.lua @@ -38,12 +38,12 @@ local config = { ['tab'] = { map = '', cmd = "lua require('spectre').tab()", - desc = 'next query' + desc = 'next query', }, ['shift-tab'] = { map = '', cmd = "lua require('spectre').tab_shift()", - desc = 'previous query' + desc = 'previous query', }, ['toggle_line'] = { map = 'dd', @@ -197,8 +197,8 @@ local config = { }, }, ['sd'] = { - cmd = "sd", - options = { }, + cmd = 'sd', + options = {}, }, }, default = { diff --git a/lua/spectre/replace/sd.lua b/lua/spectre/replace/sd.lua index caa8a03..0c3df01 100644 --- a/lua/spectre/replace/sd.lua +++ b/lua/spectre/replace/sd.lua @@ -15,7 +15,7 @@ sd.replace = function(self, value) -- Read the original file local lines = {} - local file = io.open(value.filename, "r") + local file = io.open(value.filename, 'r') for line in file:lines() do table.insert(lines, line) end @@ -23,26 +23,27 @@ sd.replace = function(self, value) if value.lnum <= #lines then -- Use `io.popen` to get the transformed line using `sd` - local command = string.format("echo '%s' | sd '%s' '%s'", lines[value.lnum], value.search_text, value.replace_text) + local command = + string.format("echo '%s' | sd '%s' '%s'", lines[value.lnum], value.search_text, value.replace_text) local handle = io.popen(command, 'r') if handle then - local transformedLine = handle:read("*a") + local transformedLine = handle:read('*a') handle:close() -- Replace the line in memory - lines[value.lnum] = transformedLine:gsub("\n$", "") -- Remove trailing newline added by `echo` + lines[value.lnum] = transformedLine:gsub('\n$', '') -- Remove trailing newline added by `echo` else self:on_error(false, value) return end else - log.debug("Line number out of bounds.") + log.debug('Line number out of bounds.') return end -- Write the modified lines back to the file - file = io.open(value.filename, "w") + file = io.open(value.filename, 'w') for _, line in ipairs(lines) do - file:write(line, "\n") + file:write(line, '\n') end file:close()