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

General support for joining lines with line continuation characters #114

Open
kiryph opened this issue Jun 13, 2017 · 6 comments
Open

General support for joining lines with line continuation characters #114

kiryph opened this issue Jun 13, 2017 · 6 comments

Comments

@kiryph
Copy link

kiryph commented Jun 13, 2017

I miss support for the commonly found line continuation style with a trailing backslash when joining lines. For example in cmake:

message("\
This is the first line of a quoted argument. \
In fact it is the only line but since it is long \
the source code uses line continuation.\
")

I would like to have following behavior: when joining those lines, the backslashes are automatically removed.

Many languages use this style:

  • awk
  • c
  • c++
  • cmake
  • gnuplot
  • python
  • shell scripting languages (e.g. bash)

and most likely many more which I am however not familiar with.

I know this does not apply to all languages, e.g. Lua which uses \z:

The escape sequence '\z' skips the following span of white-space characters, including line breaks; it is particularly useful to break and indent a long literal string into multiple lines without adding the newlines and spaces into the string contents.

@AndrewRadev
Copy link
Owner

Yeah, that makes sense, I've thought about it myself. I guess it should be a global definition, of which there's currently none. I'll see what I can do about it.

@gaving
Copy link

gaving commented Aug 30, 2020

I'd also be quite keen on this kind of functionality for shell scripts e.g. transforming:-

codeclimate() {
  docker run --interactive --tty --rm --env CODE_PATH="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate "$@"
}

To:-

codeclimate() {
  docker run \
    --interactive \
    --tty \
    --rm \
    --env CODE_PATH="$PWD" \
    --volume "$PWD":/code \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume /tmp/cc:/tmp/cc codeclimate/codeclimate "$@"
}

And back.

Currently just do a '<,'>snomag/--/\ ^M--/g but would be nice if it was a suitable feature of splitjoin (assuming it made sense)!

@flwyd
Copy link

flwyd commented Nov 2, 2023

I wrote https://github.com/flwyd/vim-conjoin to remove line continuation characters for several dozen filetypes (though I wasn't aware of Lua's \z and backslash-newline continuations inside strings). Conjoin cooperates with splitjoin's gJ as long as the splitjoin plugin is loaded before conjoin.

Conjoin only removes characters when joining lines, it doesn't add line continuations when splitting, so it doesn't help the shell script example in comment 3.

@AndrewRadev
Copy link
Owner

Sorry for ignoring this issue for quite a while. I think I kept postponing it, because I wanted to implement a general "global" setup. Instead, to provide at least something that's helpful, I've pushed a branch, line-continuations which implement splitting for the sh filetype in particular.

It only splits one at a time, so for large command-lines, it could take some f-., but the alternative might get complicated fast, since ---style flags have varying conventions, there's |-separated parts... Formatting this stuff might be tricky. We ended up with a similar arrangement for Vimscript in #15.

@gaving, if you're still around, I'd appreciate your thoughts on your use case.

@kiryph The implementation might be reusable, since the way the plugin is implemented, it just triggers certain callbacks. If the bash example works well, I could manually add support for several other filetypes rather than generalizing. What do you think?

@AndrewRadev
Copy link
Owner

Update: I've merged the branch, since I've found it pretty useful for bash myself.

@gaving
Copy link

gaving commented Nov 25, 2023

@AndrewRadev Just seen this, look forward to trying it out!

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

4 participants