Option foldexpr
is local to window, so:
:set
will establish both global and local values. Global value will be used as a default for subsequent windows where local value is not specified.:setlocal
will determine local value only.
It's not clear to me what merging the two expressions would mean, but of course you can create a fold function containing all the complicated logic you want.
What is definitely easy is to set different values for foldexpr
depending on the file (or file type). Use an autocommand for that.
So, the whole thing could be, in your .vimrc:
" Default: for all files
set foldmethod=expr
set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
nnoremap <F8> :setlocal foldmethod=expr<CR><Bar>zM
" Only for specific files
augroup NonDefaultFoldMethod
autocmd!
autocmd BufNewFile,BufRead file1.txt,file2.txt setlocal foldexpr=getline(v:lnum)!~@/
augroup end
The augroup/autocmd!
idiom is there just to avoid duplicating autocommands if you source .vimrc repeatedly. It's best practice when establishing autocommands.