Use case or problem
When using Vim key bindings, pressing o or O (open new line) in Normal mode doesn’t behave the same way Enter does in Insert mode, as it doesn’t seem aware of the current Markdown context.
For example, unlike Enter, o/O does not:
- create a new list item when used within a list
- retain indentation level when used within a code block
- continue a blockquote
In other words, the new line should ideally be a part of the list/blockquote, ie. be prefixed with
> or similar, just like if you had pressed Enter in insert mode (or non-Vim mode).
Make Vim mode respect the current Markdown context.
Current workaround (optional)
I usually press a (append to line) and then Enter, but I just as often forget to do it, so I press o and then Backspace followed by Enter.
Related feature requests (optional)
(Copied from Vim: O and o don't respect current context in Bug Reports/Bug Graveyard)
Yes please!! I’m constantly writing outlines or taking notes and almost every time I need to create a new line I press
o. Then I have to delete the whole line (often including a few space characters at the beginning of the line for some reason), move the cursor back to the end of the previous line, enter insert mode, and then press
This isn’t a muscle memory I’m going to lose given how often I use it in vim, vscode, and other places and it really interrupts the flow.
Adding to the list of things
o doesn’t account for:
- adding a new row in the advanced tables plugin
It would probably make things a lot more consistent for
o to just be a macro for “move the cursor to the end of the line in insert mode and press
enter”, or “
enter”, so that any plugins rebinding enter for a particular context are still respected by vim mode.
As a temporary workaround in case this doesn’t get addressed: There is a “Vimrc Support” plugin that lets you do custom mappings. I haven’t tested it. But I wonder if you could remap
<esc>A<enter> or equivalent.
O might be trickier.
That’d be a nice solution, but I can’t get it to work. I try the following mappings:
map o <Esc>A<CR>
map O <Esc>I<CR><Esc>ki
And the mappings are applied, but the carriage returns don’t seem to work. o works the same as A on its own, and O the same as
The first thing I thought was that maybe
<CR> is called something else here, or just isn’t supported, but it works on its own in other mappings (I tried to bind the unused + key to just
<CR>, for example, which worked).
Note that you can test these mappings in Obsidian without Vimrc Support, by hitting : in Normal mode followed by the map command.
There’s a workaround @pseudometa found (requires the vimrc plugin).
btw, the last update for the code editor shortcuts plugin enables us to create a better
O in Obsidian that properly inserts prefixes for markdown lists
" Smarter o and O (inserting prefix for markdown lists)
exmap blankBelow obcommand obsidian-editor-shortcuts:insertLineBelow
exmap blankAbove obcommand obsidian-editor-shortcuts:insertLineAbove
nmap &a& :blankAbove
nmap &b& :blankBelow
nmap o &b&i
nmap O &a&i
Cool, that works! Crazy that we have to install a separate plugin though IMO, but thanks a lot, I’m satisfied!
One little thing I noticed: It doesn’t recognize checkboxes (ie.
- [ ]) as a leading list prefix, it just continues a checkbox list as a regular bullet list. Not a big deal, but a bit annoying.
Can you file an issue for that?
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.