write as an expression?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

write as an expression?

Bee-16
I would like this function to be written as an expression.

function! SpellReplaceAll()
  if &spell
    try | spellr
    catch
    endtry
  endif
endfun
nmap <F6> :call SpellReplaceAll()<cr>

How to make it work as an expression?

The following does not work :(
nmap <F6> &spell==1 ? spellr<cr>

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: write as an expression?

Tim Chase
On 2018-07-19 08:17, Bee wrote:

> I would like this function to be written as an expression.
>
> function! SpellReplaceAll()
>   if &spell
>     try | spellr
>     catch
>     endtry
>   endif
> endfun
> nmap <F6> :call SpellReplaceAll()<cr>
>
> How to make it work as an expression?
>
> The following does not work :(
> nmap <F6> &spell==1 ? spellr<cr>

Might be able to use an <expr> map.  Untested

  :nnoremap <expr> <f6> &spell?':spellr<cr>':''

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: write as an expression?

Bee-16
Thank you Tim
Both these work.
When to use ' or " ?

nmap <expr> <F6> &spell?':spellrepall<cr>':''
nmap <expr> <F6> &spell?":spellrepall<cr>":""

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: write as an expression?

Tim Chase
On 2018-07-19 10:08, Bee wrote:
> When to use ' or " ?

In some contexts (that I don't have memorized) a double-quote is
treated as the start of a comment.

  :help :quote

Also, double-quote strings can get special sequences replaced in them
while single-quote strings don't:

  :help expr-quote
  :help literal-string

I tend to use the single-quote for all strings in Vim unless I have
need for the specific replacement functionality that double-quotes
provide.

-tim



--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.