-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
363 lines (336 loc) · 10.8 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
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
355
356
357
358
359
360
361
362
vim.opt.number = true
vim.opt.list = true
vim.opt.listchars:append("tab:> ")
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.cursorline = true
vim.opt.cursorcolumn = false
--plugins
vim.cmd([[packadd packer.nvim]]) --using packer as package manager
require("packer").startup(function(use)
use("wbthomason/packer.nvim")
use("Shatur/neovim-ayu")
require('ayu').colorscheme()
-- end gruvbox theme
-- use treesitter for lang highlight
use("nvim-treesitter/nvim-treesitter")
require("nvim-treesitter.configs").setup({
ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
highlight = {
enable = true,
},
})
--end treeseter
-- lua line
use("nvim-lualine/lualine.nvim")
require("lualine").setup({
options = {
icons_enabled = true,
theme = "ayu",
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 = {},
})
--end lualine
--brgin fzf (finding files quickly )
use("junegunn/fzf")
use("junegunn/fzf.vim")
--end fzf
-- nvim tree
-- file explorer
use("nvim-tree/nvim-tree.lua")
-- vs-code like icons
use("nvim-tree/nvim-web-devicons")
require("nvim-tree").setup({})
-- end nvim tree
-- vim-cmp
use("hrsh7th/nvim-cmp") -- The completion plugin
use("hrsh7th/cmp-buffer") -- buffer completions
use("hrsh7th/cmp-path") -- path completions
use("hrsh7th/cmp-cmdline") -- cmdline completions
use("saadparwaiz1/cmp_luasnip") -- snippet completions
use("hrsh7th/cmp-nvim-lsp")
-- snippets
use("L3MON4D3/LuaSnip") --snippet engine
use("rafamadriz/friendly-snippets") -- a bunch of snippets to use
-- LSP
use("neovim/nvim-lspconfig") -- enable LSP
use("williamboman/mason.nvim") -- simple to use language server installer
use("williamboman/mason-lspconfig.nvim") -- simple to use language server installer
use("jose-elias-alvarez/null-ls.nvim") -- LSP diagnostics and code actions
use("jose-elias-alvarez/typescript.nvim")
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = { "pyright", "tsserver", "html", "cssls", "eslint", "jsonls", "bashls", "dockerls", "yamlls" },
})
-- vscode like snipets LSP
require("luasnip.loaders.from_vscode").lazy_load()
local kind_icons = {
Text = "",
Method = "m",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
TypeParameter = "",
}
local cmp = require("cmp")
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
--vim.fn["vsnip#anonymous"](args.body) -- For vsnip users.
require("luasnip").lsp_expand(args.body) -- For luasnip users.
-- require('snippy').expand_snippet(args.body) -- For snippy users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For ultisnips users.
-- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set select to false to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
-- { name = 'vsnip' }, -- For vsnip users.
{ name = "luasnip" }, -- For luasnip users.,
{ name = 'emmet_ls' }
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = "buffer" },
}),
})
-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
--Set configuration for specific filetype.
--[[ cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
}, {
{ name = 'buffer' },
})
})
require("cmp_git").setup() ]]
--
-- Use buffer source for / and ? (if you enabled native_menu, this won't work anymore).
cmp.setup.cmdline({ "/", "?" }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
-- Use cmdline & path source for ':' (if you enabled native_menu, this won't work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
matching = { disallow_symbol_nonprefix_matching = false },
})
-- Set up lspconfig.
local lspconfig = require("lspconfig")
local capabilities = require("cmp_nvim_lsp").default_capabilities()
local servers = { "pyright", "tsserver", "html", "cssls", "eslint", "jsonls", "bashls", "dockerls", "yamlls" }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup({
capabilities = capabilities,
})
end
-- end vim-cmp snippets
-- teminal
use({
"akinsho/toggleterm.nvim",
tag = "*",
config = function()
require("toggleterm").setup({
shell = "/bin/bash",
size = 20,
open_mapping = [[<c-\>]],
hide_numbers = true,
shade_filetypes = {},
shade_terminals = true,
shading_factor = 2,
start_in_insert = true,
insert_mappings = true,
persist_size = true,
direction = "horizontal",
close_on_exit = true,
shell = vim.o.shell,
float_opts = {
border = "curved",
winblend = 0,
highlights = {
border = "Normal",
background = "#000000",
},
},
})
end,
})
-- end terminal
-- bufferline
use({ "akinsho/bufferline.nvim", tag = "*", requires = "nvim-tree/nvim-web-devicons" })
vim.opt.termguicolors = true
require("bufferline").setup({
options = {
numbers = "ordinal",
close_command = "bdelete! %d",
right_mouse_command = "bdelete! %d",
left_mouse_command = "buffer %d",
middle_mouse_command = nil,
indicator_icon = "▎",
buffer_close_icon = "",
modified_icon = "●",
close_icon = "",
left_trunc_marker = "",
right_trunc_marker = "",
max_name_length = 18,
max_prefix_length = 15,
tab_size = 18,
diagnostics = false,
custom_filter = function(buf_number)
-- Func to filter out unwanted buffer types
return true
end,
offsets = {
{
filetype = "NvimTree",
text = "File Explorer",
text_align = "center",
padding = 1,
},
},
show_buffer_icons = true,
show_buffer_close_icons = true,
show_close_icon = true,
show_tab_indicators = true,
persist_buffer_sort = true,
separator_style = "slant",
enforce_regular_tabs = true,
always_show_bufferline = true,
sort_by = "id",
},
})
--end bufferline
--autopairs ()[] ..
use("windwp/nvim-autopairs")
--setup autopairs
local status_ok, npairs = pcall(require, "nvim-autopairs")
if not status_ok then
return
end
npairs.setup({
check_ts = true,
ts_config = {
lua = { "string", "source" },
javascript = { "string", "template_string" },
java = false,
},
disable_filetype = { "TelescopePrompt", "spectre_panel" },
fast_wrap = {
map = "<M-e>",
chars = { "{", "[", "(", '"', "'" },
pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
offset = 0, -- Offset from pattern match
end_key = "$",
keys = "qwertyuiopzxcvbnmasdfghjkl",
check_comma = true,
highlight = "PmenuSel",
highlight_grey = "LineNr",
},
})
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } }))
--end autopairs
use({"prettier/vim-prettier",
run = "yarn install --frozen-lockfile --production",
ft = { "javascript", "typescript", "html", "css", "json", "markdown" }, -- Extensions à formater
})
local nvim_lsp = require('lspconfig')
nvim_lsp.tsserver.setup({
on_attach = function(client, bufnr)
-- Keybindings or additional settings for the LSP can go here
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<Cmd>lua vim.lsp.buf.rename()<CR>', opts)
end,
capabilities = vim.lsp.protocol.make_client_capabilities(),
filetypes = { "html" , "css" , "javascript", "javascriptreact", "typescript", "typescriptreact" }, -- Enable for React and TypeScript
root_dir = function() return vim.loop.cwd() end -- Set the root directory to the current working directory
})
require'lspconfig'.emmet_ls.setup({
filetypes = { 'html', 'css', 'typescriptreact', 'javascriptreact', 'javascript', 'typescript', 'scss', 'sass', 'less' },
})
end)
-- Map global leader from \ to space
vim.g.mapleader = " "
vim.api.nvim_set_keymap("n", "<leader>fr", ":History<CR>", { noremap = true })
vim.keymap.set("n", "<leader>a", ":NvimTreeFindFileToggle<cr>", { silent = true })
vim.keymap.set("n", "<leader>z", ":NvimTreeFocus<cr>", { silent = true })
vim.keymap.set("n", "<leader><right>", ":BufferLineCycleNext<cr>", { silent = true })
vim.keymap.set("n", "<leader><left>", ":BufferLineCyclePrev<cr>", { silent = true })
vim.keymap.set("n", "<leader>t", ":ToggleTerm<cr>", { silent = true })