-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
357 lines (305 loc) · 12.5 KB
/
Copy pathinit.lua
File metadata and controls
357 lines (305 loc) · 12.5 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
343
344
345
346
347
348
349
350
351
352
353
354
-- Polyfill for Telescope/Treesitter compatibility in Neovim 0.12+
if not vim.treesitter.language.ft_to_lang then
vim.treesitter.language.ft_to_lang = function(ft)
return vim.treesitter.language.get_lang(ft) or ft
end
end
-- Automatically set the compiler environment variable for tree-sitter CLI on Windows
if vim.fn.has("win32") == 1 then
-- If cl.exe is not in PATH, but gcc is available, fall back to gcc
if vim.fn.executable("cl") == 0 and vim.fn.executable("gcc") == 1 then
vim.env.CC = "gcc"
elseif vim.fn.executable("cl") == 0 and vim.fn.executable("clang") == 1 then
vim.env.CC = "clang"
end
end
require 'mocha.options'
require 'mocha.keymaps'
-- vim.opt.mouse = ""
-- =============================
-- Lazy Package Manager
-- =============================
-- [[ Install `lazy.nvim` plugin manager ]]
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
if vim.v.shell_error ~= 0 then
error('Error cloning lazy.nvim:\n' .. out)
end
end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)
-- Setup lazy.nvim
require('lazy').setup({
{ -- Fuzzy Finder (files, lsp, etc)
'nvim-telescope/telescope.nvim',
event = 'VimEnter',
branch = 'master',
dependencies = {
'nvim-lua/plenary.nvim',
{ -- If encountering errors, see telescope-fzf-native README for installation instructions
'nvim-telescope/telescope-fzf-native.nvim',
-- `build` is used to run some command when the plugin is installed/updated.
-- This is only run then, not every time Neovim starts up.
build = 'make',
-- `cond` is a condition used to determine whether this plugin should be
-- installed and loaded.
-- cond = function()
-- return vim.fn.executable 'make' == 1
-- end,
},
{ 'nvim-telescope/telescope-ui-select.nvim' },
-- Useful for getting pretty icons, but requires a Nerd Font.
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
},
config = function()
local actions = require 'telescope.actions'
-- https://github.com/MagicDuck/grug-far.nvim/pull/305
local is_windows = vim.fn.has 'win64' == 1 or vim.fn.has 'win32' == 1
local vimfnameescape = vim.fn.fnameescape
local winfnameescape = function(path)
local escaped_path = vimfnameescape(path)
if is_windows then
local need_extra_esc = path:find '[%[%]`%$~]'
local esc = need_extra_esc and '\\\\' or '\\'
escaped_path = escaped_path:gsub('\\[%(%)%^&;]', esc .. '%1')
if need_extra_esc then
escaped_path = escaped_path:gsub("\\\\['` ]", '\\%1')
end
end
return escaped_path
end
local select_default = function(prompt_bufnr)
vim.fn.fnameescape = winfnameescape
local result = actions.select_default(prompt_bufnr, 'default')
vim.fn.fnameescape = vimfnameescape
return result
end
-- Telescope is a fuzzy finder that comes with a lot of different things that
-- it can fuzzy find! It's more than just a "file finder", it can search
-- many different aspects of Neovim, your workspace, LSP, and more!
--
-- The easiest way to use Telescope, is to start by doing something like:
-- :Telescope help_tags
--
-- After running this command, a window will open up and you're able to
-- type in the prompt window. You'll see a list of `help_tags` options and
-- a corresponding preview of the help.
--
-- Two important keymaps to use while in Telescope are:
-- - Insert mode: <c-/>
-- - Normal mode: ?
--
-- This opens a window that shows you all of the keymaps for the current
-- Telescope picker. This is really useful to discover what Telescope can
-- do as well as how to actually do it!
-- [[ Configure Telescope ]]
-- See `:help telescope` and `:help telescope.setup()`
require('telescope').setup {
-- You can put your default mappings / updates / etc. in here
-- All the info you're looking for is in `:help telescope.setup()`
--
defaults = {
mappings = {
i = {
['<cr>'] = select_default,
['<c-d>'] = actions.delete_buffer,
},
n = {
['<cr>'] = select_default,
['<c-d>'] = actions.delete_buffer,
['dd'] = actions.delete_buffer,
},
},
file_ignore_patterns = { 'node_modules', '.next', '.git' },
},
-- pickers = {}
extensions = {
['ui-select'] = {
require('telescope.themes').get_dropdown(),
},
},
}
-- Enable Telescope extensions if they are installed
-- pcall(require('telescope').load_extension, 'fzf')
-- pcall(require('telescope').load_extension, 'ui-select')
-- See `:help telescope.builtin`
local builtin = require 'telescope.builtin'
vim.keymap.set('n', '<leader>sh', builtin.help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' })
vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sm', builtin.marks, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
local map = vim.keymap.set
-- [[ Window Navigation for Systems Mastery ]]
map('n', '<leader>wh', '<C-w>h', { desc = 'Move focus [W]indow [H]eft (Left)' })
map('n', '<leader>wl', '<C-w>l', { desc = 'Move focus [W]indow [L]ight (Right)' })
map('n', '<leader>wk', '<C-w>k', { desc = 'Move focus [W]indow [K]up (Up)' })
map('n', '<leader>wj', '<C-w>j', { desc = 'Move focus [W]indow [J]own (Down)' })
-- Slightly advanced example of overriding default behavior and theme
vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
winblend = 10,
previewer = false,
})
end, { desc = '[/] Fuzzily search in current buffer' })
-- It's also possible to pass additional configuration options.
-- See `:help telescope.builtin.live_grep()` for information about particular keys
vim.keymap.set('n', '<leader>s/', function()
builtin.live_grep {
grep_open_files = true,
prompt_title = 'Live Grep in Open Files',
}
end, { desc = '[S]earch [/] in Open Files' })
-- Shortcut for searching your Neovim configuration files
vim.keymap.set('n', '<leader>sn', function()
builtin.find_files { cwd = vim.fn.stdpath 'config' }
end, { desc = '[S]earch [N]eovim files' })
end,
},
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
keys = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Local Keymaps (which-key)",
},
},
},
require 'mocha.plugins.lualine',
require 'mocha.plugins.neotree',
require 'mocha.plugins.cord',
require 'mocha.plugins.lsp',
require 'mocha.plugins.cmp',
require 'mocha.plugins.wakatime',
require 'mocha.plugins.bufferline',
require 'mocha.plugins.oil',
-- require 'mocha.plugins.indents',
require 'mocha.plugins.themes',
require 'mocha.plugins.live-server',
require 'mocha.plugins.cake',
require 'mocha.plugins.wrapped',
require 'mocha.plugins.dap',
require 'mocha.plugins.treesitter',
require 'mocha.plugins.navic',
require 'mocha.plugins.trouble',
require 'mocha.plugins.surround',
require 'mocha.plugins.markdown',
require 'mocha.plugins.dashboard',
require 'mocha.plugins.persistence',
require 'mocha.plugins.jdtls',
require 'mocha.plugins.csharp',
})
--wakatime
--require("lazy").setup({
-- other plugins...
-- { "wakatime/vim-wakatime", lazy = false },
--})
local map = vim.keymap.set
local opts = { silent = true }
-- Horizontal split terminal
map('n', '<Leader>ht', ':split | terminal<CR>', opts)
-- Vertical split terminal
map('n', '<Leader>tv', ':vsplit | terminal<CR>', opts)
-- Floating terminal
-- map('n', '<Leader>tf', function()
-- vim.api.nvim_open_win(vim.api.nvim_create_buf(false, true), true, {
-- relative = 'editor',
-- width = math.floor(vim.o.columns * 0.8),
-- height = math.floor(vim.o.lines * 0.8),
-- row = math.floor(vim.o.lines * 0.1),
-- col = math.floor(vim.o.columns * 0.1),
-- style = 'minimal',
-- border = 'rounded',
-- })
-- vim.cmd('terminal')
-- end, opts)
local float_term_win
map('n', '<Leader>tf', function()
local buf = vim.api.nvim_create_buf(false, true)
float_term_win = vim.api.nvim_open_win(buf, true, {
relative = 'editor',
width = math.floor(vim.o.columns * 0.8),
height = math.floor(vim.o.lines * 0.8),
row = math.floor(vim.o.lines * 0.1),
col = math.floor(vim.o.columns * 0.1),
style = 'minimal',
border = 'rounded',
})
vim.cmd('terminal')
end, opts)
map('n', '<Leader>tj', function()
if float_term_win and vim.api.nvim_win_is_valid(float_term_win) then
vim.api.nvim_set_current_win(float_term_win)
end
end, opts)
-- Navigate between splits (normal + terminal mode)
map({'n', 't'}, '<C-h>', '<C-\\><C-N><C-w>h', opts)
map({'n', 't'}, '<C-j>', '<C-\\><C-N><C-w>j', opts)
map({'n', 't'}, '<C-k>', '<C-\\><C-N><C-w>k', opts)
map({'n', 't'}, '<C-l>', '<C-\\><C-N><C-w>l', opts)
-- Close current split
map('n', '<Leader>q', ':close<CR>', opts)
-- Horizontal empty split
map('n', '<Leader>hs', ':new<CR>', opts)
-- Vertical empty slit
map('n', '<Leader>vs', ':vnew<CR>', opts)
vim.api.nvim_set_option("clipboard", "unnamedplus")
-- [[ ARCHITECTURAL POLYFILL ]]
-- Fixes Telescope for Neovim 0.12+
vim.treesitter.ft_to_lang = function(ft)
return vim.treesitter.language.get_lang(ft) or ft
end
local map = vim.keymap.set
map("n", "<F6>", function()
local file = vim.fn.expand("%:p")
local filename = vim.fn.expand("%:t")
local filetype = vim.bo.filetype
local basename = vim.fn.expand("%:t:r")
local dir = vim.fn.fnamemodify(file, ":h")
if filename == "" then
print("Save the file first.")
return
end
local cmd = nil
if filetype == "java" then
cmd = string.format('kitty --hold sh -c "cd %s && javac %s && java %s"', dir, filename, basename)
elseif filetype == "c" then
cmd = string.format('kitty --hold sh -c "cd %s && gcc %s -o %s && ./%s"', dir, filename, basename, basename)
elseif filetype == "cpp" then
cmd = string.format('kitty --hold sh -c "cd %s && g++ %s -o %s && ./%s"', dir, filename, basename, basename)
elseif filetype == "python" then
cmd = string.format('kitty --hold sh -c "python3 %s"', filename)
elseif filetype == "javascript" then
cmd = string.format('kitty --hold sh -c "node %s"', filename)
elseif filetype == "typescript" then
cmd = string.format('kitty --hold sh -c "ts-node %s"', filename)
elseif filetype == "sh" then
cmd = string.format('kitty --hold sh -c "bash %s"', filename)
elseif filetype == "lua" then
cmd = string.format('kitty --hold sh -c "lua %s"', filename)
elseif filetype == "go" then
cmd = string.format('kitty --hold sh -c "go run %s"', filename)
else
print("Unsupported filetype: " .. filetype)
return
end
vim.fn.jobstart({"sh", "-c", cmd})
end)