mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
Implemented nunmap and vunmap and provided a more detailed example of surround
This commit is contained in:
parent
eae8d02942
commit
b7b6d27982
2 changed files with 43 additions and 5 deletions
33
README.md
33
README.md
|
|
@ -127,23 +127,46 @@ Note how `exmap` lists command names without colons and in `nmap` the colon is r
|
|||
## Surround Text with `surround`
|
||||
|
||||
The plugin defines a custom Ex command named `surround` to surround either your currently selected text in visual mode or the word your cursor is over in normal mode with text.
|
||||
This is particularly useful for creating wikilinks in Obsidian `[[WikiLink]]`.
|
||||
This is useful for Vim users who are used to the `vim-surround` plugin.
|
||||
|
||||
The syntax follows `:surround [prefixText] [postfixText]`.
|
||||
|
||||
Some examples:
|
||||
|
||||
- `surround ( )`
|
||||
- `surround " "`
|
||||
- `surround [[ ]]`
|
||||
|
||||
Here's my surround config as an example:
|
||||
Here's an example config that implements many of the features from vim-surround:
|
||||
|
||||
```
|
||||
" Surround text with [[ ]] to make a wikilink
|
||||
exmap surround_wiki surround [[ ]]
|
||||
exmap surround_double_quotes surround " "
|
||||
exmap surround_single_quotes surround ' '
|
||||
exmap surround_brackets surround ( )
|
||||
exmap surround_square_brackets surround [ ]
|
||||
exmap surround_curly_brackets surround { }
|
||||
|
||||
" NOTE: must use 'map' and not 'nmap'
|
||||
exmap wiki surround [[ ]]
|
||||
map [[ :wiki
|
||||
map [[ :surround_wiki
|
||||
nunmap s
|
||||
vunmap s
|
||||
map s" :surround_double_quotes
|
||||
map s' :surround_single_quotes
|
||||
map sb :surround_brackets
|
||||
map s( :surround_brackets
|
||||
map s) :surround_brackets
|
||||
map s[ :surround_square_brackets
|
||||
map s[ :surround_square_brackets
|
||||
map s{ :surround_curly_brackets
|
||||
map s} :surround_curly_brackets
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
1. Select some text in visual mode, then press `s` and then the desired surround character. e.g. `s"` to surround the selected text with double quotes.
|
||||
2. Place your cursor over a word in normal mode, then press `s` and then the desired surround character. e.g. `s"` to surround the word with double quotes.
|
||||
|
||||
## Inserting Links/Hyperlinks with `pasteinto`
|
||||
|
||||
The plugin defines a custom Ex command named `pasteinto` to paste text into your currently selected text in visual mode, or the word your cursor is over in normal mode.
|
||||
|
|
|
|||
15
main.ts
15
main.ts
|
|
@ -33,6 +33,9 @@ const mappingCommands: String[] = [
|
|||
"map",
|
||||
"nmap",
|
||||
"noremap",
|
||||
"iunmap",
|
||||
"nunmap",
|
||||
"vunmap",
|
||||
]
|
||||
|
||||
function sleep(ms: number) {
|
||||
|
|
@ -270,6 +273,18 @@ export default class VimrcPlugin extends Plugin {
|
|||
}
|
||||
});
|
||||
|
||||
vimObject.defineEx('nunmap', '', (cm: any, params: any) => {
|
||||
if (params.argString.trim()) {
|
||||
this.codeMirrorVimObject.unmap(params.argString.trim(), 'normal');
|
||||
}
|
||||
});
|
||||
|
||||
vimObject.defineEx('vunmap', '', (cm: any, params: any) => {
|
||||
if (params.argString.trim()) {
|
||||
this.codeMirrorVimObject.unmap(params.argString.trim(), 'visual');
|
||||
}
|
||||
});
|
||||
|
||||
vimObject.defineEx('noremap', '', (cm: any, params: any) => {
|
||||
if (!params?.args?.length) {
|
||||
throw new Error('Invalid mapping: noremap');
|
||||
|
|
|
|||
Loading…
Reference in a new issue