Skip to content

Commit

Permalink
feat: Add a.vim, create buffer-local maps for C/C++.
Browse files Browse the repository at this point in the history
Signed-off-by: Guennadi Maximov C <[email protected]>
  • Loading branch information
DrKJeff16 committed Aug 15, 2024
1 parent eab7934 commit 6cd7c9e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
6 changes: 6 additions & 0 deletions lua/plugin/_spec/editing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ local M = {
version = false,
config = source('plugin.autopairs'),
},
{
'vim-scripts/a.vim',
ft = { 'c', 'cpp' },
version = false,
init = function() vim.g.installed_a_vim = 1 end,
},
}

return M
Expand Down
89 changes: 67 additions & 22 deletions lua/user_api/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,81 @@ local function assoc()
end,
},
{
pattern = 'c',
pattern = { 'c', 'cpp' },
group = group,
callback = function()
local wk_avail = require('user_api.maps.wk').available
local desc = require('user_api.maps.kmap').desc
local map_dict = require('user_api.maps').map_dict
local optset = vim.api.nvim_set_option_value
local opts = {
['ts'] = 2,
['sts'] = 2,
['sw'] = 2,
['et'] = true,

local buf_opts = {
ts = 2,
sts = 2,
sw = 2,
ai = true,
si = true,
et = true,
}

for option, val in next, opts do
for option, val in next, buf_opts do
optset(option, val, { buf = 0 })
end
end,
},
{
pattern = 'cpp',
group = group,
callback = function()
local optset = vim.api.nvim_set_option_value
local opts = {
['ts'] = 2,
['sts'] = 2,
['sw'] = 2,
['et'] = true,
}

for option, val in next, opts do
optset(option, val, { buf = 0 })
if vim.g.installed_a_vim == 1 then
---@type KeyMapDict
local Keys = {
['<leader><C-h>s'] = {
':A<CR>',
desc('Cycle Header/Source', true, 0),
},
['<leader><C-h>x'] = {
':AS<CR>',
desc('Horizontal Cycle Header/Source', true, 0),
},
['<leader><C-h>v'] = {
':AV<CR>',
desc('Vertical Cycle Header/Source', true, 0),
},
['<leader><C-h>t'] = {
':AT<CR>',
desc('Tab Cycle Header/Source', true, 0),
},
['<leader><C-h>S'] = {
':IH<CR>',
desc('Cycle Header/Source (Cursor)', true, 0),
},
['<leader><C-h>X'] = {
':IHS<CR>',
desc('Horizontal Cycle Header/Source (Cursor)', true, 0),
},
['<leader><C-h>V'] = {
':IHV<CR>',
desc('Vertical Cycle Header/Source (Cursor)', true, 0),
},
['<leader><C-h>T'] = {
':IHT<CR>',
desc('Tab Cycle Header/Source (Cursor)', true, 0),
},
}
---@type RegKeysNamed
local Names = {
['<leader><C-h>'] = { group = '+Header/Source Switch (C/C++)' },
}
if wk_avail() then
map_dict(Names, 'wk.register', false, 'n', 0)
end
map_dict(Keys, 'wk.register', false, 'n', 0)

require('user_api.maps').nop({
'ih',
'is',
'ihn',
}, {
noremap = true,
silent = true,
buffer = 0,
}, 'n', '<leader>')
end
end,
},
Expand Down

0 comments on commit 6cd7c9e

Please sign in to comment.