-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
206 lines (196 loc) · 6.67 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
local g = vim.g
local opt = vim.opt
g.mapleader = " "
g.maplocalleader = ";"
opt.background = "light" -- dark, light
opt.backupcopy = "yes"
opt.breakindent = true
opt.clipboard:append("unnamedplus")
opt.completeopt = { "menu", "menuone", "noselect" }
opt.cursorline = true
opt.expandtab = true
opt.grepformat = "%f:%l:%m"
opt.grepprg = "rg --vimgrep -S "
opt.ignorecase = true
opt.infercase = true
opt.laststatus = 2
opt.number = true
opt.preserveindent = true
opt.pumheight = 10
opt.scrolloff = 5
opt.shiftround = true
opt.shiftwidth = 2
opt.shortmess = "c"
opt.sidescrolloff = 5
opt.signcolumn = "yes"
opt.smartcase = true
opt.smartindent = true
opt.splitbelow = true
opt.splitright = true
opt.tabstop = 2
opt.termguicolors = true
opt.winborder = "single"
opt.wrap = false
local function map(mode, lhs, rhs, opts)
if type(opts) == "string" then
vim.keymap.set(mode, lhs, rhs, { desc = opts })
else
vim.keymap.set(mode, lhs, rhs, opts)
end
end
map("v", "<", "<gv", "dedent")
map("v", ">", ">gv", "indent")
map("i", "<A-u>", "<c-r>=trim(system('uuidgen'))<cr>", "uuid")
map("n", "<A-u>", "i<c-r>=trim(system('uuidgen'))<cr><esc>", "uuid")
map("n", "-", ":Explore %:p:h<cr>", "open file manager")
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
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
local servers = {
cssls = {},
eslint = {},
html = {},
lua_ls = {
settings = {
Lua = {
completion = { callSnippet = "Replace" },
diagnostics = { globals = { "vim" } },
runtime = { version = "LuaJIT" },
telemetry = { enable = false },
workspace = { checkThirdParty = false, library = { vim.env.VIMRUNTIME } },
},
},
},
rust_analyzer = {},
ts_ls = {},
}
local diagnostic_config = { severity_sort = true, virtual_lines = false, virtual_text = true }
map("n", "<leader>k", function()
vim.diagnostic.config({ virtual_lines = { current_line = true }, virtual_text = false })
vim.api.nvim_create_autocmd("CursorMoved", {
group = vim.api.nvim_create_augroup("line-diagnostics", { clear = true }),
callback = function()
vim.diagnostic.config(diagnostic_config)
return true
end,
})
end)
require("lazy").setup({
{ "Mofiqul/vscode.nvim", lazy = true, priority = 1000, opts = { italic_comments = false } },
{
"lewis6991/gitsigns.nvim",
opts = {},
lazy = false,
keys = { { "<leader>gs", "<cmd>Gitsigns toggle_current_line_blame<cr>", desc = "toggle git blame" } },
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
opts = { disable_filetype = { "TelescopePrompt", "vim" }, map_cr = true, enable_check_bracket_line = false },
},
{
"saghen/blink.cmp",
dependencies = { "rafamadriz/friendly-snippets" },
version = "1.*",
opts = {
keymap = { preset = "enter" }, -- supertab, enter, none
completion = {
documentation = { auto_show = true },
menu = { draw = { columns = { { "label", "label_description", gap = 1 }, { "kind" } } } },
},
signature = { enabled = true },
sources = { default = { "lsp", "path", "snippets", "buffer" } },
fuzzy = { implementation = "prefer_rust_with_warning" },
},
opts_extend = { "sources.default" },
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
require("nvim-treesitter.install").prefer_git = true
require("nvim-treesitter.configs").setup({
auto_install = true,
ensure_installed = { "diff", "lua", "luadoc", "markdown", "markdown_inline", "vimdoc" },
highlight = { enable = true, additional_vim_regex_highlighting = false },
})
end,
},
{
"ibhagwan/fzf-lua",
opts = { { "ivy" }, winopts = { border = "none", preview = { border = "none" } } },
keys = {
{ "<leader>ff", ":silent FzfLua files<cr>", desc = "find files" },
{ "<leader>fr", ":silent FzfLua resume<cr>", desc = "resume search" },
{ "<leader>fb", ":silent FzfLua buffers<cr>", desc = "find buffer" },
{ "<leader>fg", ":silent FzfLua live_grep<cr>", desc = "find word" },
{ "<leader>fh", ":silent FzfLua helptags<cr>", desc = "find helptag" },
{ "<leader>fk", ":silent FzfLua keymaps<cr>", desc = "find keymap" },
{ "<leader>/", ":silent FzfLua lgrep_curbuf<cr>", desc = "find in buffer" },
},
},
{
"williamboman/mason.nvim",
dependencies = { "neovim/nvim-lspconfig", "ibhagwan/fzf-lua", "saghen/blink.cmp" },
config = function()
local fzf = require("fzf-lua")
local lspconfig = require("lspconfig")
require("mason").setup()
local capabilities = require("blink.cmp").get_lsp_capabilities(vim.lsp.protocol.make_client_capabilities())
vim.diagnostic.config({ severity_sort = true, virtual_text = true })
for server, config in pairs(servers) do
lspconfig[server].setup({
capabilities = capabilities,
flags = { debounce_text_changes = 150 },
settings = config.settings or {},
init_options = config.init_options or {},
})
end
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("config-lsp-attach", { clear = true }),
callback = function(event)
local buf = event.buf
map("n", "<leader>rn", vim.lsp.buf.rename, { buffer = buf })
map("n", "gr", fzf.lsp_references, { buffer = buf })
map("n", "gd", fzf.lsp_definitions, { buffer = buf })
map("n", "gD", fzf.lsp_typedefs, { buffer = buf })
map("n", "gI", fzf.lsp_implementations, { buffer = buf })
map("n", "<leader>ca", fzf.lsp_code_actions, { buffer = buf })
map("n", "<leader>xx", fzf.diagnostics_document, { buffer = buf })
map("n", "<leader>XX", fzf.diagnostics_workspace, { buffer = buf })
end,
})
end,
},
{
"stevearc/conform.nvim",
opts = {
format_on_save = { lsp_format = true, async = false },
formatters_by_ft = {
css = { "prettier", lsp_format = "fallback" },
html = { "prettier", lsp_format = "fallback" },
javascript = { "prettier", lsp_format = "fallback" },
javascriptreact = { "prettier", lsp_format = "fallback" },
json = { "prettier", lsp_format = "fallback" },
lua = { "stylua", lsp_format = "fallback" },
rust = { "rustfmt", lsp_format = "fallback" },
typescript = { "prettier", lsp_format = "fallback" },
typescriptreact = { "prettier", lsp_format = "fallback" },
},
},
},
})
vim.cmd.colorscheme("vscode") -- default, vscode
-- MasonInstall eslint-lsp css-lsp html-lsp typescript-language-server lua-language-server stylua prettier rustfmt