0

I have the textobjects-user and textobject-quotes plugin installed, using vim 8. Those let me work with multi-line strings, so I can place the cursor inside a multi-line quoted string and diq to delete or yiq to yank. Those text objects work so I know the plugin works.

I tried to define a simple key remap so I could yank the contents of a quoted string, open it in a new split, and strip excess whitespace:

nnoremap <leader>Q yiq<CR>:vnew<CR>p:%s/^\s\+//<CR>

It doesn't work. If I remove the yiq<CR> and do that from the keyboard, then invoke <leader>Q the split and paste and whitespace stripping work. If I change yiq to yi' it works.

Any reason I can't use the plugin's text objects inside a remap like this?

melpomene
  • 84,125
  • 8
  • 85
  • 148
gregjor
  • 21,802
  • 1
  • 23
  • 16
  • Presumably the plugin remaps `yiq`, but you said you want the native vim `yiq` (`noremap`), which AFAICT doesn't do anything. – melpomene May 24 '18 at 04:04
  • No I want the plugin `yiq` behavior. It doesn't remap `y` but it does add new text objects `iq` and `aq`. – gregjor May 24 '18 at 04:08
  • But you answered my question... `nmap` not `nnoremap`. Duh. Thanks. – gregjor May 24 '18 at 04:11

1 Answers1

2

The nore in nnoremap means "don't try to execute other mappings while executing this one". It makes your mapping non-recursive.

Since you expressly want to use another mapping in your mapping it must be recursive:

nmap <leader>Q yiq<CR>:vnew<CR>p:%s/^\s\+//<CR>
romainl
  • 186,200
  • 21
  • 280
  • 313