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
|
-- vim: fdm=marker
local cmd = vim.cmd
local g = vim.g
g.mapleader = ' ' -- <leader> key to <space>
g.maplocalleader = '\\'
require('plugins')
require('hardmode')
require('globals')
-- OPTIONS -- {{{
local opt = vim.opt
opt.backspace = 'indent,eol,start'
opt.clipboard:prepend { 'unnamedplus' }
opt.cmdheight = 1
opt.colorcolumn = {80} -- depends on 'textwidth'
-- opt.complete = '.,w,b,u'
opt.completeopt = {'menu','menuone','noinsert'}
opt.concealcursor = ''
opt.conceallevel = 2
opt.cursorline = true
opt.expandtab = false
opt.exrc = true
opt.fillchars = 'fold:─'
opt.foldenable = true
-- opt.foldlevel = 0
opt.foldlevelstart = 1
opt.hidden = true
opt.hlsearch = false
opt.ignorecase = true
opt.inccommand = 'split'
opt.incsearch = true
opt.laststatus = 2
opt.lazyredraw = true
opt.list = true
opt.listchars:append { trail = '¬', tab = '> ' } -- space/lead = '⋅' }
opt.mouse = 'a'
opt.number = true
opt.pumheight = 0 -- use available screenspace
opt.redrawtime = 1500
opt.ruler = true
opt.scrolloff = 3
opt.shiftround = true
opt.shortmess:append { c = true }
opt.breakindent = true
opt.breakindentopt = { shift = 2 }
opt.showbreak = '↪ '
opt.showcmd = false
opt.showmode = true
opt.showmatch = true
opt.signcolumn = 'auto'
opt.smartcase = true
opt.spell = false
opt.spelloptions = 'camel'
opt.statusline = '%!luaeval("statusline()")'
opt.termguicolors = true
opt.textwidth = 0
opt.timeoutlen = 400
opt.title = true
opt.ttimeoutlen = 10
opt.undolevels = 1000
opt.updatetime = 200
opt.wrap = true
-- configure :grep to use ripgrep if it's available
if vim.fn.executable('rg') then
vim.opt.grepprg = 'rg --vimgrep --smart-case --hidden'
vim.opt.grepformat = '%f:%l:%c:%m'
end
-- persistent undo
local undodir = vim.fn.stdpath('cache') .. '/undodir_' .. vim.env.USER
if vim.fn.isdirectory(undodir) == 0 then
vim.fn.mkdir(undodir, 'p', '0700')
end
vim.g.undodir = undodir
vim.opt.undofile = true
-- }}}
-- COLORS -- {{{
-- g.nihoncolors_transparent_background = true
cmd [[ colorscheme lush ]]
-- }}}
-- KEY BINDS -- {{{
local nnoremap = require('astronauta.keymap').nnoremap
local vnoremap = require('astronauta.keymap').vnoremap
local tnoremap = require('astronauta.keymap').tnoremap
nnoremap { 'Q', function() cmd [[ quitall ]] end, silent = false }
nnoremap { 'gb', function() cmd [[ bnext ]] end }
nnoremap { 'gB', function() cmd [[ bprevious ]] end }
nnoremap { '<tab>', function() cmd [[ exe 'normal zA' | IndentBlanklineRefresh ]] end }
-- nnoremap { '{', [[ {zz ]] }
-- nnoremap { '}', [[ }zz ]] }
vim.cmd [[nnoremap c "_c]]
vim.cmd [[nnoremap C "_C]]
vim.cmd [[vnoremap c "_c]]
vim.cmd [[vnoremap C "_C]]
tnoremap { '<esc>', [[ <c-\><c-n> ]] }
tnoremap { '<leader>qq', [[ <c-\><c-n> :bdelete!<cr> ]] }
vnoremap { 'T', function() cmd [[ retab! | call feedkeys("\<esc>") ]] end }
local misc = require('misc')
nnoremap { 'gf', function() misc.file_under_cursor(function(s) vim.cmd('edit ' .. s) end) end }
nnoremap { 'gF', function() misc.open_under_cursor() end }
nnoremap { 'gx', function() misc.open_under_cursor('url-launcher') end }
nnoremap { 'gGw', function() misc.word_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end }
nnoremap { 'gGe', function() misc.expr_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end }
nnoremap { 'gGf', function() misc.file_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end }
nnoremap { 'gs', function() misc.word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\<left>\<left>") ]] end) end }
nnoremap { '<leader>r', misc.live_grep }
nnoremap { '<leader>f', misc.find_files }
-- }}}
-- AUTO GROUPS -- {{{
augroup {
yank_highlight = {
{'TextYankPost', '*', [[ silent! lua require("vim.highlight").on_yank() ]]}
},
obvious_active_win = {
{'WinEnter', '*', [[ set cul ]]},
{'WinLeave', '*', [[ set nocul ]]}
},
c_makeprg = {
{'VimEnter', '*.c', [[ setlocal makeprg=ninja\ -C\ build ]]}
},
open_qf = {
{'QuickFixCmdPost', '*', [[ :clist ]]}
},
-- packer_auto_compile = {{'BufWritePost', 'plugins.lua', [[ PackerCompile ]]}},
commentstring = {
{'FileType', 'i3config', [[ setlocal commentstring=#\ %s ]]},
{'FileType', 'jsonc', [[ setlocal commentstring=//\ %s ]]},
},
folds = {
{'VimEnter', '.vim/*', [[ setlocal foldenable ]]},
{'FileType', 'json,jsonc,yaml,toml', [[ setlocal nofoldenable ]]},
},
help_quit = {
{'FileType', 'help', [[ nnoremap <buffer><silent> q <cmd>bdel<cr> ]]}
}
}
-- }}}
-- USER COMMANDS -- {{{
cmd [[ command! BalenaDiagnosticsFold call balena_diagnostics_fold#apply() ]]
cmd [[ command! -range SortLine <line1>,<line2>lua misc.sort_line() ]]
cmd [[ command! -nargs=* Make lua require('job').make({<f-args>}) ]]
cmd [[ command! -nargs=* Sh lua require('job').sh(table.concat({<f-args>}, ' ')) ]]
-- }}}
-- STATUS LINE -- {{{
require('spinner').setup {
spinner = {'⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'},
interval = 120, -- spinner frame rate in ms
}
function _G.statusline()
local hi = statusline_color(vim.fn.mode())
local sl = ''
-- left
sl = sl .. hi
sl = sl .. statusline_append(' ⢷', '%#StatusLineIcon#', hi)
sl = sl .. [[ %<%F %-m %-r ]]
-- right
sl = sl .. [[ %= ]] -- spacer
local lsp_spinner = require('spinner').status(vim.fn.bufnr())
sl = sl .. statusline_append(lsp_spinner, '%#StatusLineJobs#', hi)
local lsp_diagnostics = statusline_lsp_diagnostics(vim.fn.bufnr())
sl = sl .. statusline_append(lsp_diagnostics, '%#StatusLineDiagnostics#', hi)
local lsp_lightbulb = require('nvim-lightbulb').get_status_text()
sl = sl .. statusline_append(lsp_lightbulb, '%#StatusLineLightbulb#', hi)
sl = sl .. [[ %l:%v %y ]]
return sl
end
-- statusline_append
-- does item highlighting and conditionnal spacing
function _G.statusline_append(element, hi, default_hi)
if not element or element == '' then return '' end
if not (default_hi == '%*') then hi = '' end
return hi .. element .. default_hi .. ' '
end
function _G.statusline_color(mode)
local hi = '%*'
if mode == 'i' then
-- hi = '%#StatusLineInsert#'
elseif mode == 'c' then
-- hi = '%#StatusLineCommand#'
elseif mode == 'v' or mode == 'V' or mode == '' then
hi = '%#StatusLineVisual#'
elseif mode == 'R' or mode == 'Rv' then
hi = '%#StatusLineReplace#'
end
-- return '%{g:actual_curwin==win_getid()?'.. hi ..':%#StatusLineNC#}'
return hi
end
function _G.statusline_lsp_diagnostics(bufnr)
-- Error, Warning, Information, Hint
local error_num = vim.lsp.diagnostic.get_count(bufnr, 'Error')
local warn_num = vim.lsp.diagnostic.get_count(bufnr, 'Warning')
local s = ''
if error_num > 0 then
s = s .. '%#LspDiagnosticsError#'
s = s .. vim.fn.sign_getdefined('LspDiagnosticsSignError')[1].text .. error_num
end
if warn_num > 0 then
s = s .. '%#LspDiagnosticsWarning#'
s = s .. vim.fn.sign_getdefined('LspDiagnosticsSignWarning')[1].text .. warn_num
end
return s
end
-- }}}
-- source .nvimrc if it exists
local local_vimrc = vim.fn.getcwd()..'/.nvimrc'
if vim.loop.fs_stat(local_vimrc) then
cmd('source ' .. local_vimrc)
end
|