Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim: split and join by bar? #77

Open
blueyed opened this issue Aug 13, 2015 · 3 comments
Open

Vim: split and join by bar? #77

blueyed opened this issue Aug 13, 2015 · 3 comments

Comments

@blueyed
Copy link

blueyed commented Aug 13, 2015

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).

@AndrewRadev
Copy link
Owner

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?

@blueyed
Copy link
Author

blueyed commented Aug 22, 2015

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).

@lgalke
Copy link

lgalke commented Mar 15, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants