-- vim: fdm=marker fdl=0 local cmd = vim.cmd local g = vim.g g.mapleader = ' ' -- key to g.maplocalleader = '\\' -- 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:append { fold = '─', horiz = '─', } opt.foldenable = true opt.foldmethod = 'expr' opt.foldexpr = 'nvim_treesitter#foldexpr()' -- opt.foldlevel = 0 opt.foldlevelstart = 1 opt.hidden = true opt.hlsearch = false opt.ignorecase = true opt.inccommand = 'split' opt.incsearch = true -- 3; https://github.com/neovim/neovim/pull/17266 opt.laststatus = 3 opt.lazyredraw = true opt.list = true opt.listchars:append { trail = '¬', tab = '> ', -- space/lead = '⋅', } opt.mouse = 'a' opt.number = true opt.relativenumber = false 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.termguicolors = true opt.textwidth = 0 opt.timeoutlen = 400 opt.title = true opt.ttimeoutlen = 10 opt.undolevels = 1000 opt.updatetime = 200 opt.wrap = true opt.path = {'', '.', '.;$HOME', '/usr/include/**'} opt.isfname:remove ':' opt.guicursor = { -- block shape in normal/visual/command 'n-c-v:block', -- bar in insert/cmdline-insert/visual-exclusive 'i-ci-ve:ver15', -- underline in replace/cmdline-replace/operator-pending 'r-cr-o:hor10', 'sm:block-blinkwait175-blinkoff150-blinkon175', -- 'a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor', 'a:blinkon0-Cursor', } -- configure :grep to use ripgrep if it's available if vim.fn.executable('rg') then opt.grepprg = 'rg --vimgrep --smart-case --hidden' 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 g.undodir = undodir opt.undofile = true -- }}} g.do_filetype_lua = 1 g.did_load_filetypes = 0 -- COLORS -- {{{ -- g.nihoncolors_transparent_background = true cmd [[ colorscheme lush ]] -- }}} require('globals') require('plugins') require('hardmode') -- Configure builtin diagnositics {{{ vim.diagnostic.config { underline = true, virtual_text = { severity = {min=vim.diagnostic.severity.WARN}, source = true, prefix = '', }, signs = true, float = { pos = 'cursor' }, update_in_insert = false, severity_sort = true, virtual_lines = { prefix = '⬐ ' }, } vim.fn.sign_define({ {name='DiagnosticSignError', text='✗', texthl='DiagnosticSignError'}, -- {name='DiagnosticSignWarn', text='⚡', texthl='DiagnosticSignWarn'}, {name='DiagnosticSignWarn', text='⚐', texthl='DiagnosticSignWarn'}, {name='DiagnosticSignInfo', text='ℹ', texthl='DiagnosticSignInfo'}, {name='DiagnosticSignHint', text='🞶', texthl='DiagnosticSignHint'} }) -- }}} -- KEY BINDS -- {{{ vim.keymap.set('n', 'Q', [[ :quitall ]], {silent = true}) vim.keymap.set('n', 'gb', [[ :bnext ]], {silent = true}) vim.keymap.set('n', 'gB', [[ :bprevious ]], {silent = true}) vim.keymap.set('n', '', [[ :exe 'normal za' | IndentBlanklineRefresh ]], {silent = true}) vim.keymap.set('n', ']d', vim.diagnostic.goto_next) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) vim.keymap.set('n', 'd', vim.diagnostic.open_float) -- swap gf and gF vim.keymap.set('n', 'gf', [[ gF ]]) vim.keymap.set('v', 'gf', [[ gF ]]) -- vim.keymap.set('n', '{', [[ {zz ]]) -- vim.keymap.set('n', '}', [[ }zz ]]) -- this makes c jump to the start of the line -- vim.keymap.set({'n', 'v'}, 'c', '_c') -- vim.keymap.set({'n', 'v'}, 'C', '_C') vim.keymap.set('t', '', [[ ]]) vim.keymap.set('t', 'qq', [[ :bdelete! ]]) vim.keymap.set('v', 'T', function() vim.cmd [[retab!]] vim.api.nvim_input("") end) local misc = require('misc') vim.keymap.set('n', 'gd', function() misc.open_under_cursor(nil, true) end) -- vim.keymap.set('n', 'gf', function() misc.file_under_cursor(function(s) vim.cmd('edit ' .. s) end) end) vim.keymap.set('n', 'gx', function() misc.open_under_cursor('url-launcher') end) vim.keymap.set('n', 'gu', function() misc.open_under_cursor('url-launcher') end) vim.keymap.set('n', 'gGw', function() misc.word_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end) vim.keymap.set('n', 'gGe', function() misc.expr_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end) vim.keymap.set('n', 'gGf', function() misc.file_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end) vim.keymap.set('n', 'gss', function() misc.word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\\") ]] end) end) vim.keymap.set('n', 'r', misc.live_grep) vim.keymap.set('n', 'f', misc.find_files) vim.keymap.set('n', 'dgl', 'diffget LOCAL') vim.keymap.set('n', 'dgr', 'diffget REMOTE') vim.keymap.set('n', 'dpl', 'diffpush LOCAL') vim.keymap.set('n', 'dpr', 'diffpush REMOTE') vim.keymap.set('x', 'bf', [[lua require("misc").fold_block()]], { noremap = true, silent = true }) -- }}} -- 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 ]]}, }, easy_quit = { {'FileType', 'help,neorg', [[ nnoremap q close ]]}, {'FileType', 'alpha', [[ nnoremap q bdel ]]}, }, detect_gomod = { {'BufRead,BufNewFile', 'go.mod', [[setlocal filetype=gomod]]} }, detect_bindir_scripts = { {'BufRead,BufNewFile', '/home/robert/bin/*', [[setlocal filetype=sh]]} } } -- }}} -- USER COMMANDS -- {{{ cmd [[ command! BalenaDiagnosticsFold call balena_diagnostics_fold#apply() ]] cmd [[ command! -range SortLine ,lua require('misc').sort_line() ]] cmd [[ command! -nargs=* Make lua require('job').make({}) ]] cmd [[ command! -nargs=* Sh lua require('job').sh(table.concat({}, ' ')) ]] -- }}} -- 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_status = require('lsp-status').status() sl = sl .. statusline_append(vim.trim(lsp_status), '%#StatusLineLsp#', hi) 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.diagnostic.get(bufnr, {severity = vim.diagnostic.severity.ERROR}) local warn_num = vim.diagnostic.get(bufnr, {severity = vim.diagnostic.severity.WARN}) local s = '' if #error_num > 0 then s = s .. '%#DiagnosticError#' s = s .. vim.fn.sign_getdefined('DiagnosticSignError')[1].text .. #error_num end if #warn_num > 0 then s = s .. '%#DiagnosticWarn#' s = s .. vim.fn.sign_getdefined('DiagnosticSignWarn')[1].text .. #warn_num end return s end -- }}} _G.statusline_enable_notifysend = false require('statusline') -- 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