I want a command mapping to detect whether the current line is blank, and perform a different action for each case it detects: true of false. How do I do this?
1 Answer
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>
-
-
-
1@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. Apr 23, 2021 at 8:07