-1

I want to detect whether the current line my current on is only composed of non-visible characters, and return true of false, and use this check to trigger some nnoremap mapping, how?

3

It is not entirely clear when you say to "trigger some mapping"... Do you want to create a mapping with nnoremap if current line is empty? I guess not. Or you want to have a mapping that does different things depending on whether current line is empty?

If so then there are many possibilities, for example:

func! DoSmth()
    if getline('.') =~ '^\s*$'
        echo 'Do something if empty line!'
    else
        echo 'Do something if NOT empty line!'
    endif
endfunc

nnoremap <space>a :call DoSmth()<CR>
3
  • Yes I meant the second one you mentioned. – job_start Apr 23 at 6:27
  • May I also ask you that how to detect the previous line exists? – job_start Apr 23 at 6:52
  • @job_start it would be better to create another question for this. But in general, check :h function-list in vim to get an idea of what API vim exposes to vimscript. – Maxim Kim Apr 23 at 8:07

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.