forked from nvim-lua/kickstart.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
284 lines (231 loc) · 10 KB
/
init.lua
File metadata and controls
284 lines (231 loc) · 10 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
-- [[ options ]] {{{
-- See `:help mapleader`
-- NOTE: Must happen before plugins are loaded (otherwise wrong leader will be used)
vim.g.mapleader = ','
vim.g.maplocalleader = '-'
-- Set to true if you have a Nerd Font installed and selected in the terminal
vim.g.have_nerd_font = true
vim.g.border = 'none'
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.o.termguicolors = true
-- [[ Setting options ]]
-- See `:help vim.opt`
-- NOTE: You can change these options as you wish!
-- For more options, you can see `:help option-list`
vim.o.wrap = false
-- Make line numbers default
vim.o.number = true
-- You can also add relative line numbers, to help with jumping.
-- Experiment for yourself to see if you like it!
-- vim.opt.relativenumber = true
-- Enable mouse mode, can be useful for resizing splits for example!
vim.o.mouse = 'a'
-- Don't show the mode, since it's already in the status line
vim.o.showmode = false
-- Sync clipboard between OS and Neovim.
-- Schedule the setting after `UiEnter` because it can increase startup-time.
-- Remove this option if you want your OS clipboard to remain independent.
-- See `:help 'clipboard'`
vim.schedule(function()
vim.o.clipboard = 'unnamedplus'
end)
-- Enable break indent
vim.o.breakindent = true
-- Increment and decrement Ctrl-a Ctrl-x ignore leading -
vim.o.nrformats = 'bin,octal,hex,unsigned'
-- Save undo history
vim.o.undofile = true
vim.o.foldlevel = 99
-- Case-insensitive searching UNLESS \C or one or more capital letters in the search term
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.wildmenu = true
vim.o.wildmode = 'noselect:lastused,full'
vim.o.wildoptions = 'pum,fuzzy'
vim.o.wildignorecase = true
-- Keep signcolumn on by default
vim.o.signcolumn = 'yes'
-- Decrease update time
vim.o.updatetime = 250
-- Decrease mapped sequence wait time
vim.o.timeoutlen = 300
-- Configure how new splits should be opened
vim.o.splitright = true
vim.o.splitbelow = true
-- Sets how neovim will display certain whitespace characters in the editor.
-- See `:help 'list'`
-- and
--
-- Notice listchars is set using `vim.opt` instead of `vim.o`.
-- It is very similar to `vim.o` but offers an interface for conveniently interacting with tables.
-- See `:help lua-options`
-- and `:help lua-options-guide` `:help 'listchars'`
vim.o.list = true
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
-- Preview substitutions live, as you type!
vim.o.inccommand = 'split'
-- Show which line your cursor is on
vim.o.cursorline = true
-- Minimal number of screen lines to keep above and below the cursor.
vim.o.scrolloff = 10
vim.o.tabstop = 4
vim.o.shiftwidth = 0
vim.o.expandtab = false
vim.o.foldmethod = 'expr'
vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
vim.filetype.add {
extension = {
json = 'jsonc',
make = 'make',
log = 'log',
},
filename = {
['pre-commit'] = 'yaml',
},
}
-- }}}
-- [[ Basic Keymaps ]] See `:help vim.keymap.set()` {{{
-- stylua: ignore start
vim.keymap.set('i', 'jj', '<esc>', { desc = 'Exit insert mode' })
vim.keymap.set('n', '<leader>w', '<cmd>w<cr>', { desc = '[W]rite' })
vim.keymap.set('n', '<leader>q', '<cmd>q<cr>', { desc = '[Q]uit' })
vim.keymap.set('n', '<leader>Q', '<cmd>qa!<cr>', { desc = '[Q]uit everything' })
vim.keymap.set('n', '<leader>T', '<cmd>split +term<cr>i', { desc = 'Open terminal' })
vim.keymap.set('i', '<C-<BS>>', '<C-W>', { desc = 'Delete previous word' })
-- Make
vim.keymap.set('n', '<F7>', '<cmd>make!<cr><cmd>cw<cr>', { desc = 'make' })
vim.keymap.set('n', '<leader>mm', '<cmd>make!<cr><cmd>cw<cr>', { desc = '[M]ake' })
vim.keymap.set('n', '<leader>mr', '<cmd>make! run<cr>', { desc = '[M]ake [R]un' })
vim.keymap.set('n', '<leader>mt', '<cmd>make! test<cr>', { desc = '[M]ake [T]est' })
vim.keymap.set('n', '<leader>mc', '<cmd>make clean<cr>', { desc = '[M]ake [C]lean' })
vim.keymap.set('n', '<leader>cc', '<cmd>cclose<cr>', { desc = '[C] [C]lose' })
vim.keymap.set('x', '<tab>', '>gv', { desc = 'Indent selected text' })
vim.keymap.set('x', '<s-tab>', '<gv', { desc = 'Unindent selected text' })
vim.keymap.set('n', 'ø', 'zA', { desc = '[T]oggle [F]old' })
vim.keymap.set('n', '<leader>tw', '<cmd>set wrap!<cr>', { desc = '[T]oggle [W]rap' })
-- Buffer mappings
vim.keymap.set('n', 'gb', '<cmd>bnext<CR>', { desc = 'next [B]uffer' })
vim.keymap.set('n', 'gB', '<cmd>bNext<CR>', { desc = 'previous [B]uffer' })
-- stylua: ignore end
-- Quickfix
vim.keymap.set('n', '<c-n>', '<cmd>cn<cr>', { desc = 'Ctrl [N]ext quickfix item' })
vim.keymap.set('n', '<c-p>', '<cmd>cp<cr>', { desc = 'Ctrl [P]revious quickfix item' })
vim.keymap.set('n', 'qd', vim.diagnostic.setqflist, { desc = '[Q]uickfix [D]iagnostics' })
vim.keymap.set(
'n',
'∂',
vim.diagnostic.open_float,
{ desc = 'Open floating window showing diagnostic' }
)
-- if lsp is active 'qr' shows references
-- stylua: ignore begin
-- Clear highlights on search when pressing <Esc> in normal mode
-- See `:help hlsearch`
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
vim.keymap.set('n', '<bs>b', '<cmd>bd<CR>', { desc = 'Delete current [B]uffer' })
vim.keymap.set(
'n',
'<bs>ab',
'<cmd>%bd<bar>e#<bar>bd#<bar>\'"<CR>',
{ desc = 'Delete [A]ll other [B]uffers' }
)
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
-- is not what someone will guess without a bit more experience.
--
-- NOTE: This won't work in all terminal emulators/tmux/etc. Try your own mapping
-- or just use <C-\><C-n> to exit terminal mode
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
-- Keybinds to make split navigation easier.
-- Use CTRL+<hjkl> to switch between windows
--
-- See `:help wincmd` for a list of all window commands
vim.keymap.set('n', '<C-h>', '<C-w><C-h>', { desc = 'Move focus to the left window' })
vim.keymap.set('n', '<C-l>', '<C-w><C-l>', { desc = 'Move focus to the right window' })
vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower window' })
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
-- The commands for selected lines in viusal mode use ':m' instead of cmd
-- because we have to execute the command in normal mode and then go back to visual
vim.keymap.set('n', '√', ':m .+1<CR>==', { noremap = true, silent = true })
vim.keymap.set('n', 'ª', ':m .-2<CR>==', { noremap = true, silent = true })
vim.keymap.set('x', '√', ":m '>+1<CR>gv=gv", { noremap = true, silent = true })
vim.keymap.set('x', 'ª', ":m '<-2<CR>gv=gv", { noremap = true, silent = true })
vim.keymap.set('n', '<A-j>', ':m .+1<CR>==', { noremap = true, silent = true })
vim.keymap.set('n', '<A-k>', ':m .-2<CR>==', { noremap = true, silent = true })
vim.keymap.set('x', '<A-j>', ":m '>+1<CR>gv=gv", { noremap = true, silent = true })
vim.keymap.set('x', '<A-k>', ":m '<-2<CR>gv=gv", { noremap = true, silent = true })
-- stylua: ignore end
-- }}}
-- [[ Basic Autocommands ]] {{{
-- See `:help lua-guide-autocommands`
-- Highlight when yanking (copying) text
-- Try it with `yap` in normal mode
-- See `:help vim.highlight.on_yank()`
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
callback = function()
vim.hl.on_yank { timeout = 400 }
end,
})
-- Set makeprg to Ninja if ninja build files exist in subdirectories
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWinEnter' }, {
pattern = { '*.c*', '*.h*', 'CMake*' },
desc = 'Override makeprg if ninja build files can be found',
callback = function()
local ninjafiles = vim.fs.find({ 'build.ninja' }, { type = 'file' })
local builddir = vim.fs.dirname(ninjafiles[1])
if builddir ~= nil then
vim.opt.makeprg = 'ninja -C ' .. builddir
vim.api.nvim_create_user_command('Configure', '!cmake ' .. builddir, {})
vim.api.nvim_create_user_command('Reconfigure', '!cmake -B ' .. builddir .. ' --fresh', {})
vim.api.nvim_create_user_command('CTest', '!ctest --test-dir ' .. builddir .. ' -j', {})
vim.keymap.set('n', '<leader>mt', '<cmd>CTest<cr>')
end
end,
})
-- Jump to last position when opening a file
vim.api.nvim_create_autocmd('BufRead', {
callback = function(opts)
vim.api.nvim_create_autocmd('FileType', {
once = true,
buffer = opts.buf,
callback = function()
local ft = vim.bo[opts.buf].ft
local last_pos = vim.api.nvim_buf_get_mark(opts.buf, '"')
if
not (ft:match 'commit' or ft:match 'rebase' or ft:match 'xxd')
and last_pos[1] > 1
and last_pos[1] <= vim.api.nvim_buf_line_count(opts.buf)
then
vim.api.nvim_feedkeys('g`"', 'x', false)
end
end,
})
end,
})
-- }}}
-- [[ ColorScheme ]] {{{
vim.api.nvim_create_autocmd('ColorScheme', {
group = vim.api.nvim_create_augroup('retrobox-overrides', { clear = false }),
pattern = 'retrobox', -- colorscheme or list of schemes
callback = function()
-- Your custom highlight commands go here
vim.api.nvim_set_hl(0, 'Normal', { bg = 'none', italic = false })
-- vim.api.nvim_set_hl(0, 'NormalFloat', { bg = 'none', italic = false })
vim.api.nvim_set_hl(0, 'VertSplit', { bg = 'none' })
vim.api.nvim_set_hl(0, 'QuickFixLine', { bg = 'none' })
-- vim.api.nvim_set_hl(0, 'Folded', { bg = vim.api.nvim_get_hl(0, { name = 'Special' }).fg, fg = 'black' })
vim.api.nvim_set_hl(0, 'Path', { link = 'Identifier' })
vim.api.nvim_set_hl(0, 'signcolumn', { bg = 'none' })
vim.api.nvim_set_hl(0, 'CursorLineNr', { bg = 'none' })
vim.api.nvim_set_hl(0, 'LspReferenceText', { underline = true })
vim.api.nvim_set_hl(0, '@lsp.typemod.function.defaultLibrary.lua', { link = 'Special' })
end,
})
vim.cmd.colorscheme 'retrobox'
-- }}}
require 'config.lazy'
-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 expandtab foldmethod=marker foldlevel=0