-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathnvim-surround.lua
More file actions
156 lines (153 loc) · 6.82 KB
/
Copy pathnvim-surround.lua
File metadata and controls
156 lines (153 loc) · 6.82 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
-- Configure default highlight group.
vim.cmd.highlight("default link NvimSurroundHighlight Visual")
-- Intercept dot repeat action and save the cursor position, but only if the user is not currently completing a surround
-- action. This is done so `move_cursor = false` works with dot-repeating.
vim.on_key(function(key)
if key == "." and not require("nvim-surround").pending_surround then
require("nvim-surround").normal_curpos = require("nvim-surround.buffer").get_curpos()
end
end)
--[====================================================================================================================[
DEFAULT KEYMAPS
--]====================================================================================================================]
-- Boolean value determining if the default keymaps are set. This option takes precedence over all other
-- `g:nvim_surround_no_*_mappings` options.
---@type boolean
vim.g.nvim_surround_no_mappings = vim.g.nvim_surround_no_mappings or false
-- Boolean value determining if the default normal mode keymaps are set.
---@type boolean
vim.g.nvim_surround_no_normal_mappings = vim.g.nvim_surround_no_normal_mappings or false
-- Boolean value determining if the default visual mode keymaps are set.
---@type boolean
vim.g.nvim_surround_no_visual_mappings = vim.g.nvim_surround_no_visual_mappings or false
-- Boolean value determining if the default insert mode keymaps are set.
---@type boolean
vim.g.nvim_surround_no_insert_mappings = vim.g.nvim_surround_no_insert_mappings or false
if not vim.g.nvim_surround_no_mappings then
if not vim.g.nvim_surround_no_insert_mappings then
vim.keymap.set("i", "<C-g>s", "<Plug>(nvim-surround-insert)", {
desc = "Add a surrounding pair around the cursor (insert mode)",
})
vim.keymap.set("i", "<C-g>S", "<Plug>(nvim-surround-insert-line)", {
desc = "Add a surrounding pair around the cursor, on new lines (insert mode)",
})
end
if not vim.g.nvim_surround_no_normal_mappings then
vim.keymap.set("n", "ys", "<Plug>(nvim-surround-normal)", {
desc = "Add a surrounding pair around a motion (normal mode)",
})
vim.keymap.set("n", "yss", "<Plug>(nvim-surround-normal-cur)", {
desc = "Add a surrounding pair around the current line (normal mode)",
})
vim.keymap.set("n", "yS", "<Plug>(nvim-surround-normal-line)", {
desc = "Add a surrounding pair around a motion, on new lines (normal mode)",
})
vim.keymap.set("n", "ySS", "<Plug>(nvim-surround-normal-cur-line)", {
desc = "Add a surrounding pair around the current line, on new lines (normal mode)",
})
vim.keymap.set("n", "ds", "<Plug>(nvim-surround-delete)", {
desc = "Delete a surrounding pair",
})
vim.keymap.set("n", "cs", "<Plug>(nvim-surround-change)", {
desc = "Change a surrounding pair",
})
vim.keymap.set("n", "cS", "<Plug>(nvim-surround-change-line)", {
desc = "Change a surrounding pair, putting replacements on new lines",
})
end
if not vim.g.nvim_surround_no_visual_mappings then
vim.keymap.set("x", "S", "<Plug>(nvim-surround-visual)", {
desc = "Add a surrounding pair around a visual selection",
})
vim.keymap.set("x", "gS", "<Plug>(nvim-surround-visual-line)", {
desc = "Add a surrounding pair around a visual selection, on new lines",
})
end
end
--[====================================================================================================================[
<PLUG> KEYMAPS
--]====================================================================================================================]
vim.keymap.set("i", "<Plug>(nvim-surround-insert)", function()
require("nvim-surround").insert_surround({ line_mode = false })
end, {
desc = "Add a surrounding pair around the cursor (insert mode)",
silent = true,
})
vim.keymap.set("i", "<Plug>(nvim-surround-insert-line)", function()
require("nvim-surround").insert_surround({ line_mode = true })
end, {
desc = "Add a surrounding pair around the cursor, on new lines (insert mode)",
silent = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-normal)", function()
return require("nvim-surround").normal_surround({ line_mode = false })
end, {
desc = "Add a surrounding pair around a motion (normal mode)",
expr = true,
silent = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-normal-cur)", function()
return "<Plug>(nvim-surround-normal)Vg_"
end, {
desc = "Add a surrounding pair around the current line (normal mode)",
expr = true,
silent = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-normal-line)", function()
return require("nvim-surround").normal_surround({ line_mode = true })
end, {
desc = "Add a surrounding pair around a motion, on new lines (normal mode)",
expr = true,
silent = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-normal-cur-line)", function()
return "^" .. tostring(vim.v.count1) .. "<Plug>(nvim-surround-normal-line)g_"
end, {
desc = "Add a surrounding pair around the current line, on new lines (normal mode)",
expr = true,
silent = true,
})
vim.keymap.set("x", "<Plug>(nvim-surround-visual)", function()
local curpos = require("nvim-surround.buffer").get_curpos()
return string.format(
":lua require'nvim-surround'.visual_surround({ line_mode = false, curpos = { %d, %d }, curswant = %d })<CR>",
curpos[1],
curpos[2],
vim.fn.winsaveview().curswant
)
end, {
desc = "Add a surrounding pair around a visual selection",
silent = true,
expr = true,
})
vim.keymap.set("x", "<Plug>(nvim-surround-visual-line)", function()
local curpos = require("nvim-surround.buffer").get_curpos()
return string.format(
":lua require'nvim-surround'.visual_surround({ line_mode = true, curpos = { %d, %d }, curswant = 0 })<CR>",
curpos[1],
curpos[2]
)
end, {
desc = "Add a surrounding pair around a visual selection, on new lines",
silent = true,
expr = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-delete)", require("nvim-surround").delete_surround, {
desc = "Delete a surrounding pair",
expr = true,
silent = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-change)", function()
return require("nvim-surround").change_surround({ line_mode = false })
end, {
desc = "Change a surrounding pair",
expr = true,
silent = true,
})
vim.keymap.set("n", "<Plug>(nvim-surround-change-line)", function()
return require("nvim-surround").change_surround({ line_mode = true })
end, {
desc = "Change a surrounding pair, putting replacements on new lines",
expr = true,
silent = true,
})