summaryrefslogtreecommitdiffstats
path: root/.config/nvim/plugin/backports.lua
blob: c6ba87b36a9d373aa79f8cf8eb3b6f01bd7e8065 (plain) (blame)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
-- backports from nightly to 0.10

-- LSP Stuff
vim.keymap.set('n', 'grn', function()
	vim.lsp.buf.rename()
end)

vim.keymap.set({ 'n', 'x' }, 'gra', function()
	vim.lsp.buf.code_action()
end)

vim.keymap.set('n', 'grr', function()
	vim.lsp.buf.references()
end)

vim.keymap.set('n', 'gri', function()
	vim.lsp.buf.implementation()
end)

vim.keymap.set('n', 'gO', function()
	vim.lsp.buf.document_symbol()
end)

vim.keymap.set({ 'i', 's' }, '<C-S>', function()
	vim.lsp.buf.signature_help()
end)

-- Terminal AutoSetup
vim.api.nvim_create_autocmd('TermOpen', {
	desc = 'Default settings for :terminal buffers',
	callback = function()
		vim.bo.modifiable = false
		vim.bo.undolevels = -1
		vim.bo.scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback)
		vim.bo.textwidth = 0
		vim.wo[0][0].wrap = false
		vim.wo[0][0].list = false
		vim.wo[0][0].number = false
		vim.wo[0][0].relativenumber = false
		vim.wo[0][0].signcolumn = 'no'
		vim.wo[0][0].foldcolumn = '0'

		-- This is gross. Proper list options support when?
		local winhl = vim.o.winhighlight
		if winhl ~= '' then
			winhl = winhl .. ','
		end
		vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC'
	end,
})

-- Vim Unpaired
-- ]<Space> and [<Space> not ported

--- Execute a command and print errors without a stacktrace.
--- @param opts table Arguments to |nvim_cmd()|
local function cmd(opts)
	local ok, err = pcall(vim.api.nvim_cmd, opts, {})
	if not ok then
		vim.api.nvim_err_writeln(err:sub(#'Vim:' + 1))
	end
end

-- Quickfix mappings
vim.keymap.set('n', '[q', function()
	cmd({ cmd = 'cprevious', count = vim.v.count1 })
end, { desc = ':cprevious' })

vim.keymap.set('n', ']q', function()
	cmd({ cmd = 'cnext', count = vim.v.count1 })
end, { desc = ':cnext' })

vim.keymap.set('n', '[Q', function()
	cmd({ cmd = 'crewind', count = vim.v.count ~= 0 and vim.v.count or nil })
end, { desc = ':crewind' })

vim.keymap.set('n', ']Q', function()
	cmd({ cmd = 'clast', count = vim.v.count ~= 0 and vim.v.count or nil })
end, { desc = ':clast' })

vim.keymap.set('n', '[<C-Q>', function()
	cmd({ cmd = 'cpfile', count = vim.v.count1 })
end, { desc = ':cpfile' })

vim.keymap.set('n', ']<C-Q>', function()
	cmd({ cmd = 'cnfile', count = vim.v.count1 })
end, { desc = ':cnfile' })

-- Location list mappings
vim.keymap.set('n', '[l', function()
	cmd({ cmd = 'lprevious', count = vim.v.count1 })
end, { desc = ':lprevious' })

vim.keymap.set('n', ']l', function()
	cmd({ cmd = 'lnext', count = vim.v.count1 })
end, { desc = ':lnext' })

vim.keymap.set('n', '[L', function()
	cmd({ cmd = 'lrewind', count = vim.v.count ~= 0 and vim.v.count or nil })
end, { desc = ':lrewind' })

vim.keymap.set('n', ']L', function()
	cmd({ cmd = 'llast', count = vim.v.count ~= 0 and vim.v.count or nil })
end, { desc = ':llast' })

vim.keymap.set('n', '[<C-L>', function()
	cmd({ cmd = 'lpfile', count = vim.v.count1 })
end, { desc = ':lpfile' })

vim.keymap.set('n', ']<C-L>', function()
	cmd({ cmd = 'lnfile', count = vim.v.count1 })
end, { desc = ':lnfile' })

-- Argument list
vim.keymap.set('n', '[a', function()
	cmd({ cmd = 'previous', count = vim.v.count1 })
end, { desc = ':previous' })

vim.keymap.set('n', ']a', function()
	-- count doesn't work with :next, must use range. See #30641.
	cmd({ cmd = 'next', range = { vim.v.count1 } })
end, { desc = ':next' })

vim.keymap.set('n', '[A', function()
	if vim.v.count ~= 0 then
		cmd({ cmd = 'argument', count = vim.v.count })
	else
		cmd({ cmd = 'rewind' })
	end
end, { desc = ':rewind' })

vim.keymap.set('n', ']A', function()
	if vim.v.count ~= 0 then
		cmd({ cmd = 'argument', count = vim.v.count })
	else
		cmd({ cmd = 'last' })
	end
end, { desc = ':last' })

-- Tags
vim.keymap.set('n', '[t', function()
	-- count doesn't work with :tprevious, must use range. See #30641.
	cmd({ cmd = 'tprevious', range = { vim.v.count1 } })
end, { desc = ':tprevious' })

vim.keymap.set('n', ']t', function()
	-- count doesn't work with :tnext, must use range. See #30641.
	cmd({ cmd = 'tnext', range = { vim.v.count1 } })
end, { desc = ':tnext' })

vim.keymap.set('n', '[T', function()
	-- count doesn't work with :trewind, must use range. See #30641.
	cmd({ cmd = 'trewind', range = vim.v.count ~= 0 and { vim.v.count } or nil })
end, { desc = ':trewind' })

vim.keymap.set('n', ']T', function()
	-- :tlast does not accept a count, so use :trewind if count given
	if vim.v.count ~= 0 then
		cmd({ cmd = 'trewind', range = { vim.v.count } })
	else
		cmd({ cmd = 'tlast' })
	end
end, { desc = ':tlast' })

vim.keymap.set('n', '[<C-T>', function()
	-- count doesn't work with :ptprevious, must use range. See #30641.
	cmd({ cmd = 'ptprevious', range = { vim.v.count1 } })
end, { desc = ' :ptprevious' })

vim.keymap.set('n', ']<C-T>', function()
	-- count doesn't work with :ptnext, must use range. See #30641.
	cmd({ cmd = 'ptnext', range = { vim.v.count1 } })
end, { desc = ':ptnext' })

-- Buffers
vim.keymap.set('n', '[b', function()
	cmd({ cmd = 'bprevious', count = vim.v.count1 })
end, { desc = ':bprevious' })

vim.keymap.set('n', ']b', function()
	cmd({ cmd = 'bnext', count = vim.v.count1 })
end, { desc = ':bnext' })

vim.keymap.set('n', '[B', function()
	if vim.v.count ~= 0 then
		cmd({ cmd = 'buffer', count = vim.v.count })
	else
		cmd({ cmd = 'brewind' })
	end
end, { desc = ':brewind' })

vim.keymap.set('n', ']B', function()
	if vim.v.count ~= 0 then
		cmd({ cmd = 'buffer', count = vim.v.count })
	else
		cmd({ cmd = 'blast' })
	end
end, { desc = ':blast' })