-- -- Custom keybindings -- -- Requirements local modes = require "modes" local window = require "window" -- Commands modes.add_cmds({ { ":tabmove, :tabm, :tm", "Move tab to a position", function (w, m) -- Start from zero to follow VIM standards if m.arg ~= nil then w.tabs:reorder(w.view, m.arg + 1) end end}, }) -- Remove some default bindings modes.remove_binds("normal", { "y" }) -- Add custom binds modes.add_binds("normal", { { "", "Go back in the browser history `[count=1]` items.", function (w, m) w:back(m.count) end }, { "", "Go forward in the browser history `[count=1]` times.", function (w, m) w:forward(m.count) end }, { "h", "New blank tab", function (w) w:new_tab('luakit://newtab') end}, }) -- Add custom Yank bindings modes.add_binds("normal", { -- Yank URL { "^yy$", function (w) local uri = string.gsub(w.view.uri or "", " ", "%%20") luakit.selection.primary = uri luakit.selection.clipboard = uri w:notify("Yanked uri: " .. uri) end}, -- Yank title { "^yt$", function (w) local title = w.view.title luakit.selection.primary = title luakit.selection.clipboard = uri w:notify("Yanked title: " .. title) end}, -- Yank URL and title as a Markdown link { "^ym$", function (w) local title = w.view.title local uri = string.gsub(w.view.uri or "", " ", "%%20") local link = '[' .. title .. '](' .. uri .. ')' luakit.selection.primary = link luakit.selection.clipboard = link w:notify("Yanked as markdown link: " .. link) end}, -- Yank URL and title as a reStructuredText link { "^yr$", function (w) local title = w.view.title local uri = string.gsub(w.view.uri or "", " ", "%%20") local link = '`' .. title .. ' <' .. uri .. '>`_' luakit.selection.primary = link luakit.selection.clipboard = link w:notify("Yanked as reStructuredText link: " .. link) end}, -- Yank URL and title as a Trac link { "^yc$", function (w) local title = w.view.title local uri = string.gsub(w.view.uri or "", " ", "%%20") local link = '[' .. uri .. ' ' .. title .. ']' luakit.selection.primary = link luakit.selection.clipboard = link w:notify("Yanked as Trac link: " .. link) end}, -- Yank URL and title as an HTML link { "^yh$", function (w) local title = w.view.title local uri = string.gsub(w.view.uri or "", " ", "%%20") local link = '' .. title .. '' luakit.selection.primary = link luakit.selection.clipboard = link w:notify("Yanked as HTML link: " .. link) end}, -- Yank URL and title as a shareable link { "^ys$", function (w) local title = w.view.title local uri = string.gsub(w.view.uri or "", " ", "%%20") local link = title .. ' - ' .. uri luakit.selection.primary = link luakit.selection.clipboard = link w:notify("Yanked as shareable link: " .. link) end}, -- Reload all tabs -- Needs work -- See https://www.reddit.com/r/luakit/comments/pjepd/bind_a_shortcut_to_reload_all_tabs/ --{ "^R$", function (w) -- for ti = 1, w.tabs:count() do -- w.tabs:atindex(ti):reload() -- end --end}, })