0

For example, another ternary operator with map k:

nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')

When you go line down on a wrapped line, gk makes that you go to the next fictional line of a wrapped line. But when you do 5j, it will go 'over' the wrapped line. It worked fine.

In my case, I have mapped the zj to NextClosedFold() function.

But I thought it would be better, if I'm currently in a opened fold, and with zj, I could to the end of a opened fold, like ]z.

So I decided to create a map:

nnoremap <silent> sj (foldclosed('.') == -1 ? ]s : au call NextClosedFold('j')<cr>)   

The :echo foldclosed('.') will indicate if you're on a folded line or not. If youre not on a closed fold (-1), it will give ]s, but when this is not the case, it will move to the next closed fold. But the map is not working. I think it has something to do with the closing parenthesis, that Vim will interpret as closing the evaluation too early.

Any thoughts how to work around this?

Julius Martin
  • 159
  • 2
  • 8

1 Answers1

3
nnoremap <expr> sj foldclosed('.') == -1? ']s':NextClosedFold('j')

Note:

  • I think NextClosedFold() is your own function, also I have no idea what does the j argument mean, I just use it in the mapping. Your function should return a string, indicating the keystrokes in that case.

  • You should use <expr> mapping

  • You should not use call Func()<cr> in a <expr> mapping, the au doesn't make any sense either.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • Thanks for your reply. For reference, I have NextClosedFold picked [from this](http://stackoverflow.com/questions/9403098/is-it-possible-to-jump-to-closed-folds-in-vim). I tried your suggestions, which didn't worked. Then I tried this: " nmap 1sj :call NextClosedFold('j') " nmap 2sj ]z " nmap foldclosed('.') == -1 ? '2sj' : '1sj' Any ideas? – Julius Martin Nov 06 '14 at 21:12