obcommand inserts name of command instead of executing it
Please Review Before Posting!
- [x] I checked that the bug does not happen in the CodeMirror Vim demo. If it does, please report it there and not here.
- [x] I'm reasonably sure that this bug is indeed about the Vimrc file support and not a general Vim in Obsidian issue. If it's a general Vim issue, report it here.
Describe the bug:
obcommands no longer execute the command but instead insert the name of the command. If in insert mode then the name of the command ':mycommand' is inserted, in normal mode the command line is opened and the name of the command inserted there.
To Reproduce:
Add the following to obsidian.vimrc file:
exmap highlighttext obcommand editor:toggle-highlight imap === :highlighttext nmap '= :highlightext
In insert mode typing '===' should toggle highlight, instead it inserts the text ':highlighttext'.
In normal mode typing " '= " should toggle highlight, instead it opens the vim command line and inserts the text 'highlighttext'.
Environment (please complete the following information):
- OS: Linux (opensuse 15.6)
- Vimrc plugin version: 0.10.2
- Obsidian: 1.7.7
- Installer: 1.6.7
Additional context:
Add any other context about the problem here.
Reproduced in a sandbox vault with only vimrc plugin installed. I can say for sure this was working for me on versions 0.7.x; tried downgrading with BRAT and the problem persists, so it is probably something in obsidian that has changed which breaks the obcommands.
With the update to Obsidian 1.7.2, executing Ex commands now requires appending <CR>.
Transitioning from Insert mode to Command-line mode may work as expected if you pass through Normal mode first. In such cases, you might consider appending a immediately after the command to return to Insert mode seamlessly.
Based on this, the following .obsidian.vimrc configuration should work as intended:
exmap highlighttext obcommand editor:toggle-highlight
imap === <Esc>:highlighttext<CR>a
nmap '= :highlighttext<CR>
Thank you, thank you! I got the commands working. Should I mark this as closed? Or is this something that will be changed in upcoming versions?
I'm having the same issue even after adding <CR>
exmap switcher obcommand switcher:open
nmap <C-p> :switcher<CR>
Executing this in Normal mode inserts the text witcher
@suxur I am having no issue opening the quick switcher using your exact snippet in my vimrc. Are you still struggling with this?
@adrocic ...yup. I just updated to Obsidian v1.8.3, reinstalled the plugin, turned off other plugins and same issue. Here is my full .obsidian.vimrc
" Have j and k navigate visual lines rather than actual lines
nmap j gj
nmap k gk
" Yank to system clipboard
set clipboard=unnamed
inoremap jk <Esc>
nnoremap ; :
nnoremap : ;
unmap <Space>
exmap tabnext obcommand cycle-through-panes:cycle-through-panes
nmap <Space>] :tabnext<CR>
exmap tabprev obcommand cycle-through-panes:cycle-through-panes-reverse
nmap <Space>[ :tabprev<CR>
exmap split_horizontal obcommand workspace:split-horizontal
nmap <Space>sp :split_horizontal<CR>
exmap split_vertical obcommand workspace:split-vertical
nmap <Space>vs :split_vertical<CR>
exmap close_pane obcommand workspace:close
nmap <Space>bd :close_pane<CR>
exmap close_others obcommand workspace:close-others
nmap <Space>bq :close_others<CR>
exmap switcher obcommand switcher:open
nmap <C-p> :switcher<CR>
exmap focus_bottom obcommand editor:focus-bottom
nmap <C-j> :focus_bottom<CR>
exmap focus_top obcommand editor:focus-top
nmap <C-k> :focus_top<CR>
exmap focus_left obcommand editor:focus-left
nmap <C-h> :focus_left<CR>
exmap focus_right obcommand editor:focus-right
nmap <C-l> :focus_right<CR>
exmap toggle_left_sidebar obcommand app:toggle-left-sidebar
nmap <C-f> :toggle_left_sidebar<CR>
Thanks! Your issue is with the normal mode remapping for your colon and semi-colon keys included in your vimrc. The output after hitting <C-p> sends colon, but your mapping changes that to semi-colon and then the first character is captured as "s" from (switcher) which puts you in substr char mode and then the remaining text "witcher" is typed out.
nnoremap ; :
nnoremap : ;
@adrocic Ah nice catch! That fixed it, thanks so much!!