nvim: more stuff ported from old config

- git
- more keybindings
- some fixes
This commit is contained in:
tea 2024-09-03 11:38:45 +02:00
parent bf4cf2b67c
commit 7689f8a270
No known key found for this signature in database
7 changed files with 213 additions and 26 deletions

View File

@ -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')

View File

@ -0,0 +1,27 @@
local wk = require('which-key')
wk.add({{ '<Leader>g', group = 'Git' }})
wk.add({{ '<Leader>gc', group = 'commit' }})
wk.add({{ '<Leader>gp', group = 'pull' }})
wk.add({{ '<Leader>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]]
})

View File

@ -0,0 +1,101 @@
local map = require('my.functions').map
local format = string.format
-- buffers
map('n', '<Leader>b', ':buffers<CR>:buffer<Space>', 'Show open buffers')
for key, cmd in pairs({ Left = 'bprevious', Right = 'bnext' }) do
map('n', format('<M-%s>', key), format(':%s<cr>', cmd))
map('i', format('<M-%s>', key), format('<esc>:%s<cr>', cmd))
end
---- move buffer without moving cursor
map({ 'n', 'v' }, '<M-Up>', '<C-y>')
map({ 'n', 'v' }, '<M-Down>', '<C-e>')
-- windows
for key, letter in pairs({ Left = 'h', Down = 'j', Up = 'k', Right = 'l' }) do
map('n', format('<M-S-%s>', key), format(':wincmd %s<cr>', letter))
map('i', format('<M-S-%s>', key), format('<esc>:wincmd %s<cr>', letter))
end
-- remove word
map('n', '<C-BS>', 'db')
map('n', '', 'db')
vim.cmd([[map! <C-BS> <C-W>]])
vim.cmd([[map!  <C-W>]])
map('n', '<C-Del>', 'dw')
map('i', '<C-Del>', '<C-O>dw')
-- remove whitespace around cursor
map({ 'n', 'i' }, '<C-S-Del>',
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 = <C-v>, selection = middle mouse button)
map({ 'v', 'n' }, '<Leader>y', '"+y', 'Yank to system clipboard')
map({ 'v', 'n' }, '<Leader><C-y>', '"*y', 'Yank to system selection')
map('n', '<Leader>p', '"+p', 'Paste from system clipboard')
map('n', '<Leader>P', '"+P', 'Paste from system clipboard')
map('n', '<Leader><C-p>', '"*p', 'Paste from system selection')
map('n', '<Leader><C-M-p>', '"*P', 'Paste from system selection')
-- toggle between beginning of line and beginning of text
map({ 'n', 'i', 'v' }, '<Home>',
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' }, '<C-F>', '==', 're-indent line')
map('v', '<Leader>f', 'gq', 'reformat text')
map('n', '<C-D>', ':bdelete<CR>', '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('<cword>')
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('<Esc>', true, true, true),
'n', true)
end
end))
end
map('n', 'z=', spellsugg_select)
-- use easier keys for spell
map('n', '<F17>', '[s', 'previous misspelled word') -- <S-F5>
map('n', '<F18>', ']s', 'next misspelled word') -- <S-F6>
map('n', '<F19>', spellsugg_select, 'spelling suggestions') -- <S-F7>

View File

@ -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 = '<leader>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',
},
},
},
}

View File

@ -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',

View File

@ -0,0 +1,58 @@
local map = require('my.functions').map
return {
{ 'https://github.com/tpope/vim-fugitive',
version = '*',
keys = {
{ '<leader>gcc', '<cmd>:Git commit<cr>', desc = 'commit' },
{ '<leader>gca', '<cmd>:Git commit --amend<cr>', desc = 'amend' },
{ '<leader>gP', '<cmd>:Git push<cr>', desc = 'push' },
{ '<leader>gpo', '<cmd>:Git pull origin<cr>', desc = 'origin' },
{ '<leader>gpu', '<cmd>:Git pull upstream<cr>', desc = 'upstream' },
{ '<leader>gau', '<cmd>:Git add --update --patch<cr>', desc = '--update --patch' },
{ '<leader>ga%', '<cmd>:Git add %<cr>', desc = 'this file' },
{ '<leader>gl', '<cmd>:Git log --decorate<cr>', desc = 'log' },
{ '<leader>gs', '<cmd>:Git status<cr>', desc = 'status' },
}
},
{ 'https://github.com/lewis6991/gitsigns.nvim',
version = '*',
opts = {
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
map('n', '<Leader>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}",
}
}
}
}
}

View File

@ -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 = '<leader>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')