Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/orgmode/config/_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
---@field org_demote_subtree? OrgMappingValue Default: '>s'
---@field org_meta_return? OrgMappingValue Add heading, item or row (context-dependent) Default: '<Leader><CR>'
---@field org_return? OrgMappingValue Default: '<CR>'
---@field org_insert_mode_promote? OrgMappingValue Promote heading or decrease indent in insert mode. Default: '<C-d>'
---@field org_insert_mode_demote? OrgMappingValue Demote heading or increase indent in insert mode. Default: '<C-t>'
---@field org_insert_heading_respect_content? OrgMappingValue Add new heading after current heading block (same level) Default: '<prefix>ih'
---@field org_insert_todo_heading? OrgMappingValue Add new todo heading right after current heading (same level) Default: '<prefix>iT'
---@field org_insert_todo_heading_respect_content? OrgMappingValue Add new todo heading after current heading block (same level). Default: '<prefix>it'
Expand Down
2 changes: 2 additions & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ local DefaultConfig = {
org_demote_subtree = '>s',
org_meta_return = '<Leader><CR>', -- Add heading, item or row (context-dependent)
org_return = '<CR>',
org_insert_mode_promote = '<C-d>',
org_insert_mode_demote = '<C-t>',
org_insert_heading_respect_content = '<prefix>ih', -- Add new heading after current heading block (same level)
org_insert_todo_heading = '<prefix>iT', -- Add new todo heading right after current heading (same level)
org_insert_todo_heading_respect_content = '<prefix>it', -- Add new todo heading after current heading block (same level)
Expand Down
8 changes: 8 additions & 0 deletions lua/orgmode/config/mappings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ return {
),
org_export = m.action('org_mappings.export', { opts = { desc = 'org export', help_desc = 'Open export options' } }),
org_return = m.action('org_mappings.org_return', { modes = { 'i' }, opts = { desc = 'org return' } }),
org_insert_mode_promote = m.action('org_mappings.insert_mode_promote', {
modes = { 'i' },
opts = { desc = 'org insert mode promote' },
}),
org_insert_mode_demote = m.action('org_mappings.insert_mode_demote', {
modes = { 'i' },
opts = { desc = 'org insert mode demote' },
}),
org_next_visible_heading = m.action('org_mappings.next_visible_heading', {
modes = { 'n', 'x' },
opts = { desc = 'org next visible headline', help_desc = 'Go to next headline (any level)' },
Expand Down
38 changes: 38 additions & 0 deletions lua/orgmode/org/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,44 @@ function OrgMappings:do_demote(whole_subtree)
vim.fn.winrestview(win_view)
end

function OrgMappings:insert_mode_promote()
local line_number = vim.fn.line('.')
local line = vim.fn.getline(line_number)

if line:match('^%*+') then
local cursor_col = vim.fn.col('.')
local new_line = line:gsub('^%*+', function(asterisks)
if #asterisks > 1 then
return string.rep('*', #asterisks - 1)
else
return ''
end
end)
vim.fn.setline(line_number, new_line)
vim.fn.cursor(line_number, math.max(1, cursor_col - 1))
return
end

return vim.api.nvim_feedkeys(utils.esc('<C-d>'), 'n', true)
end

function OrgMappings:insert_mode_demote()
local line_number = vim.fn.line('.')
local line = vim.fn.getline(line_number)

if line:match('^%*+') then
local cursor_col = vim.fn.col('.')
local new_line = line:gsub('^(%*+)', function(asterisks)
return asterisks .. '*'
end)
vim.fn.setline(line_number, new_line)
vim.fn.cursor(line_number, cursor_col + 1)
return
end

return vim.api.nvim_feedkeys(utils.esc('<C-t>'), 'n', true)
end

function OrgMappings:org_return()
local actions = {
function()
Expand Down
Loading