-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinit.lua
More file actions
340 lines (296 loc) · 9.19 KB
/
init.lua
File metadata and controls
340 lines (296 loc) · 9.19 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
-- vim: ts=2 sts=2 sw=2 et
-- External tools required
-- Windows Terminal + pwsh
-- mingw64 toolchain: https://www.msys2.org/
-- ripgrep: https://github.com/BurntSushi/ripgrep
-- win32yank for clipboard integration
-- sharkdp/fd
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
-- bootstrap lazy.nvim
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
vim.g.loaded_python3_provider = 0
local opt = vim.opt
opt.encoding = "utf-8"
opt.fileencoding = "utf-8"
opt.clipboard = "unnamedplus"
opt.completeopt = "menu,menuone,noselect"
opt.mouse = "a"
opt.autowrite = true
opt.confirm = true
opt.inccommand = "nosplit"
opt.laststatus = 0
opt.list = true
opt.hlsearch = false
opt.ignorecase = true
opt.smartcase = true
opt.cursorline = true
opt.number = true
opt.relativenumber = true
opt.splitbelow = true
opt.splitright = true
opt.scrolloff = 4
opt.sidescrolloff = 8
opt.winminwidth = 5
opt.expandtab = true
opt.shiftwidth = 4
opt.shiftround = true
opt.tabstop = 4
opt.showmode = false
opt.signcolumn = "yes"
opt.termguicolors = true
opt.hidden = true
opt.undofile = true
opt.undolevels = 10000
opt.secure = true
opt.exrc = true
-- set leader key to space
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>')
-- terminal settings
local powershell_options = {
shell = vim.fn.executable "pwsh" == 1 and "pwsh" or "powershell",
shellcmdflag = "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;",
shellredir = "-RedirectStandardOutput %s -NoNewWindow -Wait",
shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode",
shellquote = "",
shellxquote = "",
}
for option, value in pairs(powershell_options) do
vim.opt[option] = value
end
vim.keymap.set('t', '<Esc>', "<C-\\><C-n>")
vim.keymap.set('t', '<C-w>', "<C-\\><C-n><C-w>")
-- minimize terminal split
vim.keymap.set('n', '<C-g>', "3<C-w>_")
-- plugins
require("lazy").setup({
-- theme
-- { "catppuccin/nvim", lazy = true, name = "catppuccin", priority=1000 },
{ "sainnhe/everforest", lazy = false, name = "everforest", priority=1000 },
-- devicons
{ "nvim-tree/nvim-web-devicons", lazy = true },
-- snippets
{ "L3MON4D3/LuaSnip", event = "VeryLazy",
config = function()
require("luasnip.loaders.from_lua").load({paths = "./snippets"})
end
},
-- language server protocol
{ "neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim"
},
config = function()
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
require('mason').setup()
local mason_lspconfig = require 'mason-lspconfig'
mason_lspconfig.setup {
ensure_installed = { "pyright" }
}
require("lspconfig").pyright.setup {
capabilities = capabilities,
}
end
},
-- autocompletion
{ "hrsh7th/nvim-cmp",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip"
},
config = function()
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local cmp = require('cmp')
local luasnip = require('luasnip')
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
completion = {
autocomplete = false
},
mapping = cmp.mapping.preset.insert ({
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<s-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<c-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select=true }),
}),
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
}
})
end
},
-- treesitter
{ "nvim-treesitter/nvim-treesitter", version = false,
build = function()
require("nvim-treesitter.install").update({ with_sync = true })
end,
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "python", "javascript" },
auto_install = false,
highlight = { enable = true, additional_vim_regex_highlighting = false },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-n>",
node_incremental = "<C-n>",
scope_incremental = "<C-s>",
node_decremental = "<C-m>",
}
}
})
end
},
-- fuzzy find
{ "nvim-telescope/telescope.nvim", cmd = "Telescope", version = false,
dependencies = { "nvim-lua/plenary.nvim" },
keys = {
{ "<leader>sf", "<cmd>Telescope git_files<cr>", desc = "Find Files (root dir)" },
{ "<leader><space>", "<cmd>Telescope buffers<cr>", desc = "Find Buffers" },
{ "<leader>sg", "<cmd>Telescope live_grep<cr>", desc = "Search Project" },
{ "<leader>ss", "<cmd>Telescope lsp_document_symbols<cr>", desc = "Search Document Symbols" },
{ "<leader>sw", "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>", desc = "Search Workspace Symbols" },
},
opts = {
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true,
case_mode = "smart_case"
}
}
}
},
{ "nvim-telescope/telescope-fzf-native.nvim",
build = "make",
config = function()
require('telescope').load_extension('fzf')
end
},
-- linting + formatting
{ "nvimtools/none-ls.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
null_ls.builtins.diagnostics.ruff,
null_ls.builtins.formatting.black,
}
})
end
},
-- terminal
{ "akinsho/toggleterm.nvim", event = "VeryLazy", version = "*",
opts = {
size = 10,
open_mapping = "<c-s>",
}
},
-- status line
{ "nvim-lualine/lualine.nvim", event = "VeryLazy",
opts = {
options = {
icons_enabled = true,
theme = 'onedark',
conponent_separators = '|',
section_separators = '',
}
},
},
-- bufferline
{ "akinsho/bufferline.nvim", version = "v4.*",
dependencies = "nvim-tree/nvim-web-devicons",
event = "VeryLazy",
keys = {
{ "<leader>bp", "<cmd>BufferLineTogglePin<CR>", desc="Toggle Buffer Pin" },
{ "<leader>bP", "<cmd>BufferLineGroupClose ungrouped<CR>", desc="Close Unpinned Buffers" },
},
opts = {
options = {
diagnostics = "nvim_lsp",
numbers = "buffer_id",
always_show_bufferline = false
}
}
},
-- auto pairing
{ "echasnovski/mini.pairs", event="VeryLazy",
config = function(_, opts)
require('mini.pairs').setup(opts)
end
},
-- surround text object
{ "echasnovski/mini.surround",
config = function(_, opts)
require('mini.surround').setup(opts)
end
},
-- show indent guides on blank lines
{ "lukas-reineke/indent-blankline.nvim",
main = "ibl",
---@module "ibl"
---@type ibl.config
opts = {
}
},
})
-- set colour scheme
vim.g.everforest_enable_italic = true
vim.cmd.colorscheme "everforest"
-- up / down with line wrap
vim.keymap.set('n', '<Up>', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', '<Down>', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- highlight yanked text
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = '*',
})
-- lsp keybindings
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, {desc = 'Rename Symbol'})
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, {desc = 'Goto Definition'})
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, {desc = 'Code Action'})
vim.keymap.set('n', 'K', vim.lsp.buf.hover, {desc = 'Hover Documentation'})
vim.keymap.set('n', '<leader>ff', vim.lsp.buf.format, {desc = 'Format Code'})
vim.diagnostic.config({
virtual_lines = { current_line=true }, -- Enables inline error/warning text
})