-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
342 lines (286 loc) · 11 KB
/
init.lua
File metadata and controls
342 lines (286 loc) · 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
local opt = vim.opt
local fn = vim.fn
local api = vim.api
local M = {}
-- vim.g.loaded_netrw = 1
-- vim.g.loaded_netrwPlugin = 1
opt.foldenable = false
opt.visualbell = true
opt.relativenumber = true
opt.inccommand = 'nosplit'
opt.cursorline = false
opt.cursorcolumn = false
opt.number = true
opt.confirm = true
opt.hidden = true
opt.clipboard:append({"unnamedplus"})
opt.list = true
opt.listchars = { tab = ' ', trail = '·', eol = '¬' }
opt.wrap = false
opt.path:remove "/usr/include"
opt.path:append "**"
opt.undofile = true
opt.signcolumn = 'yes'
opt.showtabline = 1
-- disable mouse
opt.mouse = ''
opt.laststatus = 2
-- Need to make Oil work properly
opt.splitright = true
-- opt.splitbelow = true
opt.foldlevel = 20
opt.foldmethod = 'expr'
opt.foldexpr = 'nvim_treesitter#foldexpr()'
-- Fuzzy matching
opt.wildmenu = true
opt.wildignore:append({"**/node_modules/**", "**/.git/**", "**/build/**", "**/dist/**"})
-- Backups
opt.swapfile = false
opt.backup = false
-- Indentation
opt.autoindent = true
opt.smartindent = false
opt.smarttab = true
opt.shiftwidth = 2
opt.softtabstop = 2
opt.tabstop = 2
opt.expandtab = true
vim.g.loaded_python3_provider = 0
vim.g.loaded_perl_provider = 0
-- vim.cmd([[
-- set langmap='ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ, фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz'
-- ]])
vim.g.langmap = 'ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ, фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz'
-- opt.keymap='russian-jcukenwin'
-- Nodejs host
-- if fn.executable('volta') == 1 then
-- vim.g.neovim_node_host = fn.trim(fn.system('volta which neovim-node-host'))
-- end
vim.g.host_ruby_prog = fn.trim(fn.system('which ruby'))
vim.g.mapleader = ','
vim.g.maplocalleader = ' '
-- function M.prependFileWithMagicComment()
-- local line = '# frozen_string_literal: true'
-- local currentLine = fn.getline(1)
-- if currentLine ~= line then
-- api.nvim_command("1s/^/" .. line .. "\r\r")
-- api.nvim_command("noh")
-- end
--
-- end
--
-- vim.api.nvim_create_user_command('Frt', M.prependFileWithMagicComment, { desc = 'Add magic comment line to file' })
function M.copyCurrentFilenameFromProjectRootToClipboard()
local filename = fn.expand('%:p')
filename = fn.fnamemodify(filename, ':~:.')
local projectRoot = fn.system('git rev-parse --show-toplevel')
projectRoot = fn.fnamemodify(projectRoot, ':~:.')
filename = fn.substitute(filename, projectRoot, '', '')
vim.fn.setreg('+', filename)
print('Filename copied to clipboard: ' .. filename)
end
vim.keymap.set('n', '<leader>cfp', M.copyCurrentFilenameFromProjectRootToClipboard)
function M.CloseCurrentBuffer()
local buffers = fn.getbufinfo({buflisted = 1})
if #buffers == 1 then
api.nvim_command('enew')
else
api.nvim_command('bp')
end
api.nvim_buf_delete(fn.bufnr('#'), {})
end
function M.DeleteHiddenBuffers()
local buffers = fn.getbufinfo({buflisted = 1})
local currentBufferNumber = fn.bufnr('%')
for _, buffer in ipairs(buffers) do
if buffer.hidden and buffer.bufnr ~= currentBufferNumber then
api.nvim_buf_delete(buffer.bufnr, {})
end
end
print('Hidden buffers deleted')
end
vim.keymap.set('n', '<leader>q', M.CloseCurrentBuffer, { silent = true, desc = 'Close current buffer' })
vim.keymap.set('n', '<leader>d', M.DeleteHiddenBuffers, { silent = true, desc = 'Delete hidden buffers' })
vim.cmd("let $NVIM_TUI_ENABLE_TRUE_COLOR=1")
opt.termguicolors = true
opt.background = 'dark'
-- local has_termguicolors = vim.fn.exists('+termguicolors')
-- if has_termguicolors then
-- vim.o.t_8f = "\27[38;2;%lu;%lu;%lum"
-- vim.o.t_8b = "\27[48;2;%lu;%lu;%lum"
-- end
-- vim.cmd('colorscheme gruvbox')
vim.keymap.set('n', '<leader>v', ':e $MYVIMRC<CR>', { desc = 'Edit vimrc' })
vim.keymap.set('n', '<leader><c-v>', ':cd /Users/random/.config/nvim/lua/plugins<CR>', { desc = 'Edit plugins' })
vim.keymap.set('n', '<leader>V', ':source $MYVIMRC<CR>', { desc = 'Reload vimrc' })
vim.keymap.set('n', '<leader>rs', ':syntax sync fromstart<CR>:redraw!<CR>', { desc = 'Reload syntax' })
vim.keymap.set('n', '<leader>fef', ':normal! gg=G``<CR>', { desc = 'Format file' })
vim.keymap.set('n', '<leader>g', function() vim.cmd("G") end, { desc = 'Git status' })
vim.keymap.set('n', '<C-k>', '<C-w><Up>', { silent = true, desc = 'Move to window above' })
vim.keymap.set('n', '<C-j>', '<C-w><Down>', { silent = true, desc = 'Move to window below' })
vim.keymap.set('n', '<C-l>', '<C-w><Right>', { silent = true, desc = 'Move to window right' })
vim.keymap.set('n', '<C-h>', '<C-w><Left>', { silent = true, desc = 'Move to window left' })
-- disable Shift+K in visual mode
vim.keymap.set('v', 'K', '<Nop>', { silent = true })
local filetypesMapping = {
css = '_cs',
coffee = '_co',
html = '_ht',
slim = '_sl',
javascript = '_js',
markdown = '_md',
ruby = '_rb',
sh = '_sh',
vim = '_vi',
yaml = '_an',
dockerfile = '_dc',
}
for lang, mapping in pairs(filetypesMapping) do
local command = function() vim.api.nvim_command(string.format('setlocal filetype=%s', lang)) end
vim.keymap.set('n', mapping, command, { silent = true, desc = 'Set filetype to ' .. lang })
end
vim.keymap.set('n', '<Up>', ':resize +2<CR>', { silent = true, desc = 'Increase window height' })
vim.keymap.set('n', '<Down>', ':resize -2<CR>', { silent = true, desc = 'Decrease window height' })
vim.keymap.set('n', '<Left>', ':vertical resize +2<CR>', { silent = true, desc = 'Increase window width' })
vim.keymap.set('n', '<Right>', ':vertical resize -2<CR>', { silent = true, desc = 'Decrease window width' })
vim.keymap.set('t', '<C-o>', [[<C-\><C-n>]], { silent = false, noremap = false, desc = 'Exit terminal mode' })
vim.keymap.set('n', 'Q', '@q', { silent = true, desc = 'Execute macro' })
vim.keymap.set('v', 'Q', ':norm @q<CR>', { silent = true, desc = 'Execute macro' })
vim.keymap.set('v', '<localleader>/', 'y/<C-R>"<CR>', { silent = true, desc = 'Search for selected text' })
vim.keymap.set('n', '<localleader>/', ':nohlsearch<CR>', { silent = true, desc = 'Clear search' })
-- vim.keymap.set('i', '<C-c>', '<Esc><Esc>', { silent = true })
vim.keymap.set('i', '<C-c>', '<NOP>', { silent = true, desc = 'Do nothing' })
-- Expand filename for commands like Espec
vim.keymap.set('c', '<c-e>', [[<C-R>=substitute(expand('%:r'), '^app[^/]*.', '', '')<CR>]], { desc = 'Expand filename' })
-- Open quickfix error in quickfix window
vim.keymap.set('n', '<localleader>q', [[:cg .git/quickfix.out<CR> :cwindow<CR>]], { desc = 'Open quickfix error in quickfix window' })
-- -- replaced with buddy.nvim plugin
-- function M.contains(list, x)
-- for _, v in pairs(list) do
-- if v == x then return true end
-- end
-- return false
-- end
-- function M.addDebuggerToNextLine()
-- local filetype = vim.bo.filetype
-- if filetype == 'lua' then
-- vim.api.nvim_command('normal obinding.pry')
-- elseif M.contains({'svelte', 'js', 'ts'}, filetype) then
-- vim.api.nvim_command('normal odebugger')
-- else
-- vim.api.nvim_command('normal obinding.pry')
-- end
-- end
--
-- vim.keymap.set('n', '<leader>/', M.addDebuggerToNextLine, { silent = true, desc = 'Add debugger to next line' })
function M.copyStrAndOpen()
-- local text = vim.fn.expand('<cword>')
-- vim.fn.setreg('+', text)
vim.api.nvim_command('normal! yi\'')
local text = vim.fn.getreg('+')
vim.fn.system('open https://github.com/' .. text)
end
vim.keymap.set('n', '<leader>op', M.copyStrAndOpen, { silent = true, desc = 'Copy word and open in browser' })
vim.keymap.set('n', '<leader>A', '<CMD>argadd %<CR>', { silent = false, desc = 'Add current file to arglist' })
-- function M.copyLinterError()
-- local current_line = vim.api.nvim_win_get_cursor(0)[1] - 1
-- local result = vim.diagnostic.get(fn.bufnr('%'), { lnum = current_line })
-- vim.fn.setreg('+', result[1].code)
-- end
--
-- vim.keymap.set('n', '<leader>cle', M.copyLinterError, { silent = true, desc = 'Copy linter error' })
-- inoremap <C-c> <Esc>
vim.keymap.set('i', '<C-c>', '<Esc>', { silent = true, desc = 'Exit insert mode' })
-- Function to insert issue ID into commit message
local function insert_issue_id()
-- Get current buffer contents
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
-- Find the line with the branch name
local branch_name_line = ""
for _, line in ipairs(lines) do
if line:match("^# On branch ") then
branch_name_line = line
break
end
end
-- Extract the issue ID from the branch name
local issue_id = branch_name_line:match("%w+%-%d+")
if not issue_id then
print("Issue ID could not be found in the branch name.")
return
end
-- Insert [ISSUE_ID] at the beginning of the first non-comment line
for i, line in ipairs(lines) do
if not line:match("^#") then
local new_line = "[" .. issue_id .. "] " .. line
vim.api.nvim_buf_set_lines(0, i - 1, i, false, {new_line})
break
end
end
end
-- Mapping <leader>i to the insert_issue_id function in .git/COMMIT_EDITMSG buffers
vim.api.nvim_create_autocmd("FileType", {
pattern = "gitcommit",
callback = function()
vim.keymap.set('n', '<leader>i', insert_issue_id, {buffer = true})
end,
})
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
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)
-- LSP formatting on <leader>ff
vim.keymap.set('n', '<leader>ff', function() vim.lsp.buf.format({async = true}) end, { silent = true, desc = 'Format with LSP' })
require("lazy").setup("plugins", {
install = { colorscheme = { "gruvbox", "habamax" } },
change_detection = {
enabled = true,
notify = false,
},
dev = {
path = "~/Projects/npupko"
},
checker = { enabled = false },
performance = {
rtp = {
disabled_plugins = {
"gzip",
"tarPlugin",
"tohtml",
"tutor",
"zipPlugin",
},
},
},
})
vim.api.nvim_create_autocmd("FileType", {
pattern = "ruby",
callback = function()
vim.bo.includeexpr = "v:lua.rails_container_to_file(v:fname)"
end,
})
function _G.rails_container_to_file(expr)
-- Debug output
vim.api.nvim_out_write("Original expression: " .. expr .. "\n")
-- Remove Container prefix and any potential trailing characters including the brackets
local container_path = expr:gsub('^Container%[["\']', ''):gsub('["\']%]$', '')
-- Debug output
vim.api.nvim_out_write("Container path: " .. container_path .. "\n")
-- Replace dots with directory separators
local file_path = container_path:gsub('%.', '/')
-- Append the .rb file extension
local result_path = 'app/services/' .. file_path .. '.rb'
-- Debug output
vim.api.nvim_out_write("Resulting file path: " .. result_path .. "\n")
return result_path
end
-- You can also add this line to ensure your 'path' includes the Rails directories
vim.opt.path:append { "app/**", "lib/**", "config/**", "test/**", "spec/**" }