Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
163 lines (149 loc) · 4.42 KB
/
Copy pathinit.lua
File metadata and controls
163 lines (149 loc) · 4.42 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
157
158
159
160
161
162
163
local _, linux_py_libs = next(vim.fs.find("site-packages", { type = "directory", path = ".venv/lib" }))
local _, win_py_libs = next(vim.fs.find("site-packages", { type = "directory", path = ".venv/Lib" }))
if linux_py_libs ~= nil then
vim.fn.setenv("PYTHONPATH", linux_py_libs)
elseif win_py_libs ~= nil then
vim.fn.setenv("PYTHONPATH", win_py_libs)
end
-- if vim.fn.getcwd():match("/([^/]+)") == "mnt" then
-- vim.fn.setenv("IS_WSL_WIN", "1")
-- end
vim.g.mapleader = " "
vim.g.maplocalleader = " "
vim.filetype.add({
pattern = {
["just.vars"] = "sh",
[".coveragerc"] = "dosini",
[".flake8"] = "dosini",
["requirements.*.*"] = "requirements",
[".gcloudignore"] = "gitignore",
},
})
vim.keymap.set({ "n", "v", "i" }, "<c-z>", "<esc>u", { remap = true, desc = "undo" })
vim.opt.hlsearch = false
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.scrolloff = 10
vim.opt.guicursor = "n-v-c-sm:block,i-ci-ve:ver50,r-cr-o:hor20,a:blinkwait250-blinkoff500-blinkon500"
vim.opt.cursorline = true
vim.opt.mouse = "a"
vim.opt.wrap = false
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
---@diagnostic disable-next-line: undefined-field
if not vim.uv.fs_stat(lazypath) then
print("Lazy not present - git cloning")
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup("plugins")
vim.g.send_to_repl_pane = 2
local send_clean_code = function(line)
local pane_id = vim.g.send_to_repl_pane
local send_keys_prefix = "!tmux send-keys -t " .. pane_id .. " -l -- '"
local send_keys_suffix = "'"
line = line:gsub("'", "'\\''")
line = line:gsub("!", "\\!")
line = line:gsub("%%", "\\%%")
line = line:gsub("#", "\\#")
line = line:gsub(";$", ";;")
line = line:gsub(vim.api.nvim_replace_termcodes("<Tab>", true, true, true), " ")
vim.cmd(send_keys_prefix .. line .. send_keys_suffix)
vim.cmd("!tmux send-keys -t " .. pane_id .. " Enter")
end
local send_code = function()
local pane_id = vim.g.send_to_repl_pane
local mode = vim.api.nvim_get_mode().mode
local v_line = vim.fn.line("v")
local curs = vim.api.nvim_win_get_cursor(0)
local c_line = curs[1]
if mode ~= "n" and v_line == c_line then
local s_col, e_col
local v_col = vim.fn.col("v")
local c_col = curs[2]
if v_col < c_col then
s_col, e_col = v_col - 1, c_col + 1
else
s_col, e_col = c_col, v_col
end
local line = vim.api.nvim_buf_get_text(0, v_line - 1, s_col, c_line - 1, e_col, {})[1]
send_clean_code(line)
else
if mode == "n" and vim.api.nvim_get_current_line() == "" then
vim.cmd("!tmux send-keys -t " .. pane_id .. " Enter")
else
local indent_min = 100
local indent_last
local is_string = false
local cnt
for _, line in ipairs(vim.api.nvim_buf_get_lines(0, v_line - 1, c_line, false)) do
cnt = select(2, string.gsub(line, "'''", ""))
cnt = cnt + select(2, string.gsub(line, '"""', ""))
if math.fmod(cnt, 2) == 1 then
is_string = not is_string
end
if is_string then
send_clean_code(line)
elseif line:gsub("^%s+", "") ~= "" then
_, indent_last = string.find(line, "^%s*")
indent_min = math.min(indent_min, indent_last)
send_clean_code(line)
end
end
if is_string then
print("Incomplete multiline string sent to the terminal!")
end
end
end
vim.api.nvim_input("<esc>")
end
vim.keymap.set({ "v", "n" }, "<C-Bslash>", send_code, { desc = "Send code to REPL" })
-- vim.keymap.set(
-- { 'v', 'n' },
-- '<C-i>',
-- function () send_code(3) end,
-- { desc = 'Send code to REPL Pane 3' }
-- )
vim.api.nvim_create_autocmd("FileType", {
pattern = { "*" },
callback = function(args)
local buf = args.buf
local ft = vim.bo[buf].filetype
local buftype = vim.bo[buf].buftype
if buftype == "nofile" or buftype == "prompt" or buftype == "quickfix" then
return
end
local indent = 4
local expandtab = true
local two_space_fts = {
"css",
"html",
"json",
"javascript",
"javascriptreact",
"r",
"terraform",
"terraform-vars",
"typescript",
"typescriptreact",
"yaml",
}
if vim.list_contains(two_space_fts, ft) then
-- if two_space_fts[ft] then
indent = 2
elseif ft == "make" then
indent = 8
expandtab = false
end
vim.opt_local.tabstop = indent
vim.opt_local.expandtab = expandtab
vim.opt_local.softtabstop = indent
vim.opt_local.shiftwidth = indent
end,
})