I have two functions, one using an if
statement and one using (or trying to use) a ternary expression:
nnoremap <expr> Z Toggle1()
func Toggle1 ()
if g:colors_name == "OceanicNext"
return ":colorscheme TextMate^M"
else
return ":colorscheme OceanicNext^M"
endfunc
nnoremap <expr> Q Toggle2()
func Toggle2 ()
echom g:colors_name
let cs = "TextMate" ? (g:colors_name == "OceanicNext") : "OceanicNext"
let cmd_string = printf(":colorscheme %s^M", cs)
return cmd_string
endfunc
The first one works, but the second one only 'works' the first time I run it. What's the difference between the two, and what am I doing wrong in the second one?
condition ? value1 : value2
– Matt Jun 13 '20 at 6:56nnoremap <expr> CC g:colors_name == "oceanicnext" ? ":colorscheme textmate^M" : ":colorscheme oceanicnext^M"
– David542 Jun 13 '20 at 7:04