local cmd = vim.cmd local g = vim.g g.mapleader = ' ' -- key to g.maplocalleader = '\\' require('plugins') require('hardmode') -- 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 = 'menuone,noselect' opt.concealcursor = '' opt.conceallevel = 2 opt.cursorline = true opt.expandtab = true opt.exrc = true opt.fillchars = 'fold:─' opt.foldenable = true opt.foldlevel = 0 opt.foldmethod = 'marker' opt.hidden = true opt.inccommand = 'split' opt.incsearch = true opt.laststatus = 2 opt.lazyredraw = true opt.list = true opt.listchars:append { trail = '¬', tab = '> ' } opt.mouse = 'a' opt.number = true opt.ruler = true opt.scrolloff = 3 opt.shiftround = true opt.shortmess:append { c = true } opt.showbreak = '↪ ' opt.showcmd = false opt.showmode = true opt.signcolumn = 'auto:1' opt.smartcase = true opt.spell = false opt.spelloptions = 'camel' opt.statusline = '%!luaeval("statusline()")' opt.termguicolors = true opt.textwidth = 0 opt.title = true opt.undolevels = 1000 opt.updatetime = 300 opt.wrap = true -- }}} -- COLORS -- {{{ -- g.nihoncolors_transparent_background = true cmd [[ colorscheme lush ]] -- }}} -- KEY BINDS -- {{{ local nnoremap = require('astronauta.keymap').nnoremap local inoremap = require('astronauta.keymap').inoremap 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 } -- terminal tnoremap { '', [[ ]] } tnoremap { 'qq', [[ :bdelete! ]] } vnoremap { 'T', function() cmd [[ retab! | call feedkeys("\") ]] end } nnoremap { 'gf', function() require('misc').file_under_cursor(function(s) vim.cmd('edit ' .. s) end) end } nnoremap { 'gF', function() require('misc').open_under_cursor() end } nnoremap { 'gx', function() require('misc').open_under_cursor('url-launcher') end } nnoremap { 'gGw', function() require('misc').word_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end } nnoremap { 'gGe', function() require('misc').expr_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end } nnoremap { 'gGf', function() require('misc').file_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end } nnoremap { 'gs', function() require('misc').word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\\") ]] end) end } -- }}} local u = require('utils') -- AUTO GROUPS -- {{{ u.augroup2 { yank_highlight = {{'TextYankPost', '*', [[ silent! lua require("vim.highlight").on_yank() ]]}}, obvious_active_win = { {'WinEnter', '*', 'set cul'}, {'WinLeave', '*', 'set nocul'} }, c_makeprg = {{'BufRead', '*.c', [[ set 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 ]]}, }, } -- }}} -- 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 } statusline = function() local sl = '' -- left sl = sl .. statusline_color(vim.fn.mode()) sl = sl .. [[ ⢷ %<%F %-m %-r ]] -- right sl = sl .. [[ %= ]] -- spacer local lsp_spinner = require('spinner').status(vim.fn.bufnr()) local lsp_diagnostics = statusline_lsp_diagnostics(vim.fn.bufnr()) sl = sl .. lsp_spinner .. ' ' sl = sl .. lsp_diagnostics sl = sl .. [[  %l:%v %y ]] return sl end statusline_color = function(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 statusline_lsp_diagnostics = function(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 .. vim.fn.sign_getdefined('LspDiagnosticsSignError')[1].text .. error_num end if warn_num > 0 then 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 -- 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