-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
307 lines (271 loc) · 11.1 KB
/
init.lua
File metadata and controls
307 lines (271 loc) · 11.1 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
vim.pack.add({
'https://github.com/nvim-tree/nvim-web-devicons',
'https://github.com/nvim-lua/plenary.nvim',
'https://github.com/nvim-telescope/telescope.nvim',
'https://github.com/nvim-telescope/telescope-fzf-native.nvim',
'https://github.com/lewis6991/gitsigns.nvim',
'https://github.com/tpope/vim-fugitive',
'https://github.com/tpope/vim-surround',
'https://github.com/tpope/vim-abolish',
'https://github.com/tpope/vim-dadbod',
'https://github.com/kristijanhusak/vim-dadbod-ui',
'https://github.com/kristijanhusak/vim-dadbod-completion',
'https://github.com/nvim-treesitter/nvim-treesitter',
'https://github.com/nvim-treesitter/nvim-treesitter-context',
'https://github.com/navarasu/onedark.nvim',
'https://github.com/echasnovski/mini.ai',
'https://github.com/numToStr/Comment.nvim',
'https://github.com/mfussenegger/nvim-dap',
'https://github.com/nvim-lualine/lualine.nvim',
'https://github.com/neovim/nvim-lspconfig',
'https://github.com/hrsh7th/nvim-cmp',
'https://github.com/hrsh7th/cmp-nvim-lsp',
'https://github.com/L3MON4D3/LuaSnip',
})
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.expandtab = true
vim.opt.autoindent = true
vim.opt.smartindent = true
vim.opt.cursorline = true
vim.opt.nu = true
vim.opt.relativenumber = true
vim.opt.wrap = false
vim.opt.lazyredraw = true
vim.opt.redrawtime = 10000
vim.opt.maxmempattern = 20000
vim.opt.synmaxcol = 300
vim.opt.signcolumn = 'yes:1'
vim.opt.winborder = 'single'
-- vim.opt.shada = "NONE"
-- vim.opt.guicursor = 'n-v-c-sm:block,i-ci-ve:ver40,r-cr-o:hor20'
vim.opt.hlsearch = true
vim.opt.incsearch = true
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.scrolloff = 8
vim.opt.updatetime = 50
vim.opt.colorcolumn = "160"
vim.opt.showtabline = 0
vim.opt.updatetime = 300
vim.opt.timeoutlen = 500
vim.opt.autoread = true
vim.opt.autowrite = false
vim.opt.undofile = true -- Persistent undo
vim.opt.undodir = vim.fn.expand("~/.vim/undodir") -- Undo directory
-- vim.opt.iskeyword:append("-")
vim.opt.path:append("**") -- include subdirectories in search
vim.g.mapleader = ' '
vim.g.db_ui_execute_on_save = false
vim.g.db_ui_use_nerd_fonts = true
vim.g.ftplugin_sql_omni_key = '<C-S>'
vim.g.c_syntax_for_h = true
vim.fn.setreg("o", "_f:laOption<" .. string.char(3) .. "$i>" .. string.char(3) .. "j", "c")
--
-- vim.keymap.set('n', '<leader>pv', vim.cmd.Ex)
vim.keymap.set('n', 'Q', '<nop>')
-- vim.keymap.set('n', 'wq:', '<nop>')
vim.keymap.set('i', '<Escape>', '<nop>')
vim.keymap.set('v', '<Escape>', '<nop>')
vim.keymap.set('n', '<C-s>', ':w<CR>')
-- Move cursor where it's supposed to be
vim.keymap.set('n', 'J', 'mzJ`z')
vim.keymap.set('n', 'n', 'nzzzv')
vim.keymap.set('n', 'N', 'Nzzzv')
vim.keymap.set('n', 'gd', 'gdzzzv')
vim.keymap.set('v', '<C-j>', "J")
vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
vim.keymap.set('v', '<S-Down>', ":m '>+1<CR>gv=gv")
vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")
vim.keymap.set('v', '<S-Up>', ":m '<-2<CR>gv=gv")
vim.keymap.set('n', '<M-h>', '<C-w><');
vim.keymap.set('n', '<M-j>', '<C-w>+');
vim.keymap.set('n', '<M-k>', '<C-w>-');
vim.keymap.set('n', '<M-l>', '<C-w>>');
vim.keymap.set('n', '<C-M-h>', '10<C-w><');
vim.keymap.set('n', '<C-M-j>', '10<C-w>+');
vim.keymap.set('n', '<C-M-k>', '10<C-w>-');
vim.keymap.set('n', '<C-M-l>', '10<C-w>>');
-- Better indenting in visual mode
vim.keymap.set("v", "<", "<gv", { desc = "Indent left and reselect" })
vim.keymap.set("v", ">", ">gv", { desc = "Indent right and reselect" })
vim.keymap.set("n", "<leader>rc", ":e ~/.config/nvim/init.lua<CR>", { desc = "Edit config" })
-- vim.keymap.set('n', '<M-Left>', '<C-o>');
-- vim.keymap.set('n', '<M-Right>', '<C-i>');
vim.keymap.set({'c'}, '<C-k>', '<Up>');
vim.keymap.set({'c'}, '<C-j>', '<Down>');
vim.keymap.set({'i', 'n', 'x'}, '<Left>', '<nop>');
vim.keymap.set({'i', 'n', 'x'}, '<Right>', '<nop>');
vim.keymap.set({'i', 'n', 'x'}, '<Up>', '<nop>');
vim.keymap.set({'i', 'n', 'x'}, '<Down>', '<nop>');
vim.keymap.set({'n', 'x'}, 'H', '<nop>');
vim.keymap.set({'n', 'x'}, 'L', '<nop>');
vim.keymap.set('n', '<CR>', '<nop>');
vim.keymap.set('n', '<leader>/', ':let @/ = ""<CR>');
vim.keymap.set('v', '<leader>c', ':!sh<CR>');
vim.keymap.set('v', '<leader>sc', ':s/\\u/_\\l&/g<_c_r>:let @/ = ""<_c_r>');
-- For making macro execution extra fast...
-- Took wayyy too long to figure this out but, remember that when executing a command you remain in the same mode you are in so macros execute differently
-- vim.keymap.set('n', '@', function ()
-- local buf = vim.api.nvim_get_current_buf()
-- local ft = vim.filetype.match({ buf = buf })
-- vim.bo.filetype = ""
-- vim.cmd("noautocmd norm! " .. (vim.v.count or 1) .. "@" .. vim.fn.getcharstr())
-- vim.bo.filetype = ft
-- end, {})
vim.keymap.set({'v', 'x'}, '@', function ()
local buf = vim.api.nvim_get_current_buf()
local ft = vim.filetype.match({ buf = buf })
local reg = vim.fn.getcharstr()
vim.bo.filetype = ""
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-c>", true, false, true), "x", false)
vim.cmd("noautocmd \'<,\'>norm! " .. (vim.v.count or 1) .. "@" .. reg)
vim.bo.filetype = ft
end, {})
vim.cmd('ca S Subvert')
vim.api.nvim_create_user_command('Build', '!rm extension.xpi; npx webpack && zip -r extension.xpi dist/ manifest.json && cp -f extension.xpi ~/Development/test', {});
vim.api.nvim_create_user_command('W', 'w', {});
vim.api.nvim_create_user_command('DBS', 'tabnew | DBUI', {})
vim.api.nvim_create_user_command('TODO', 'vsplit | wincmd l | edit TODO', {})
vim.api.nvim_create_user_command('TODOH', 'vsplit | wincmd l | edit ~/todo', {})
-- I don't care if this throws
pcall(function ()
vim.api.nvim_del_user_command('EditQuery')
end)
-- vim.keymap.set('v', '<leader>cc', ':s/_\\w/\\u&/g<CR>:let @/ = ""<CR>');
-- this_is_a_test
-- vim.keymap.set('n', 'dsf', 'ds)dB', { silent = true });
-- vim.keymap.set('i', '<BS>', '<nop>');
-- vim.keymap.set('i', '{', '{<C-CR>}=kjkA<C-CR>');
-- vim.keymap.set('i', '(', '()i');
-- vim.keymap.set('i', '[', '[]i');
-- vim.keymap.set('i', '\'', '\'\'');
-- vim.keymap.set('i', '"', '""');
-- NOTE: donot trigger autocmd when executing macro
-- https://www.reddit.com/r/neovim/comments/tsol2n/comment/i2ugipm/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
-- vim.cmd([[
-- xnoremap @ :<C-U>execute "set ft= \| noautocmd '<,'>norm! " . v:count1 . "@" . getcharstr() . " \| filetype detect"<cr>
-- nnoremap @ <cmd>execute "set ft= \| noautocmd norm! " . v:count1 . "@" . getcharstr() . " \| filetype detect"<cr>
-- ]])
vim.cmd('autocmd FileType sql,mysql,plsql lua require(\'cmp\').setup.buffer({ sources = {{ name = \'vim-dadbod-completion\' }} })');
vim.cmd('autocmd FileType dbout setlocal nofoldenable')
vim.cmd('autocmd FileType mysql vnoremap <buffer> <CR> <Plug>(DBUI_ExecuteQuery)')
vim.cmd('autocmd FileType sql vnoremap <buffer> <CR> <Plug>(DBUI_ExecuteQuery)')
vim.cmd('autocmd FileType pgsql vnoremap <buffer> <CR> <Plug>(DBUI_ExecuteQuery)')
-- vim.api.nvim_create_autocmd("FileType", {
-- pattern = "dbout",
-- callback = function ()
-- local buf = vim.api.expand('<abuf>')
-- local filetype_stuff = vim.api.nvim_buf_get_option(buf, "filetype")
-- vim.api.nvim_buf_set_option(buf, "filetype", filetype_stuff .. " setlocal nofoldenable")
-- end
-- })
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = {"*"},
callback = function()
if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
vim.api.nvim_exec("normal! g'\"",false)
end
end
})
vim.filetype.add({
pattern = {
['.*%.rest'] = 'json',
['.*%.tpl'] = 'html',
}
})
-- The Best Plugin
--- Angular component navigation
vim.keymap.set('n', '<leader>h', function()
local file = vim.fn.expand('%')
local file, ext = file:match('(.*)%.(.*)')
if vim.fn.filereadable(file .. '.html') == 1 then
vim.cmd('e ' .. file .. '.html')
return
end
print("No html counterpart found for " .. file)
end)
vim.keymap.set('n', '<leader>s', function()
local file = vim.fn.expand('%')
local file, ext = file:match('(.*)%.(.*)')
if vim.fn.filereadable(file .. '.scss') == 1 then
vim.cmd('e ' .. file .. '.scss')
return
end
if vim.fn.filereadable(file .. '.css') == 1 then
vim.cmd('e ' .. file .. '.css')
return
end
print("No style counterpart found for " .. file)
end)
vim.keymap.set('n', '<leader>j', function()
local file = vim.fn.expand('%')
local file, ext = file:match('(.*)%.(.*)')
if vim.fn.filereadable(file .. '.ts') == 1 then
vim.cmd('e ' .. file .. '.ts')
return;
end
if vim.fn.filereadable(file .. '.js') == 1 then
vim.cmd('e ' .. file .. '.js')
return;
end
print("No script counterpart found for " .. file)
end)
vim.keymap.set('n', '<leader>i', function ()
vim.api.nvim_feedkeys("<C-n>", 'n', false)
vim.defer_fn(function() vim.cmd("call feedkeys(\"i1<CR>\")") end, 1000)
vim.lsp.buf.code_action()
-- vim.api.nvim_feedkeys("1<CR>", 'n', false)
end)
--- Autocomplete bracket pair
vim.keymap.set('i', '<CR>', function()
local line = vim.api.nvim_get_current_line()
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
local next_line = { false } -- vim.api.nvim_buf_get_lines(0, row, row + 1, false)
-- print(next_line[1])
local currentChar = line:sub(col, col);
if col < #line and (
(currentChar == '{' and line:sub(col + 1, col + 1) == '}') or
(currentChar == '[' and line:sub(col + 1, col + 1) == ']') or
(currentChar == '(' and line:sub(col + 1, col + 1) == ')') or
(currentChar == '>' and line:sub(col + 1, col + 1) == '<')
) then
return '<CR><CR>kV"_C'
end
if col == #line then
if currentChar == '{' and (not next_line[1] or not next_line[1]:match('^%s*}')) then
return '<CR><CR>}kV"_C'
end
if currentChar == '[' and (not next_line[1] or not next_line[1]:match('^%s*]')) then
return '<CR><CR>]kV"_C'
end
if currentChar == '(' and (not next_line[1] or not next_line[1]:match('^%s*)')) then
return '<CR><CR>)kV"_C'
end
end
-- print(line:sub(col, 1), line:sub(col + 1, 1))
-- return line:sub(col, 1) .. line:sub(col + 1, 1)
-- print("It is " .. line:sub(col, col) .. line:sub(col + 1, col + 1) .. #line .. col)
return '<CR>'
end, { expr = true });
local generalSettingsGroup = vim.api.nvim_create_augroup('General settings', { clear = true })
-- vim.api.nvim_create_autocmd("TextYankPost", {
-- group = generalSettingsGroup,
-- callback = function()
-- vim.highlight.on_yank()
-- end
-- })
vim.api.nvim_create_autocmd('FileType', {
pattern = { '*.api' },
callback = function()
print('execing')
vim.keymap.set('x', '<CR>', curl, { expr = true })
end,
group = generalSettingsGroup,
})
-- Create undo directory if it doesn't exist
local undodir = vim.fn.expand("~/.vim/undodir")
if vim.fn.isdirectory(undodir) == 0 then
vim.fn.mkdir(undodir, "p")
end