Vim: split and join by bar?
Would it make sense for the Vim mode to handle/use bars (|) to join/split?
E.g. the following:
if bufname("%") == "peekabook"
return
endif
to:
if bufname("%") == "peekabook" | return | endif
So basically, it would use | for splitting/joining, in case there is no continuation backslash (which is handled currently).
In this case, the only way for it to make sense is to work on specific constructs, like if-clauses. Which I can try to implement. As you said, joining is not going to be a problem, since I can just check if the next line starts with a \. I'm not sure about splitting.
Right now, splitting a line just relies on being in the right place. Maybe I could do something like, "if the cursor is on or just before a |, then split by that", although I'm not sure of edge cases. I'll try it out.
Do you have any other constructs you'd like splitjoin to work on, apart from if-clauses?
Thanks for looking into this!
Do you have any other constructs you'd like splitjoin to work on, apart from if-clauses?
Maybe this could be based on endwise's list?
'fu,fun,func,function,wh,while,if,for,try,au,augroup' (https://github.com/tpope/vim-endwise/blob/master/plugin/endwise.vim#L46).
Be aware that there are cases, in which retaining the bars is the desired behaviour, such as in an (auto-) command. For example, I have this command living in my ftplugin/tex.vim:
command! -buffer -bang -range -nargs=1 -complete=file Export <line1>,<line2>w! >> <args>
\| <line1>,<line2>d
\| if '<bang>' == '!'
\| call append(line('.') - 1, '\input{<args>}')
\| endif
Or this autocmd in my vimrc:
autocmd FileType tex,mail,pandoc if exists(':Thesaurus') | setlocal keywordprg=:Thesaurus | endif
In both cases, the desired behaviour is to retain the bars while adding line-continuation characters on splitting / deleting line-continuation characters on joining.