mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
Merge pull request #218 from jsrozner/navigate_folds
Add a jssnippet to skip folds
This commit is contained in:
commit
4657923eb3
2 changed files with 24 additions and 0 deletions
|
|
@ -60,6 +60,26 @@ nmap ]] :nextHeading
|
|||
nmap [[ :prevHeading
|
||||
```
|
||||
|
||||
|
||||
## Avoid unfolding folded sections
|
||||
```javascript
|
||||
function moveUpSkipFold() {
|
||||
view.editor.exec('goUp');
|
||||
}
|
||||
function moveDownSkipFold() {
|
||||
view.editor.exec('goDown');
|
||||
}
|
||||
```
|
||||
Then in your `.obsidian.vimrc` file add the following:
|
||||
|
||||
```
|
||||
exmap upSkipFold jsfile mdHelpers.js {moveUpSkipFold()}
|
||||
exmap downSkipFold jsfile mdHelpers.js {moveDownSkipFold()}
|
||||
nmap k :upSkipFold
|
||||
nmap j :downSkipFold
|
||||
```
|
||||
|
||||
|
||||
## Vimwiki-like link navigation
|
||||
|
||||
This snippet allows to navigate next/previous links with Tab/Shift+Tab.
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@ If you understand the risks and choose to use this feature, turn on "Support JS
|
|||
|
||||
There are two ways to define JS-based commands.
|
||||
|
||||
#### JSCommand - JSFunction
|
||||
**The `jscommand` Ex command** defines a JS function that has an `editor: Editor`, a `view: MarkdownView` and a `selection: EditorSelection` arguments (see the [Obsidian API](https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts) if you're not sure what these are).
|
||||
You define only the body of the function, in a single line wrapped by curly braces, e.g.:
|
||||
|
||||
|
|
@ -276,8 +277,11 @@ exmap logCursor jscommand { console.log(editor.getCursor()); }
|
|||
nmap <C-q> :logCursor
|
||||
```
|
||||
|
||||
#### JSCommand - JSFile
|
||||
Another version of the same functionality is **the `jsfile` Ex command**, which executes code from a file you give as a parameter, then appends another optional piece of code to it (e.g. in case you want to store several helper methods in a file and launch different ones as part of different commands).
|
||||
|
||||
The `jsfile` should be placed in your vault (alongside, e.g., your markdown files).
|
||||
|
||||
As above, the code running as part of `jsfile` has the arguments `editor: Editor`, `view: MarkdownView` and `selection: EditorSelection`.
|
||||
|
||||
Here's an example from my own `.obsidian.vimrc` that maps `]]` and `[[` to jump to the next/previous Markdown header:
|
||||
|
|
|
|||
Loading…
Reference in a new issue