-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinit.lua
More file actions
264 lines (216 loc) · 9.19 KB
/
init.lua
File metadata and controls
264 lines (216 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
---@diagnostic disable: missing-fields
-- INFO: introduction
-- this is a minimal neovim configuration written in lua. this is not meant to
-- be a distribution, but rather a template for you to build upon and/or a
-- reference for how to configure neovim using lua in the latest version.
--
-- TUTOR:
-- if you're completely new to neovim and/or vim, consider going through
-- `:Tutor` inside neovim to get a basic idea of how it works.
-- if you don't know what this means, type the following:
-- - <escape key>
-- - :
-- - Tutor
-- - <enter key>
--
-- LUA:
-- some level of familiarity with lua/programming languages are also expected.
-- if you're new to lua, consider going through the official reference:
-- https://www.lua.org/manual
-- or a more friendly tutorial like:
-- https://learnxinyminutes.com/docs/lua/
-- you can also check out `:h lua-guide` inside neovim for a neovim-specific
-- lua guide.
--
-- DEPENDENCIES:
-- this configuration assumes you have the following tools installed on your
-- system:
-- `git` - for vim builtin package manager. (see `:h vim.pack`)
-- `ripgrep` - for fuzzy finding
-- clipboard tool: xclip/xsel/win32yank - for clipboard sharing between OS and neovim (see `h: clipboard-tool`)
-- a nerdfont (ensure the terminal running neovim is using it)
-- run `:checkhealth` inside neovim to see if your system is missing anything.
--
-- MINIMAL:
-- to say that something is 'minimal' you have to define what variable you're
-- minimizing. this configuration minimizes for lines of code and concepts.
-- to some, this configuration may have too many plugins. for example, using
-- mason.nvim to manage lsp servers will be an unnecessary dependency if the
-- user is already familiar with lsps and is comfortable managing them through
-- their OS package manager. but to someone that isn't familiar with lsp servers
-- this approach wouldn't cover everything needed to have the 'minimum' necessary
-- for lsp + completion + fuzzy finding. to some, fuzzy finding is also a bloated
-- dependency.
-- this configuration is only a starting point/reference. it is expected that
-- the user will change the configuration to suit their needs.
-- INFO: options
-- these change the default neovim behaviours using the 'vim.opt' API.
-- see `:h vim.opt` for more details.
-- run `:h '{option_name}'` to see what they do and what values they can take.
-- for example, `:h 'number'` for `vim.opt.number`.
-- set <space> as the leader key
-- must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- enable true color support
vim.opt.termguicolors = true
-- make line numbers default
vim.opt.number = true
vim.opt.relativenumber = true
-- enable mouse mode, can be useful for resizing splits
vim.opt.mouse = "a"
-- sync clipboard between OS and neovim.
-- remove this option if you want your OS clipboard to remain independent.
-- see `:help 'clipboard'`
vim.opt.clipboard = "unnamedplus"
-- save undo history
vim.opt.undofile = true
-- keep signcolumn on by default
vim.opt.signcolumn = "yes"
-- sets how neovim will display certain whitespace characters in the editor.
-- see `:help 'list'`
-- and `:help 'listchars'`
vim.opt.list = true
vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣", }
-- enable live preview of substitutions
vim.opt.inccommand = "split"
-- show which line your cursor is on
vim.opt.cursorline = true
-- set highlight on search, but clear on pressing <Esc> in normal mode
vim.opt.hlsearch = true
-- enable break indent
vim.opt.breakindent = true
-- enable line wrapping
vim.opt.wrap = true
-- formatting
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.textwidth = 80
vim.diagnostic.config({
signs = {
text = {
[vim.diagnostic.severity.ERROR] = " ",
[vim.diagnostic.severity.WARN] = " ",
[vim.diagnostic.severity.INFO] = " ",
[vim.diagnostic.severity.HINT] = " ",
},
},
virtual_text = true, -- show inline diagnostics
})
-- clear search highlights with <Esc>
vim.keymap.set("n", "<Esc>", "<cmd>nohlsearch<CR>")
-- INFO: colorscheme
vim.cmd.colorscheme("catppuccin")
-- INFO: plugins
-- we install plugins with neovim's builtin package manager: vim.pack
-- and then enable/configure them by calling their setup functions.
--
-- (see `:h vim.pack` for more details on how it works)
-- you can press `gx` on any of the plugin urls below to open them in your
-- browser and check out their documentation and functionality.
-- alternatively, you can run `:h {plugin-name}` to read their documentation.
--
-- plugins are then loaded and configured with a call to `setup` functions
-- provided by each plugin. this is not a rule of neovim but rather a convention
-- followed by the community.
-- these setup calls take a table as an agument and their expected contents can
-- vary wildly. refer to each plugin's documentation for details.
-- INFO: formatting and syntax highlighting
vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter" }, { confirm = false })
-- equivalent to :TSUpdate
require("nvim-treesitter.install").update("all")
require("nvim-treesitter.configs").setup({
auto_install = true, -- autoinstall languages that are not installed yet
})
-- INFO: completion engine
vim.pack.add({ "https://github.com/saghen/blink.cmp" }, { confirm = false })
require("blink.cmp").setup({
completion = {
documentation = {
auto_show = true,
},
},
-- default blink keymaps
keymap = {
['<C-p>'] = { 'select_prev', 'fallback_to_mappings' },
['<C-n>'] = { 'select_next', 'fallback_to_mappings' },
['<C-y>'] = { 'select_and_accept', 'fallback' },
['<C-e>'] = { 'cancel', 'fallback' },
['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
['<Tab>'] = { 'snippet_forward', 'fallback' },
['<S-Tab>'] = { 'snippet_backward', 'fallback' },
['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
['<C-k>'] = { 'show_signature', 'hide_signature', 'fallback' },
},
fuzzy = {
implementation = "lua",
},
})
-- INFO: lsp server installation and configuration
-- lsp servers we want to use and their configuration
-- see `:h lspconfig-all` for available servers and their settings
local lsp_servers = {
lua_ls = {
-- https://luals.github.io/wiki/settings/ | `:h nvim_get_runtime_file`
Lua = { workspace = { library = vim.api.nvim_get_runtime_file("lua", true) }, },
},
clangd = {},
rust_analyzer = {},
gopls = {},
}
vim.pack.add({
"https://github.com/neovim/nvim-lspconfig", -- default configs for lsps
-- NOTE: if you'd rather install the lsps through your OS package manager you
-- can delete the next three mason-related lines and their setup calls below.
-- see `:h lsp-quickstart` for more details.
"https://github.com/mason-org/mason.nvim", -- package manager
"https://github.com/mason-org/mason-lspconfig.nvim", -- lspconfig bridge
"https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim" -- auto installer
}, { confirm = false })
require("mason").setup()
require("mason-lspconfig").setup()
require("mason-tool-installer").setup({
ensure_installed = vim.tbl_keys(lsp_servers),
})
-- configure each lsp server on the table
-- to check what clients are attached to the current buffer, use
-- `:checkhealth vim.lsp`. to view default lsp keybindings, use `:h lsp-defaults`.
for server, config in pairs(lsp_servers) do
vim.lsp.config(server, {
settings = config,
-- only create the keymaps if the server attaches successfully
on_attach = function(_, bufnr)
vim.keymap.set("n", "grd", vim.lsp.buf.definition,
{ buffer = bufnr, desc = "vim.lsp.buf.definition()", })
vim.keymap.set("n", "grf", vim.lsp.buf.format,
{ buffer = bufnr, desc = "vim.lsp.buf.format()", })
end,
})
end
-- INFO: fuzzy finder
vim.pack.add({
"https://github.com/nvim-lua/plenary.nvim", -- library dependency
"https://github.com/nvim-tree/nvim-web-devicons", -- icons (nerd font)
"https://github.com/nvim-telescope/telescope.nvim" -- the fuzzy finder
}, { confirm = false })
require("telescope").setup({})
local pickers = require("telescope.builtin")
vim.keymap.set("n", "<leader>sp", pickers.builtin, { desc = "[S]earch Builtin [P]ickers", })
vim.keymap.set("n", "<leader>sb", pickers.buffers, { desc = "[S]earch [B]uffers", })
vim.keymap.set("n", "<leader>sf", pickers.find_files, { desc = "[S]earch [F]iles", })
vim.keymap.set("n", "<leader>sw", pickers.grep_string, { desc = "[S]earch Current [W]ord", })
vim.keymap.set("n", "<leader>sg", pickers.live_grep, { desc = "[S]earch by [G]rep", })
vim.keymap.set("n", "<leader>sr", pickers.resume, { desc = "[S]earch [R]esume", })
vim.keymap.set("n", "<leader>sh", pickers.help_tags, { desc = "[S]earch [H]elp", })
vim.keymap.set("n", "<leader>sm", pickers.man_pages, { desc = "[S]earch [M]anuals", })
-- INFO: keybinding helper
vim.pack.add({ "https://github.com/folke/which-key.nvim" }, { confirm = false })
require("which-key").setup({
spec = {
{ "<leader>s", group = "[S]earch", icon = { icon = "", color = "green", }, },
}
})
-- uncomment to enable automatic plugin updates
-- vim.pack.update()