I am trying to create a text object for consecutive lower-case letters.Here is how I am setting up the inner text object:xnoremap in :<C-u>normal! ?[^a-z]?e+1<CR>v/[^a-z]/s-1<CR>onoremap in :normal vin<CR>The following shows what happens when I type vin:[text]               some important text[cursor]                       |[expected selection]      ^^^^^^^^^[actual selection]             ^^^^I then tried the following with the same text and cursor position:v:<C-u>normal! ?iThe cursor didn't move.  I expected it to.Searching forward doesn't work either:v:<C-u>normal! /tHowever all these work:v:<C-u>normal! bv:<C-u>normal! ev:<C-u>normal! Fiv:<C-u>normal! ftHow can I solve this?
How to search in visual mapping?
cursor motions;visual mode
This is because the <CR> in your mapping signals to the norm command to finish, not for the the ? command to finish. So when you get to the first <CR>, the command that vim runs isnormal! ?[^a-z]?e+1And this command does not do anything. Because you don't hit enter by the time the normal command is over, nothing actually happens. So here we have a dilemma. We need to tell vim to press enter inside of the normal command, but we can't press enter (because that finishes the normal command). Here is where we use <C-v> to enter a literal carriage return.So you need to put a <C-v> before every <CR> that is not the final <CR> in your command. This makes the following mapping:xnoremap in :<C-u>normal! ?[^a-z]?e+1<C-v><CR>v/[^a-z]/s-1<C-v><CR><CR>onoremap in :normal vin<CR>Some unrelated side notes about your approach:This approach only works if you're in the middle of your object. If you're at the beginning of it, things break.Using \L is equivalent to [^a-z], and is faster and more readable.