From 37179bc46d079c4d0d553d5c134eea38d620291a Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 17 Mar 2021 02:19:25 -0400 Subject: add rich git support with hunks --- init.lua | 2 +- lua/nv-utils/init.lua | 202 +++++++++++++++++++++++++++++++++++++++++ lua/settings.lua | 4 +- lua/utils.lua | 168 ---------------------------------- vimscript/functions.vim | 42 +++++---- vimscript/nv-whichkey/init.vim | 29 ++---- 6 files changed, 239 insertions(+), 208 deletions(-) create mode 100644 lua/nv-utils/init.lua delete mode 100644 lua/utils.lua diff --git a/init.lua b/init.lua index 20ed1ddd..b862cfb1 100644 --- a/init.lua +++ b/init.lua @@ -7,7 +7,7 @@ else require('keymappings') require('settings') require('colorscheme') - require('utils') + require('nv-utils') -- Plugins require('nv-compe') diff --git a/lua/nv-utils/init.lua b/lua/nv-utils/init.lua new file mode 100644 index 00000000..fff4ded7 --- /dev/null +++ b/lua/nv-utils/init.lua @@ -0,0 +1,202 @@ +local function_wrapper = {} + +function function_wrapper.define_augroups(definitions) -- {{{1 + -- Create autocommand groups based on the passed definitions + -- + -- The key will be the name of the group, and each definition + -- within the group should have: + -- 1. Trigger + -- 2. Pattern + -- 3. Text + -- just like how they would normally be defined from Vim itself + for group_name, definition in pairs(definitions) do + vim.cmd('augroup ' .. group_name) + vim.cmd('autocmd!') + + for _, def in pairs(definition) do + local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ') + vim.cmd(command) + end + + vim.cmd('augroup END') + end +end +function_wrapper.define_augroups( + {_general_settings = { + {'TextYankPost', '*', 'lua require(\'vim.highlight\').on_yank({higroup = \'IncSearch\', timeout = 200})'}, + {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, + {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, + {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, + {'FileType', 'java', 'luafile ~/.config/nvim/lua/lsp/java-ls.lua'}, + {'FileType', 'java', 'nnoremap ca lua require(\'jdtls\').code_action()'}, + + }, + } +) + + +-- Add this to lightbulb, java makes this annoying tho +-- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb() + +-- lsp + +function function_wrapper.add_to_workspace_folder() + vim.lsp.buf.add_workspace_folder() +end + +function function_wrapper.clear_references() + vim.lsp.buf.clear_references() +end + +function function_wrapper.code_action() + vim.lsp.buf.code_action() +end + +function function_wrapper.declaration() + vim.lsp.buf.declaration() + vim.lsp.buf.clear_references() +end + +function function_wrapper.definition() + vim.lsp.buf.definition() + vim.lsp.buf.clear_references() +end + +function function_wrapper.document_highlight() + vim.lsp.buf.document_highlight() +end + +function function_wrapper.document_symbol() + vim.lsp.buf.document_symbol() +end + +function function_wrapper.formatting() + vim.lsp.buf.formatting() +end + +function function_wrapper.formatting_sync() + vim.lsp.buf.formatting_sync() +end + +function function_wrapper.hover() + vim.lsp.buf.hover() +end + +function function_wrapper.implementation() + vim.lsp.buf.implementation() +end + +function function_wrapper.incoming_calls() + vim.lsp.buf.incoming_calls() +end + +function function_wrapper.list_workspace_folders() + vim.lsp.buf.list_workspace_folders() +end + +function function_wrapper.outgoing_calls() + vim.lsp.buf.outgoing_calls() +end + +function function_wrapper.range_code_action() + vim.lsp.buf.range_code_action() +end + +function function_wrapper.range_formatting() + vim.lsp.buf.range_formatting() +end + +function function_wrapper.references() + vim.lsp.buf.references() + vim.lsp.buf.clear_references() +end + +function function_wrapper.remove_workspace_folder() + vim.lsp.buf.remove_workspace_folder() +end + +function function_wrapper.rename() + vim.lsp.buf.rename() +end + +function function_wrapper.signature_help() + vim.lsp.buf.signature_help() +end + +function function_wrapper.type_definition() + vim.lsp.buf.type_definition() +end + +function function_wrapper.workspace_symbol() + vim.lsp.buf.workspace_symbol() +end + +-- diagnostic + +function function_wrapper.get_all() + vim.lsp.diagnostic.get_all() +end + +function function_wrapper.get_next() + vim.lsp.diagnostic.get_next() +end + +function function_wrapper.get_prev() + vim.lsp.diagnostic.get_prev() +end + +function function_wrapper.goto_next() + vim.lsp.diagnostic.goto_next() +end + +function function_wrapper.goto_prev() + vim.lsp.diagnostic.goto_prev() +end + +function function_wrapper.show_line_diagnostics() + vim.lsp.diagnostic.show_line_diagnostics() +end + +-- git signs + +function function_wrapper.next_hunk() + require('gitsigns').next_hunk() +end + +function function_wrapper.prev_hunk() + require('gitsigns').prev_hunk() +end + +function function_wrapper.stage_hunk() + require('gitsigns').stage_hunk() +end + +function function_wrapper.undo_stage_hunk() + require('gitsigns').undo_stage_hunk() +end + +function function_wrapper.reset_hunk() + require('gitsigns').reset_hunk() +end + +function function_wrapper.reset_buffer() + require('gitsigns').reset_buffer() +end + +function function_wrapper.preview_hunk() + require('gitsigns').preview_hunk() +end + +function function_wrapper.blame_line() + require('gitsigns').blame_line() +end + + +-- misc + + +-- autoformat +-- autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 1000) + +return function_wrapper + diff --git a/lua/settings.lua b/lua/settings.lua index b4657987..5c5945cf 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -12,8 +12,8 @@ vim.o.termguicolors=true vim.o.splitright=true --Vertical splits will automatically be to the right vim.o.t_Co="256" --Support 256 colors vim.o.conceallevel=0 --So that I can see `` in markdown files -vim.bo.tabstop=2 --Insert 2 spaces for a tab -vim.bo.shiftwidth=2 --Change the number of space characters inserted for indentation +vim.cmd('set ts=4') --Insert 2 spaces for a tab +vim.cmd('set sw=4') --Change the number of space characters inserted for indentation vim.bo.expandtab=true --Converts tabs to spaces vim.bo.smartindent=true --Makes indenting smart vim.wo.number = true diff --git a/lua/utils.lua b/lua/utils.lua deleted file mode 100644 index cc5bd855..00000000 --- a/lua/utils.lua +++ /dev/null @@ -1,168 +0,0 @@ -local function_wrapper = {} - -function function_wrapper.define_augroups(definitions) -- {{{1 - -- Create autocommand groups based on the passed definitions - -- - -- The key will be the name of the group, and each definition - -- within the group should have: - -- 1. Trigger - -- 2. Pattern - -- 3. Text - -- just like how they would normally be defined from Vim itself - for group_name, definition in pairs(definitions) do - vim.cmd('augroup ' .. group_name) - vim.cmd('autocmd!') - - for _, def in pairs(definition) do - local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ') - vim.cmd(command) - end - - vim.cmd('augroup END') - end -end -function_wrapper.define_augroups( - {_general_settings = { - {'TextYankPost', '*', 'lua require(\'vim.highlight\').on_yank({higroup = \'IncSearch\', timeout = 200})'}, - {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, - {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, - {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'}, - {'FileType', 'java', 'luafile ~/.config/nvim/lua/lsp/java-ls.lua'}, - {'FileType', 'java', 'nnoremap ca lua require(\'jdtls\').code_action()'}, - - }, - } -) - - --- Add this to lightbulb, java makes this annoying tho --- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb() - --- lsp - -function function_wrapper.add_to_workspace_folder() - vim.lsp.buf.add_workspace_folder() -end - -function function_wrapper.clear_references() - vim.lsp.buf.clear_references() -end - -function function_wrapper.code_action() - vim.lsp.buf.code_action() -end - -function function_wrapper.declaration() - vim.lsp.buf.declaration() - vim.lsp.buf.clear_references() -end - -function function_wrapper.definition() - vim.lsp.buf.definition() - vim.lsp.buf.clear_references() -end - -function function_wrapper.document_highlight() - vim.lsp.buf.document_highlight() -end - -function function_wrapper.document_symbol() - vim.lsp.buf.document_symbol() -end - -function function_wrapper.formatting() - vim.lsp.buf.formatting() -end - -function function_wrapper.formatting_sync() - vim.lsp.buf.formatting_sync() -end - -function function_wrapper.hover() - vim.lsp.buf.hover() -end - -function function_wrapper.implementation() - vim.lsp.buf.implementation() -end - -function function_wrapper.incoming_calls() - vim.lsp.buf.incoming_calls() -end - -function function_wrapper.list_workspace_folders() - vim.lsp.buf.list_workspace_folders() -end - -function function_wrapper.outgoing_calls() - vim.lsp.buf.outgoing_calls() -end - -function function_wrapper.range_code_action() - vim.lsp.buf.range_code_action() -end - -function function_wrapper.range_formatting() - vim.lsp.buf.range_formatting() -end - -function function_wrapper.references() - vim.lsp.buf.references() - vim.lsp.buf.clear_references() -end - -function function_wrapper.remove_workspace_folder() - vim.lsp.buf.remove_workspace_folder() -end - -function function_wrapper.rename() - vim.lsp.buf.rename() -end - -function function_wrapper.signature_help() - vim.lsp.buf.signature_help() -end - -function function_wrapper.type_definition() - vim.lsp.buf.type_definition() -end - -function function_wrapper.workspace_symbol() - vim.lsp.buf.workspace_symbol() -end - --- diagnostic - -function function_wrapper.get_all() - vim.lsp.diagnostic.get_all() -end - -function function_wrapper.get_next() - vim.lsp.diagnostic.get_next() -end - -function function_wrapper.get_prev() - vim.lsp.diagnostic.get_prev() -end - -function function_wrapper.goto_next() - vim.lsp.diagnostic.goto_next() -end - -function function_wrapper.goto_prev() - vim.lsp.diagnostic.goto_prev() -end - -function function_wrapper.show_line_diagnostics() - vim.lsp.diagnostic.show_line_diagnostics() -end - --- git signs - --- misc - - --- autoformat --- autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 1000) - -return function_wrapper diff --git a/vimscript/functions.vim b/vimscript/functions.vim index fa2a6a20..6f869935 100644 --- a/vimscript/functions.vim +++ b/vimscript/functions.vim @@ -1,17 +1,25 @@ -command! LspCodeAction lua require 'function-wrapper'.code_action() -command! LspDeclaration lua require 'function-wrapper'.declaration() -command! LspDefinition lua require 'function-wrapper'.definition() -command! LspDocumentSymbol lua require 'function-wrapper'.document_symbol() -command! LspFormatting lua require 'function-wrapper'.formatting() -command! LspFormattingSync lua require 'function-wrapper'.formatting_sync() -command! LspHover lua require 'function-wrapper'.hover() -command! LspImplementation lua require 'function-wrapper'.implementation() -command! LspRangeCodeAction lua require 'function-wrapper'.range_code_action() -command! LspRangeFormatting lua require 'function-wrapper'.range_formatting() -command! LspReferences lua require 'function-wrapper'.references() -command! LspRename lua require 'function-wrapper'.rename() -command! LspTypeDefinition lua require 'function-wrapper'.type_definition() -command! LspWorkspaceSymbol lua require 'function-wrapper'.workspace_symbol() -command! LspGotoNext lua require 'function-wrapper'.goto_next() -command! LspGotoPrev lua require 'function-wrapper'.goto_prev() -command! LspShowLineDiagnostics lua require 'function-wrapper'.show_line_diagnostics() +command! LspCodeAction lua require 'nv-utils'.code_action() +command! LspDeclaration lua require 'nv-utils'.declaration() +command! LspDefinition lua require 'nv-utils'.definition() +command! LspDocumentSymbol lua require 'nv-utils'.document_symbol() +command! LspFormatting lua require 'nv-utils'.formatting() +command! LspFormattingSync lua require 'nv-utils'.formatting_sync() +command! LspHover lua require 'nv-utils'.hover() +command! LspImplementation lua require 'nv-utils'.implementation() +command! LspRangeCodeAction lua require 'nv-utils'.range_code_action() +command! LspRangeFormatting lua require 'nv-utils'.range_formatting() +command! LspReferences lua require 'nv-utils'.references() +command! LspRename lua require 'nv-utils'.rename() +command! LspTypeDefinition lua require 'nv-utils'.type_definition() +command! LspWorkspaceSymbol lua require 'nv-utils'.workspace_symbol() +command! LspGotoNext lua require 'nv-utils'.goto_next() +command! LspGotoPrev lua require 'nv-utils'.goto_prev() +command! LspShowLineDiagnostics lua require 'nv-utils'.show_line_diagnostics() +command! NextHunk lua require 'nv-utils'.next_hunk() +command! PrevHunk lua require 'nv-utils'.prev_hunk() +command! StageHunk lua require 'nv-utils'.stage_hunk() +command! UndoStageHunk lua require 'nv-utils'.undo_stage_hunk() +command! ResetHunk lua require 'nv-utils'.reset_hunk() +command! ResetBuffer lua require 'nv-utils'.reset_buffer() +command! PreviewHunk lua require 'nv-utils'.preview_hunk() +command! BlameLine lua require 'nv-utils'.blame_line() diff --git a/vimscript/nv-whichkey/init.vim b/vimscript/nv-whichkey/init.vim index 24613d45..af715242 100644 --- a/vimscript/nv-whichkey/init.vim +++ b/vimscript/nv-whichkey/init.vim @@ -35,6 +35,7 @@ let g:which_key_map['h'] = [ 's' , let g:which_key_map['m'] = [ ':MarkdownPreviewToggle' , 'markdown preview'] let g:which_key_map['n'] = [ ':let @/ = ""' , 'no highlight' ] let g:which_key_map['r'] = [ ':RnvimrToggle' , 'ranger' ] +let g:which_key_map['p'] = [ '"0p' , 'paste' ] " TODO create entire treesitter section let g:which_key_map['T'] = [ ':TSHighlightCapturesUnderCursor' , 'treesitter highlight' ] let g:which_key_map['v'] = [ 'v' , 'split right'] @@ -140,30 +141,18 @@ let g:which_key_map.g = { \ 'b' : [':GitBlameToggle' , 'blame'], \ 'B' : [':GBrowse' , 'browse'], \ 'd' : [':Git diff' , 'diff'], - \ 'i' : [':Gist -b' , 'post gist'], + \ 'j' : [':NextHunk' , 'next hunk'], + \ 'k' : [':PrevHunk' , 'prev hunk'], \ 'l' : [':Git log' , 'log'], + \ 'p' : [':PreviewHunk' , 'preview hunk'], + \ 'r' : [':ResetHunk' , 'reset hunk'], + \ 'r' : [':ResetBuffer' , 'reset buffer'], + \ 's' : [':StageHunk' , 'stage hunk'], \ 'S' : [':Gstatus' , 'status'], + \ 'u' : [':UndoStageHunk' , 'undo stage hunk'], \ } - " set these up for git signs - " ['n ]c'] = { expr = true, "&diff ? ']c' : 'lua require\"gitsigns\".next_hunk()'"}, - " ['n [c'] = { expr = true, "&diff ? '[c' : 'lua require\"gitsigns\".prev_hunk()'"}, - - " ['n hs'] = 'lua require"gitsigns".stage_hunk()', - " ['n hu'] = 'lua require"gitsigns".undo_stage_hunk()', - " ['n hr'] = 'lua require"gitsigns".reset_hunk()', - " ['n hR'] = 'lua require"gitsigns".reset_buffer()', - " ['n hp'] = 'lua require"gitsigns".preview_hunk()', - " ['n hb'] = 'lua require"gitsigns".blame_line()', - " \ 'p' : [':Git push' , 'push'], - " \ 'P' : [':Git pull' , 'pull'], - " \ 'g' : [':GGrep' , 'git grep'], - " \ 'D' : [':Gdiffsplit' , 'diff split'], - " \ 'c' : [':Git commit' , 'commit'], - " \ 'A' : [':CocCommand fzf-preview.GitStatus' , 'actions'], - " \ 'a' : [':Git add .' , 'add all'], - " \ 'A' : [':Git add %' , 'add current'], - " \ 'S' : [':!git status' , 'status'], +" G is for gist let g:which_key_map.G = { \ 'name' : '+gist' , \ 'b' : [':Gist -b' , 'post gist browser'], -- cgit v1.2.3