forked from wsdjeg/SpaceVim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuffer.lua
More file actions
40 lines (35 loc) · 1.11 KB
/
buffer.lua
File metadata and controls
40 lines (35 loc) · 1.11 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
local M = {}
function M.set_lines(bufnr, startindex, endindex, replacement)
if startindex < 0 then
startindex = #vim.buffer(bufnr) + 1 + startindex
end
if endindex < 0 then
endindex = #vim.buffer(bufnr) + 1 + endindex
end
if #replacement == endindex - startindex then
for i = startindex, endindex - 1, 1
do
vim.buffer(bufnr)[i + 1] = replacement[i - startindex]
end
else
if endindex < #vim.buffer(bufnr) then
for i = endindex + 1, #vim.buffer(bufnr), 1
do
replacement:add(vim.buffer(bufnr)[i])
end
end
for i = startindex, #replacement + startindex - 1, 1
do
if i + 1 > #vim.buffer(bufnr) then
vim.buffer(bufnr):insert(replacement[i - startindex])
else
vim.buffer(bufnr)[i + 1] = replacement[i - startindex]
end
end
for i = #replacement + startindex + 1, #vim.buffer(bufnr), 1
do
vim.buffer(bufnr)[#replacement + startindex + 1] = nil
end
end
end
return M