1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
--
-- 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", {
{ "<Mod1-Left>", "Go back in the browser history `[count=1]` items.", function (w, m) w:back(m.count) end },
{ "<Mod1-Right>", "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 = '<a href="' .. uri .. '">' .. title .. '</a>'
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},
})
|