spwx207 downloadsOrg-mode headline editing for Vim mode: Tab/Shift-Tab fold cycling, and folded headings act as one line for V, dd, p and >>/<< promote/demote.
Evil Org adds org-mode outline keys to the Vim mode of Obsidian. The keys operate as in the Emacs package evil-org-mode.
The plugin uses Markdown headings as org-mode headlines. A subtree is a heading and all of the lines under it, to the next heading of the same or a higher level. The plugin counts a folded heading as one line. Thus, Vim commands move, copy, and delete the full subtree.
Set Settings → Editor → Vim key bindings to on.
The keys operate only in Vim normal mode and Vim visual mode. They do not change insert mode, except the table keys. The commands and indent mode operate in all modes, also when Vim mode is off.
In fenced code blocks and front matter, a line that starts with # is not a heading.
Tab: Fold a headingIn a table, Tab moves to the next cell. See Tab, Shift-Tab, and Enter in a table.
Tab changes the fold state of the heading at the cursor (org-cycle). The fold states are:
Tab changes the state as follows:
Tab shows the children. If the heading has no subheadings, Tab shows the subtree.Tab again immediately after the children, Tab shows the subtree.Tab folds the subtree.Thus, the sequence is folded → children → subtree → folded.
Folded list items and code blocks in the subtree stay folded. On a block that is not a heading, such as a list item or the opening fence of a code block, Tab opens or closes the fold of that block.
Shift-Tab: Fold the noteIn a table, Shift-Tab moves to the previous cell.
Shift-Tab changes the fold state of all of the note (org-global-cycle). The fold states are:
Shift-Tab changes the state as follows:
Shift-Tab immediately after the overview, Shift-Tab shows the contents.Shift-Tab immediately after the contents, Shift-Tab shows all of the note.Shift-Tab shows the overview.Text before the first heading does not change. If the cursor is in text that becomes folded, the cursor moves to the visible line above it.
Tab, Shift-Tab, and Enter in a tableIn a Markdown table, these keys align the table and move the cursor between cells, as in the org-mode table editor:
Tab moves to the next cell (org-table-next-field). In the last cell, Tab adds an empty row and moves to its first cell.Shift-Tab moves to the previous cell (org-table-previous-field). In the first cell, the cursor does not move.Enter moves to the same column in the next row (org-table-next-row). In the last row, Enter adds an empty row.The cursor goes to the start of the text of the cell. The keys skip the delimiter row (| --- | :-: |).
A Markdown table needs a delimiter row, right below its first row. If the table does not have one, these keys add it. For example, type | Name | Phone | and push Enter: the delimiter row goes below the row, and the cursor goes to a new row below it. To set the alignment of a column, put colons in the delimiter row, as in | :-: |.
To align the table, the plugin pads each cell with spaces, so that the pipes line up:
| gets one.---.\|) is text in its cell.These keys operate in Vim normal mode and in insert mode, as in evil-org. With a count, Enter moves down as in Vim. One u undoes one key.
A table is a block of lines that start with |. Lines in fenced code blocks are not tables. In Live Preview, the table shows as text when the cursor of Vim is in it (see Tables in Live Preview).
Alt with h, j, k, l, or an arrow: Change a tableIn a Markdown table, in Vim normal mode, these keys move, delete, and insert rows and columns, as in the org-mode table editor and evil-org. On macOS, the Alt key is the Option key. To use Ctrl in place of Alt, see Meta key. Each arrow key does the same as the letter in its direction:
| Key | Arrow key | Change | org-mode command |
|---|---|---|---|
Alt-h |
Alt-← |
Move the column left | org-table-move-column-left |
Alt-l |
Alt-→ |
Move the column right | org-table-move-column-right |
Alt-k |
Alt-↑ |
Move the row up | org-table-move-row-up |
Alt-j |
Alt-↓ |
Move the row down | org-table-move-row-down |
Alt-Shift-h |
Alt-Shift-← |
Delete the column | org-table-delete-column |
Alt-Shift-l |
Alt-Shift-→ |
Insert an empty column to the left of the column | org-table-insert-column |
Alt-Shift-k |
Alt-Shift-↑ |
Delete the row | org-table-kill-row |
Alt-Shift-j |
Alt-Shift-↓ |
Insert an empty row above the row | org-table-insert-row |
Alt-Shift-j inserts the row below the delimiter row, because Markdown has only one header row.. repeats the change. One u undoes it. The plugin aligns the table, as Tab does.Off a table, Alt-j and Alt-k move a subtree (see below), and the other keys do what they did before.
yy, dd, p, and P on a table rowIn a Markdown table, in Vim normal mode, these keys copy, delete, and paste table rows, and keep the table valid:
yy copies the row as a line, as in Vim.dd deletes the row and aligns the table (org-table-kill-row). The row goes to the register as a line, as in Vim. The cursor stays in its column, in the row that takes the place of the deleted row, or in the row above at the end of the table.p and P put copied or deleted table rows below or above the row at the cursor, and align the table. The rows get the columns of the table. The cursor goes to the first cell of the first new row.3yy and 3dd stop at the last row of the table, as a count stops at the end of the note. They do not copy or delete the text after the table. 3p puts three copies of the rows.dd does nothing on the delimiter row and on the header row, because a Markdown table needs them. To delete the full table, use dap or dip, or a count that includes all of the table, such as 9dd on the header row.p and P in the header row or on the delimiter row put the rows below the delimiter row.Tab moves into its cells, and dd deletes it. The same is true of a row such as | - | - | below the delimiter row.dj, dk, and Vjd, delete rows in the same way. If they include the delimiter row or the header row, but not all of the table, they do nothing. A delete that includes lines outside the table, such as dj on the last row, is the usual Vim delete.p and P paste as usual.. repeats dd, p, and P. One u undoes each one.i|, a|, and Ctrl-v on table cellsIn a Markdown table, you can select cells in Vim visual mode, and copy, cut, and paste them, as in the org-mode table editor.
The text objects i| and a| select the cell at the cursor:
i| is the text of the cell, without the spaces around it.a| is the cell with its spaces and the | after it. Thus, da| deletes the cell from the row.ci|, di|, yi|, da|) and in visual mode (vi|).ci| starts insert mode in the cell. di| and yi| do nothing.d2a|), the selection includes that number of cells, from the cell at the cursor to the right.|, the cell is the cell that the | closes. A last cell without a closing | goes to the end of the line.i| and a| also. The plugin's i| does not include the spaces around the text.A visual block (Ctrl-v) in a table selects cells. The block selects all of each cell from the cell of one corner to the cell of the other corner, also when the block covers only part of a cell. Thus, the block selects the same cells in a table that is not aligned. The editor shows the block as Vim draws it, not as cells.
y copies the cells (org-table-copy-region).d and x make the cells empty (org-table-cut-region), and align the table. They do not delete rows or columns. The cells go to the register, as with y.D, X, and Y do the same, but to the last column of the table.p and P in normal mode put copied cells into the table (org-table-paste-rectangle). The first cell goes into the cell at the cursor. The other cells go to the right and down. They replace the text of the cells there. If the cells go past the last row or column, the plugin adds rows or columns. Then the plugin aligns the table.p and P paste into the row below it.p pastes the cells as columns of text. You can also paste them into a spreadsheet.p and P paste cells only when the register has the text of the most recent cell copy or cut. If the register has other text, p and P paste as usual.p and P paste the cells from the Vim register, not from the system clipboard. With clipboard=unnamed (Vim Motions), text that you copy in a different app after the cells does not go into the table.u undoes each change. . repeats d and x.c, >, <, and p in visual mode also operate as usual.v), the keys operate on the text, as usual. For example, vey in a cell copies a word.In Live Preview, Obsidian shows a table in a table editor of its own. Vim does not operate in the cells of that editor: keys such as u, gg, or V are typed into the cell. Thus, when the cursor of Vim is in a table, the plugin shows the table as text, as in Source mode. Then all of the Vim keys operate in the table. When the cursor leaves the table, Obsidian shows its table editor again.
j, k, gg, or a search, the table shows as text.+ buttons of the table editor operate as usual, and so do links in a cell.V, dd, yy, cc, u, p, PV: When you select a folded heading, the selection includes all of its subtree.dd, yy, cc, 3dd: The plugin counts a folded heading as one line. Thus, these commands operate on all of the subtree. On a table row, see yy, dd, p, and P on a table row.u: When you undo a delete, the deleted headings come back folded.p / P: These keys put a yanked subtree after or before a folded heading, not in it. Pasted subtrees stay folded (org-yank-folded-subtrees).>> / <<: Change the level of a heading or list itemOn a heading:
>> adds one # to the heading. << removes one #. These keys do not indent the line.M-S-→ / M-S-←).M-→ / M-←).On a list item:
M-S-→ / M-S-←).>> makes the item a sub-item of the item above it. The item gets the indent of the sub-items of that item.<< makes the item a sibling of its parent. On an item that has no parent, << does nothing.On a range (3>>, V>):
> and < indent the lines as in standard Vim.. repeats the change. One u undoes all of the change.
Alt-j / Alt-k: Move a subtree, list item, or lineOn macOS, the Alt key is the Option key. To use Ctrl-j and Ctrl-k instead, see Meta key. In a table, these keys move the table row. See Change a table.
On a heading, these keys move the subtree down or up, past the next or previous sibling (M-↓ / M-↑):
. repeats the move. One u undoes it.In a list, these keys move the item at the cursor, with its body and sub-items, past the next or previous item (M-↓ / M-↑):
., and u operate as for subtrees.On other lines, these keys move the line. A folded heading counts as one line.
Enter: Follow a link or toggle a checkboxIn a table, Enter moves to the next row. See Tab, Shift-Tab, and Enter in a table.
Enter follows it (org-return-follows-link), as Follow link under cursor does.Enter checks the checkbox (org-toggle-checkbox). If the checkbox is already marked, as in [x] or [/], Enter clears it. The cursor can be on any line of the item.At all other locations, and with a count, Enter operates as in Vim. One u undoes one toggle.
To keep Vim's Enter on links and checkboxes, set Settings → Evil Org → Enter follows links and toggles checkboxes to off. In a table, Enter still moves to the next row.
o / O: Open a list item or table rowIn a list, these keys open a new item below or above the item at the cursor (evil-org-open-below / evil-org-open-above):
o opens the new item after the sub-items of the item.3o) and . open more items.In a Markdown table, o and O insert an empty row below or above the row at the cursor, as evil-org-open-below / evil-org-open-above do in an org table. The cursor goes to the new row, in the same column, in insert mode, and the plugin aligns the table. In the header row and on the delimiter row, they insert the row below the delimiter row.
On a heading, o and O open a usual line. To open a new heading, use the Insert heading command.
On a folded heading, item, or block, o opens the line below the fold.
ar / ir: Select a subtreeThese text objects select a subtree (evil-org ar / ir). They operate on folded and open subtrees.
ar is the subtree that contains the cursor, plus the blank lines after it.ir is the body of that subtree. It does not include the heading or the blank lines around the body.dar, yar, cir, >ar) and in visual mode.d2ar), the selection includes the parent subtree. When you type ar again in visual mode, the result is the same.On a Markdown table row:
ar is the row.ir is the text between the first | and the last | of the row.ar again in visual mode.ae / ie: Select a Markdown elementThese text objects select the Markdown element at the cursor (evil-org ae / ie). The element can be one of these:
A paragraph in the body of a list item is an element in that item.
ae is the element, plus the blank lines after it. On a blank line, ae is the element above it.
ie is the inside of the element:
# characters.You can use them with all operators (dae, yae, cie, >ae) and in visual mode.
With a count (d2ae), the selection includes the next element that contains it. When you type ae again in visual mode, the result is the same. The sequence is:
ar.A folded heading or item counts as one line. Thus, dae on a folded heading deletes all of the subtree.
gh: Go to the headinggh moves the cursor to the heading of the line (org-up-element).
gh moves the cursor to the parent heading. Thus, each gh moves one level up the outline.2gh), the cursor moves up that number of levels.gh is linewise. For example, dgh deletes the lines from the heading to the cursor line.Ctrl-o moves the cursor back.These actions are also Obsidian commands:
Tab.Shift-Tab.Alt-j.Alt-k.# than the heading of that subtree, to a maximum of 6.gh.The commands have no default hotkeys. To set a hotkey, open Settings → Hotkeys.
The commands operate in all modes, also when Vim mode is off. In Vim normal mode, the insert commands start insert mode.
Alt-Enter to insert a headingIn Obsidian, Alt-Enter is the default hotkey of Follow link under cursor. To use Alt-Enter for Insert heading, do these steps:
Alt-Enter hotkey from this command.Alt-Enter.NOTE: To follow links from the keyboard, set a different hotkey for Follow link under cursor.
You cannot map Alt-Enter in a vimrc file. Obsidian gets its hotkeys before Vim does.
Indent mode indents the lines of a note by the outline (org-indent-mode). It changes only how the editor shows the lines. It does not change the text of the note.
# characters of every heading start at the left edge.## ), the indent is 3 characters at the size of that heading.In Live Preview, indent mode shows a bullet in place of the # characters of a heading. The bullets are:
| Level | Bullet |
|---|---|
| 1 | ◉ |
| 2 | ○ |
| 3 | ✸ |
| 4 | ✿ |
At level 5, the sequence starts again. The bullet has the size of the heading. It replaces the last # character, and the other # characters show as blank space, as with org-hide-leading-stars. For example, ### C shows as ✸ C. When the cursor is on a heading, the editor shows the # characters in place of the bullet. The text of the heading does not move. Source mode does not show bullets.
To set indent mode to on or off, use one of these:
The setting applies to all notes. It stays after you restart Obsidian.
Indent mode operates only in the editor. It does not operate in reading view.
Set Settings → Evil Org → Compact headings to on. The editor then shows the headings on consecutive lines, as in org-mode:
The text of the note does not change. You can use this setting with or without indent mode.
Set Settings → Evil Org → Uniform heading size to on. The editor then shows all headings at the font size and line height of body text, as in org-mode. Headings keep their color and weight. You can use this setting with or without indent mode.
Set Settings → Evil Org → Hide heading fold arrows to on. The editor then does not show the fold arrows of headings, as in org-mode.
Tab and Shift-Tab.The keys that org-mode binds to Meta (M-) use Alt by default. To use Ctrl instead, set Settings → Evil Org → Meta key to Ctrl. This changes:
Alt-j / Alt-k, which move a subtree, list item, or line, to Ctrl-j / Ctrl-k.Alt with h, j, k, l, or an arrow, which change a table, to Ctrl with the same keys.The Alt keys then do what they did without the plugin. In Vim normal mode, the plugin gets the Ctrl keys before Vim and Obsidian do. Thus, Vim's Ctrl-j and an Obsidian hotkey on Ctrl-k do not operate in Vim normal mode, and in a table the same goes for Ctrl-h, Ctrl-l, and Ctrl with an arrow.
The Obsidian commands keep their names, such as Move subtree down (M-↓ in org-mode).
To install the plugin from Obsidian, do these steps:
To install the plugin manually, do these steps:
main.js and manifest.json from the latest release.<vault>/.obsidian/plugins/evil-org/.Obsidian does not have a public API for its Vim mode. Thus, the plugin uses interfaces that Obsidian does not document. An Obsidian update can stop the plugin. When you disable the plugin, Vim goes back to its standard behavior.
In Vim normal mode, the plugin gets Alt-j and Alt-k (or Ctrl-j and Ctrl-k, see Meta key) before Obsidian does. Thus, an Obsidian hotkey on Alt-j or Alt-k does not operate in Vim normal mode.
In Vim normal mode, the plugin gets Enter in a table, on a link, and in a list item with a checkbox, and in a table it gets Alt with h, l, an arrow, or Shift, before Obsidian and Vim do.
In Live Preview, with Vim, the plugin gets a click on a cell of a table before Obsidian's table editor does (see Tables in Live Preview).
To change, build, test, or release the plugin, see DEVELOPMENT.md.