0

The goal is to create a mapping that will:

  • create a mapping for the user --> remap does the trick
  • that gets the current expression under the cursor --> expand('<cexpr>') will do the trick
  • put this into the command line, so the user can adjust as necessary

What I've tried so far:

  • :let exp = expand('<cexpr>') -> gets the value, for example "my_expr"
  • nnoremap = :Evaluate<Space> expand('<cexpr>') -> writes that text in there instead of resolving it
  • nnoremap <expr> = 'Evaluate '. expand('<cexpr>') . ' = ' --> changes to visual mode

should pre-set the ex command to :Evaluate my_expr so the user can adjust the expression before pressing enter.

0
2

I think you're just missing a colon before Evaluate...

nnoremap <expr> = ':Evaluate '. expand('<cexpr>') . ' = '

When I try it with the colon I get

Evaluate foo = 

...waiting at the command line.

Without the colon I get Visual mode just like you describe. Remember, this is a Normal mode mapping so it's like you literally enter E followed by v in Normal mode which places you in Visual mode. Adding the colon makes sure you go to the command line first.

2
  • As I'm a "new contributor" here I take the option to not be Q+A in a comment: Thanks, feels a bit dumb to have that asked - but both the explanation and the solution is now clear! Nov 18 '21 at 21:02
  • 1
    You're welcome and don't even worry about that. We all overlook small things from time to time. Welcome to Vi&Vim SE...as a contributor. :)
    – B Layer
    Nov 18 '21 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.