From 7689f8a2704a76f25caf90bfaaa795de814aba59 Mon Sep 17 00:00:00 2001 From: tea Date: Tue, 3 Sep 2024 11:38:45 +0200 Subject: [PATCH] nvim: more stuff ported from old config - git - more keybindings - some fixes --- .config/nvim/init.lua | 2 + .config/nvim/lua/my/git.lua | 27 ++++++ .config/nvim/lua/my/keybindings.lua | 101 ++++++++++++++++++++++ .config/nvim/lua/my/plugins/coding.lua | 44 +++++----- .config/nvim/lua/my/plugins/filetypes.lua | 2 +- .config/nvim/lua/my/plugins/git.lua | 58 +++++++++++++ .config/nvim/lua/my/plugins/tools.lua | 5 +- 7 files changed, 213 insertions(+), 26 deletions(-) create mode 100644 .config/nvim/lua/my/git.lua create mode 100644 .config/nvim/lua/my/keybindings.lua create mode 100644 .config/nvim/lua/my/plugins/git.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index bf0a85d..bcf23ed 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -20,4 +20,6 @@ require('my/early') require('my.functions') require('my/lazy') require('my/options') +require ('my/keybindings') require('my/filetypes') +require('my/git') diff --git a/.config/nvim/lua/my/git.lua b/.config/nvim/lua/my/git.lua new file mode 100644 index 0000000..efbf5e8 --- /dev/null +++ b/.config/nvim/lua/my/git.lua @@ -0,0 +1,27 @@ +local wk = require('which-key') +wk.add({{ 'g', group = 'Git' }}) +wk.add({{ 'gc', group = 'commit' }}) +wk.add({{ 'gp', group = 'pull' }}) +wk.add({{ 'ga', group = 'add' }}) + +local gitgroup = vim.api.nvim_create_augroup('config_git', { clear = true }) +-- enable spell check +vim.api.nvim_create_autocmd({ 'FileType' }, { + group = gitgroup, + pattern = { 'gitcommit' }, + command = [[setlocal spell]] +}) + +-- start in insert mode on line 1 +vim.api.nvim_create_autocmd({ 'FileType' }, { + group = gitgroup, + pattern = { 'gitcommit', 'gitrebase' }, + command = [[startinsert | 1]] +}) + +-- don't mark whitespace characters +vim.api.nvim_create_autocmd({ 'FileType' }, { + group = gitgroup, + pattern = { 'git' }, + command = [[setlocal nolist]] +}) diff --git a/.config/nvim/lua/my/keybindings.lua b/.config/nvim/lua/my/keybindings.lua new file mode 100644 index 0000000..461dfd5 --- /dev/null +++ b/.config/nvim/lua/my/keybindings.lua @@ -0,0 +1,101 @@ +local map = require('my.functions').map +local format = string.format + +-- buffers +map('n', 'b', ':buffers:buffer', 'Show open buffers') +for key, cmd in pairs({ Left = 'bprevious', Right = 'bnext' }) do + map('n', format('', key), format(':%s', cmd)) + map('i', format('', key), format(':%s', cmd)) +end + +---- move buffer without moving cursor +map({ 'n', 'v' }, '', '') +map({ 'n', 'v' }, '', '') + +-- windows +for key, letter in pairs({ Left = 'h', Down = 'j', Up = 'k', Right = 'l' }) do + map('n', format('', key), format(':wincmd %s', letter)) + map('i', format('', key), format(':wincmd %s', letter)) +end + +-- remove word +map('n', '', 'db') +map('n', '', 'db') +vim.cmd([[map! ]]) +vim.cmd([[map!  ]]) + +map('n', '', 'dw') +map('i', '', 'dw') + +-- remove whitespace around cursor +map({ 'n', 'i' }, '', + function() + local row, pos_cursor = unpack(vim.api.nvim_win_get_cursor(0)) + pos_cursor = pos_cursor + 1 -- api / lua is off by one + local line = vim.api.nvim_get_current_line() + local pos_start, pos_end = 0, 0 + + while pos_start ~= nil do + if pos_start <= pos_cursor and pos_end >= pos_cursor then + local before = line:sub(1, pos_start - 1) + local after = line:sub(pos_end + 1) + local space = '' + if before:len() > 0 and after:len() > 0 then + space = ' ' + end + vim.api.nvim_set_current_line(before .. space .. after) + vim.api.nvim_win_set_cursor(0, { row, pos_start - 1 }) + break + end + pos_start, pos_end = line:find('%s+', pos_end + 1) + end + end +) + +-- system clipboard (clipboard = , selection = middle mouse button) +map({ 'v', 'n' }, 'y', '"+y', 'Yank to system clipboard') +map({ 'v', 'n' }, '', '"*y', 'Yank to system selection') +map('n', 'p', '"+p', 'Paste from system clipboard') +map('n', 'P', '"+P', 'Paste from system clipboard') +map('n', '', '"*p', 'Paste from system selection') +map('n', '', '"*P', 'Paste from system selection') + +-- toggle between beginning of line and beginning of text +map({ 'n', 'i', 'v' }, '', + function() + local row, col = unpack(vim.api.nvim_win_get_cursor(0)) + if col == 0 then + local col_new = vim.api.nvim_get_current_line():match('^%s*'):len() + vim.api.nvim_win_set_cursor(0, { row, col_new }) + else + vim.api.nvim_win_set_cursor(0, { row, 0 }) + end + end +) + +map({ 'n', 'v' }, '', '==', 're-indent line') +map('v', 'f', 'gq', 'reformat text') +map('n', '', ':bdelete', 'close buffer') + +---- will i ever use the below? ---- + +-- use ui.select for spelling suggestions so dressing can make it look nice +local function spellsugg_select() + local word = vim.fn.expand('') + local suggestions = vim.fn.spellsuggest(word) + vim.ui.select(suggestions, {}, vim.schedule_wrap(function(selected) + if selected then + vim.api.nvim_feedkeys('ciw' .. selected, 'n', true) + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes('', true, true, true), + 'n', true) + end + end)) +end + +map('n', 'z=', spellsugg_select) + +-- use easier keys for spell +map('n', '', '[s', 'previous misspelled word') -- +map('n', '', ']s', 'next misspelled word') -- +map('n', '', spellsugg_select, 'spelling suggestions') -- diff --git a/.config/nvim/lua/my/plugins/coding.lua b/.config/nvim/lua/my/plugins/coding.lua index 60d0357..89a5fa8 100644 --- a/.config/nvim/lua/my/plugins/coding.lua +++ b/.config/nvim/lua/my/plugins/coding.lua @@ -1,5 +1,24 @@ return { - -- FIXME: Comment stopped working + { 'https://github.com/windwp/nvim-autopairs', + event = 'InsertEnter', + opts = {}, + }, + { 'https://github.com/L3MON4D3/LuaSnip', + version = '*', + opts = { + paths = vim.fn.stdpath('config') .. '/snippets', + }, + }, + { 'https://github.com/GnikDroy/projections.nvim', + branch = 'pre_release', + opts = { + workspaces = { '~/src', '~/documents' }, + patterns = require('my.functions').project_root_markers, + }, + }, + { 'https://github.com/AckslD/nvim-FeMaco.lua' }, + -- this has to be at the bottom or the keybindings won't work + -- no, i don't know why and i don't care anymore { 'https://github.com/numToStr/Comment.nvim', dependencies = { 'nvim-ts-context-commentstring' }, version = '*', @@ -18,28 +37,5 @@ return { eol = 'cA', }, }, - { 'https://github.com/windwp/nvim-autopairs', - event = 'InsertEnter', - opts = {}, - }, - { 'https://github.com/L3MON4D3/LuaSnip', - version = '*', - opts = { - paths = vim.fn.stdpath('config') .. '/snippets', - }, - }, - { 'https://github.com/GnikDroy/projections.nvim', - opts = { - workspaces = { '~/src', '~/documents' }, - patterns = require('my.functions').project_root_markers, - }, - }, - { 'https://github.com/AckslD/nvim-FeMaco.lua' }, - { 'https://github.com/danymat/neogen', - version = '*', - opts = { - snippet_engine = 'luasnip', - }, - }, }, } diff --git a/.config/nvim/lua/my/plugins/filetypes.lua b/.config/nvim/lua/my/plugins/filetypes.lua index 2d6b071..a5feccf 100644 --- a/.config/nvim/lua/my/plugins/filetypes.lua +++ b/.config/nvim/lua/my/plugins/filetypes.lua @@ -2,7 +2,7 @@ local has_api_level = require('my.functions').has_api_level return { { 'https://github.com/nvim-treesitter/nvim-treesitter', - version = '*', + -- version = '*', build = [[:TSUpdateSync]], opts = { ensure_installed = 'all', diff --git a/.config/nvim/lua/my/plugins/git.lua b/.config/nvim/lua/my/plugins/git.lua new file mode 100644 index 0000000..53bbe64 --- /dev/null +++ b/.config/nvim/lua/my/plugins/git.lua @@ -0,0 +1,58 @@ +local map = require('my.functions').map + +return { + { 'https://github.com/tpope/vim-fugitive', + version = '*', + keys = { + { 'gcc', ':Git commit', desc = 'commit' }, + { 'gca', ':Git commit --amend', desc = 'amend' }, + { 'gP', ':Git push', desc = 'push' }, + { 'gpo', ':Git pull origin', desc = 'origin' }, + { 'gpu', ':Git pull upstream', desc = 'upstream' }, + { 'gau', ':Git add --update --patch', desc = '--update --patch' }, + { 'ga%', ':Git add %', desc = 'this file' }, + { 'gl', ':Git log --decorate', desc = 'log' }, + { 'gs', ':Git status', desc = 'status' }, + } + }, + { 'https://github.com/lewis6991/gitsigns.nvim', + version = '*', + opts = { + on_attach = function(bufnr) + local gs = package.loaded.gitsigns + map('n', 'gb', + function() gs.blame_line({ full = true }) end, + 'show blame for current line', bufnr) + end, + }, + }, + { 'https://github.com/linrongbin16/gitlinker.nvim', + dependencies = { 'plenary.nvim' }, + version = '*', + opts = { + router = { + browse = { + ["^schlomp%.space"] = "https://schlomp.space/" + .. "{_A.ORG}/" + .. "{_A.REPO}/src/commit/" + .. "{_A.REV}/" + .. "{_A.FILE}?display=source" -- '?display=source' + .. "#L{_A.LSTART}" + .. "{(_A.LEND > _A.LSTART and ('-L' .. _A.LEND) or '')}", + ['^git%.gentoo%.org'] = "https://gitweb.gentoo.org/?p=" + .. "{string.len(_A.ORG) > 0 and (_A.ORG .. '/') or ''}" + .. "{_A.REPO .. '.git'};a=blob;" + .. "f={_A.FILE};" + .. "hb={_A.REV}" + .. "#l{_A.LSTART}", + ['^anongit%.gentoo%.org'] = "https://gitweb.gentoo.org/?p=" + .. "{string.len(_A.ORG) > 0 and (_A.ORG .. '/') or ''}" + .. "{_A.REPO .. '.git'};a=blob;" + .. "f={_A.FILE};" + .. "hb={_A.REV}" + .. "#l{_A.LSTART}", + } + } + } + } +} diff --git a/.config/nvim/lua/my/plugins/tools.lua b/.config/nvim/lua/my/plugins/tools.lua index 70c24a0..cd0ff17 100644 --- a/.config/nvim/lua/my/plugins/tools.lua +++ b/.config/nvim/lua/my/plugins/tools.lua @@ -157,6 +157,7 @@ return { }, }, { 'https://github.com/dhruvasagar/vim-table-mode', + dependencies = { 'which-key.nvim' }, version = '*', init = function() vim.g.table_mode_map_prefix = 'T' @@ -177,7 +178,9 @@ return { on_open = function(win) vim.api.nvim_win_set_option(win, 'wrap', true) -- does not work end, - stages = 'static', + -- stages = 'static', + stages = 'slide', + timeout = 10000 }, init = function() vim.notify = require('notify')