Created
April 8, 2019 21:55
-
-
Save Elv13/e9caf5399a0ccf41cda2f8cada9a9501 to your computer and use it in GitHub Desktop.
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
-- Get a string from the command prompt. | |
local function prompt(message) | |
return vim.api.nvim_call_function("input", {message}) | |
end | |
--- Bring sanity back to search, no idiotic magic by default | |
local function search() | |
local res = prompt("Search: "):gsub("/", "\\/") | |
vim.api.nvim_input("<cmd>/\\V"..res.."/<cr><esc>n") | |
end | |
--- Search and replace without idotic magic. | |
-- no more dozen of backslashes per minute... | |
local function replace() | |
local str = prompt("Search: "):gsub("/", "\\/") | |
local rep = prompt("Replace " ..str.." with: "):gsub("/", "\\/") | |
vim.api.nvim_input("<cmd>%s/\\V"..str.."/"..rep.."/gc<cr>") | |
end | |
-- CTRL+O to save (insert mode) | |
keymap.insert["<C-s>"] = cmd ":w" | |
keymap.normal["<C-s>"] = cmd ":w" | |
-- CTRL+W to search (insert mode) | |
keymap.insert["<C-w>"] = search | |
keymap.normal["<C-w>"] = search | |
keymap.insert["<C-f>"] = search | |
-- map CTRL+R to search and replace | |
keymap.insert["<C-r>"] = replace | |
keymap.normal["<C-r>"] = replace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment