summary refs log tree commit diff
path: root/.vim/init.lua
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-07-29 23:39:08 +0200
committerRobert Günzler <r@gnzler.io>2021-07-29 23:40:32 +0200
commit3079e935c793a9aa1831fd165e28636eb7a87dae (patch)
treee832ac6a08ad70c14c01b1eac32ac1b5eec3549f /.vim/init.lua
parentcefbce656c511a3583744ed7735aa71249b73500 (diff)
vim: cleanup config
Diffstat (limited to '.vim/init.lua')
-rw-r--r--.vim/init.lua67
1 files changed, 51 insertions, 16 deletions
diff --git a/.vim/init.lua b/.vim/init.lua
index 600a76b..d56d1c7 100644
--- a/.vim/init.lua
+++ b/.vim/init.lua
@@ -15,7 +15,7 @@ opt.clipboard:prepend { 'unnamedplus' }
 opt.cmdheight = 1
 opt.colorcolumn = {80} -- depends on 'textwidth'
 opt.complete = '.,w,b,u'
-opt.completeopt = 'menuone,noinsert,noselect'
+opt.completeopt = 'menuone,noselect'
 opt.concealcursor = ''
 opt.conceallevel = 2
 opt.cursorline = true
@@ -72,46 +72,61 @@ nnoremap { 'gB', function() cmd [[ bprevious ]] end }
 -- terminal
 tnoremap { '<esc>', [[ <c-\><c-n> ]] }
 tnoremap { '<leader>qq', [[ <c-\><c-n> :bdelete!<cr> ]] }
+vnoremap { 'T', function() cmd [[ retab! | call feedkeys("\<esc>") ]] end }
 
-nnoremap { 'gf', function() require('misc').open_under_cursor('open') end }
-nnoremap { 'gF', function() require('misc').open_under_cursor() end }
-nnoremap { 'gx', function() require('misc').open_under_cursor('url-launcher') 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("\<left>\<left>") ]] end) end }
-
-nnoremap { '<leader>gg', function() require('neogit').open({ kind = "split" }) end }
-nnoremap { 'gm', function() cmd [[ GitMessenger ]] end }
-vnoremap { 'T', function() cmd [[ retab! | call feedkeys("\<esc>") ]] end }
+nnoremap { 'gs',  function() require('misc').word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\<left>\<left>") ]] end) end }
 -- }}}
 
 local u = require('utils')
 
 -- AUTO GROUPS -- {{{
 u.augroup2 {
-  yank_highlight = {{ 'TextYankPost', '*', [[ silent! lua require("vim.highlight").on_yank() ]] }},
+  yank_highlight = {{'TextYankPost', '*', [[ silent! lua require("vim.highlight").on_yank() ]]}},
   obvious_active_win = {
-    { 'WinEnter', '*', 'set cul' },
-    { 'WinLeave', '*', 'set nocul' }
+    {'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', [[ source <afile> | PackerCompile ]]}},
+  commentstring = {
+    {'FileType', 'i3config', [[ setlocal commentstring=#\ %s ]]},
+    {'FileType', 'jsonc', [[ setlocal commentstring=//\ %s ]]},
   },
-  c_makeprg = {{'BufRead', '*.c', [[ set makeprg=ninja\ -C\ build ]] }},
 }
 -- }}}
 
 -- USER COMMANDS -- {{{
-u.def('BalenaDiagnosticsFold', [[ call balena_diagnostics_fold#apply() ]])
-u.def('SortLine', [[ call setline(".", join(sort(split(getline("."), " ")), " ")) ]])
+cmd [[ command! BalenaDiagnosticsFold call balena_diagnostics_fold#apply() ]]
+cmd [[ command! -range SortLine <line1>,<line2>lua require('misc').sort_line() ]]
+cmd [[ command! -nargs=1 Make lua require('job').make({<f-args>}) ]]
 -- }}}
 
 -- 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 .. [[ %=  %l:%v %y ]]
+  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)
@@ -128,6 +143,20 @@ statusline_color = function(mode)
   -- 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
@@ -135,3 +164,9 @@ 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