-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.lua
308 lines (267 loc) · 9.38 KB
/
init.lua
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
-- leader keymaps
vim.g.mapleader = " "
vim.keymap.set("n","<leader>pv",vim.cmd.Ex)
vim.keymap.set("n","<leader>nt",vim.cmd.Neotree)
vim.keymap.set("n","<leader>md",vim.cmd.MarkdownPreviewToggle) --only works on md files
vim.keymap.set("n","<leader>cs","<cmd>Telescope colorscheme<cr>") -- added colorscheme keybind
vim.cmd('set number')
vim.cmd('colorscheme default')
vim.cmd('tnoremap <Esc> <C-/><C-n>') --remap terminal for insert to normal mode
function open_terminal()
-- make vertical split
vim.cmd("vsplit")
vim.cmd("set nonumber")
vim.cmd("cd %:p:h") -- terminal now opens in current directory
vim.cmd("terminal")
vim.cmd("startinsert") --enter insert mode
end
vim.keymap.set("n","<leader>ot","<cmd>lua open_terminal()<cr>")
local packer = require('packer')
packer.util = require('packer.util')
packer.startup(function()
local use = use
-- add you plugins here like:
-- use 'neovim/nvim-lspconfig'
use {
'nvim-telescope/telescope.nvim', tag = '0.1.5',
-- or , branch = '0.1.x',
requires = { {'nvim-lua/plenary.nvim'} }
}
use { "williamboman/mason.nvim"}
use {
"iamcco/markdown-preview.nvim",
run = function() vim.fn["mkdp#util#install"]() end,
}
use {
'nvim-lualine/lualine.nvim',
requires = { 'nvim-tree/nvim-web-devicons', opt = true }
}
use { 'dccsillag/magma-nvim', run = ':UpdateRemotePlugins' }
use {"williamboman/mason.nvim"} -- mason
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
}
use {
"startup-nvim/startup.nvim",
requires = {"nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim"},
config = function()
require"startup".setup({theme = 'clax'})
end
}
use {
"L3MON4D3/LuaSnip",
-- follow latest release.
tag = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
-- install jsregexp (optional!:).
run = "make install_jsregexp"
}
use {"hrsh7th/nvim-cmp"} --completion plugin
use {"hrsh7th/cmp-buffer"} --source for text in buffer
use {"hrsh7th/cmp-path"} --source for file system paths
use{"saadparwaiz1/cmp_luasnip"} -- for autocompletion
use{"rafamadriz/friendly-snippets"} -- useful snippets
use {
"windwp/nvim-autopairs",
config = function() require("nvim-autopairs").setup {} end
}
use { 'nvim-tree/nvim-web-devicons'}
use {'romgrk/barbar.nvim'}
use 'andweeb/presence.nvim'
use {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
requires = {
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
}
}
end
)
-- keymaps
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>lg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>of', builtin.oldfiles, {})
vim.keymap.set('n', '<leader>nf', vim.cmd.new, {})
-- treesitter config
require'nvim-treesitter.configs'.setup {
ensure_installed = { "c", "lua", "vim", "python", "javascript", "typescript", "bash", "go", "rust","html","css", },
sync_install = false,
auto_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
}
-- import nvim-cmp plugin safely
local cmp_status, cmp = pcall(require, "cmp")
if not cmp_status then
return
end
-- import luasnip plugin safely
local luasnip_status, luasnip = pcall(require, "luasnip")
if not luasnip_status then
return
end
-- load VSCode-like snippets from plugins (e.g., friendly-snippets)
require("luasnip/loaders/from_vscode").lazy_load()
vim.opt.completeopt = "menu,menuone,noselect"
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
["<C-e>"] = cmp.mapping.abort(), -- close completion window
["<CR>"] = cmp.mapping.confirm({ select = false }),
}),
-- sources for autocompletion
sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- LSP
{ name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within the current buffer
{ name = "path" }, -- file system paths
}),
})
-- Load friendly snippets
require("luasnip/loaders/from_vscode").lazy_load()
-- HTML snippets
local html_snippets = {
htmldoc = "<!DOCTYPE html>\n<html>\n<head>\n\t<title>${1:Title}</title>\n</head>\n<body>\n\t$0\n</body>\n</html>",
div = "<div>${0}</div>",
span = "<span>${0}</span>",
a = "<a href=\"${1:#}\">${2:Link}</a>",
img = "<img src=\"${1:path/to/image}\" alt=\"${2:Alt text}\">",
input = "<input type=\"${1:text}\" name=\"${2:name}\" id=\"${3:id}\"${4: value=\"${5:}\"}>",
-- Add more HTML snippets as needed
}
-- React.js snippets
local react_snippets = {
rfce = "import React from 'react';\n\nfunction ${1:ComponentName}() {\n\treturn (\n\t\t<div>\n\t\t\t$0\n\t\t</div>\n\t);\n}\n\nexport default ${1:ComponentName};",
useState = "const [${1:state}, set${2:State}] = React.useState(${3:initialState});",
useEffect = "React.useEffect(() => {\n\t$0\n}, []);",
-- Add more React.js snippets as needed
}
-- Next.js snippets
local nextjs_snippets = {
nextpage = "import React from 'react';\nimport Head from 'next/head';\n\nfunction ${1:PageName}() {\n\treturn (\n\t\t<div>\n\t\t\t<Head>\n\t\t\t\t<title>${2:Page Title}</title>\n\t\t\t</Head>\n\t\t\t$0\n\t\t</div>\n\t);\n}\n\nexport default ${1:PageName};",
-- Add more Next.js snippets as needed
}
-- JSX/TSX snippets
local jsx_tsx_snippets = {
tsxdoc = "import React from 'react';\n\ninterface Props {\n\t$0\n}\n\nconst ${1:ComponentName}: React.FC<Props> = ({ $2 }) => {\n\treturn (\n\t\t<div>\n\t\t\t$3\n\t\t</div>\n\t);\n};\n\nexport default ${1:ComponentName};",
-- Add more JSX/TSX snippets as needed
}
-- Add HTML snippets
for trigger, snippet in pairs(html_snippets) do
luasnip.snippets[trigger] = luasnip.parser.parse_snippet({ trig = trigger, wordTrig = true }, snippet)
end
-- Add React.js snippets
for trigger, snippet in pairs(react_snippets) do
luasnip.snippets[trigger] = luasnip.parser.parse_snippet({ trig = trigger, wordTrig = true }, snippet)
end
-- Add Next.js snippets
for trigger, snippet in pairs(nextjs_snippets) do
luasnip.snippets[trigger] = luasnip.parser.parse_snippet({ trig = trigger, wordTrig = true }, snippet)
end
-- Add JSX/TSX snippets
for trigger, snippet in pairs(jsx_tsx_snippets) do
luasnip.snippets[trigger] = luasnip.parser.parse_snippet({ trig = trigger, wordTrig = true }, snippet)
end
-- barbar config
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
-- Move to previous/next
map('n', '<A-,>', '<Cmd>BufferPrevious<CR>', opts)
map('n', '<A-.>', '<Cmd>BufferNext<CR>', opts)
-- Re-order to previous/next
map('n', '<A-<>', '<Cmd>BufferMovePrevious<CR>', opts)
map('n', '<A->>', '<Cmd>BufferMoveNext<CR>', opts)
-- Goto buffer in position...
map('n', '<A-1>', '<Cmd>BufferGoto 1<CR>', opts)
map('n', '<A-2>', '<Cmd>BufferGoto 2<CR>', opts)
map('n', '<A-3>', '<Cmd>BufferGoto 3<CR>', opts)
map('n', '<A-4>', '<Cmd>BufferGoto 4<CR>', opts)
map('n', '<A-5>', '<Cmd>BufferGoto 5<CR>', opts)
map('n', '<A-6>', '<Cmd>BufferGoto 6<CR>', opts)
map('n', '<A-7>', '<Cmd>BufferGoto 7<CR>', opts)
map('n', '<A-8>', '<Cmd>BufferGoto 8<CR>', opts)
map('n', '<A-9>', '<Cmd>BufferGoto 9<CR>', opts)
map('n', '<A-0>', '<Cmd>BufferLast<CR>', opts)
-- Pin/unpin buffer
map('n', '<A-p>', '<Cmd>BufferPin<CR>', opts)
-- Close buffer
map('n', '<A-c>', '<Cmd>BufferClose<CR>', opts)
-- Wipeout buffer
-- :BufferWipeout
-- Close commands
-- :BufferCloseAllButCurrent
-- :BufferCloseAllButPinned
-- :BufferCloseAllButCurrentOrPinned
-- :BufferCloseBuffersLeft
-- :BufferCloseBuffersRight
-- Magic buffer-picking mode
map('n', '<C-p>', '<Cmd>BufferPick<CR>', opts)
-- Sort automatically by...
map('n', '<Space>bb', '<Cmd>BufferOrderByBufferNumber<CR>', opts)
map('n', '<Space>bd', '<Cmd>BufferOrderByDirectory<CR>', opts)
map('n', '<Space>bl', '<Cmd>BufferOrderByLanguage<CR>', opts)
map('n', '<Space>bw', '<Cmd>BufferOrderByWindowNumber<CR>', opts)
-- Other:
-- :BarbarEnable - enables barbar (enabled by default)
-- :BarbarDisable - very bad command, should never be used
--
--
--
--
-- lualine config
require('lualine').setup {
options = {
icons_enabled = true,
theme = 'gruvbox-material',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
-- mason
require("mason").setup()