vim-surround icon indicating copy to clipboard operation
vim-surround copied to clipboard

Issue dsB

Open Mephistophiles opened this issue 8 years ago • 3 comments

vimrc:

set nocompatible
filetype off
set runtimepath+=~/.vim/bundle/dein.vim/

call dein#begin(expand('~/.vim/bundle/'))
let g:dein#types#git#clone_depth = 1

call dein#add('tpope/vim-surround')

call dein#end()
filetype plugin indent on

test sample:

$ - cursor

#include <stdio.h>


int main(void) {
        if (1) {
                $return 1;
        }

        return 0;
}

on dsB result:

#include <stdio.h>


int main(void) {
        $if (1)          return 1;


        return 0;
}

Mephistophiles avatar Feb 03 '17 13:02 Mephistophiles

Hey just so you know ds} does what you want; dsB maps to ds{ by default. The difference is subtle and relates to whitespace; if you prefer the other behaviour you could try mapping dsB to ds} instead.

qstrahl avatar Apr 07 '17 20:04 qstrahl

I would like to return was on a new line. Is this possible?

Mephistophiles avatar Apr 08 '17 08:04 Mephistophiles

I just encountered this issue.

Observed behavior:

if (condition) {
	true
}

With the cursor on the t in true. Pressing dsB or ds} results in:

if (condition) 	true

Or if ds{ is pressed:

if (condition) true

like qstrahl mentioned, only the whitespace differs.

Expected behavior

I was expecting the same outcome as Mephistophiles:

if (condition)
	true

that only the curly brackets would have been deleted, and the true line remained below the if statement.

That's how it works if the open curly bracket is on it's own line:

if (condition)
{
	true
}

dsB, ds} and ds} all result in:

if (condition)
	true

By design?

When there are two or more lines in the if statement:

if (condition) {
	one
	two
}

and the curly brackets are deleted:

if (condition) 	one
two

then only the first line ends up on the line above. Maybe it's on purpose to make it clear that only the first line depends on the condition?

Or I might be overthinking it and the most common indentation style is to have the open curly bracket on it's own line, so that's what vim-surround targets, and when the open curly bracket is deleted then the line below moves up.

System Info

vim-surround 2.1
gvim_8.1.0451_x64
Windows 10 version 1803

Notes

While I was testing the different brace placements here: https://en.wikipedia.org/wiki/Indentation_style#Brace_placement_in_compound_statements

I noticed that the Horstmann style:

if (condition)
{ one
  two
}

causes another issue when the curly brackets are deleted:

if (condition one
		two)
{
}

the lines inside the curly brackets end up inside the condition parentheses, and the curly brackets remain undeleted.


I also noticed that the Whitesmiths and Lisp styles indent the open curly bracket, so I tried it with Horstmann:

if (condition)
	{ one
	two
}

and this happens when the curly brackets are deleted:

one
	two
if (condition)

the two lines in the if statement ends up above the condition.

The Horstmann style might not be used very often, and indenting the first line is probably even rarer, but the current behavior is definitely unexpected.

duianto avatar Oct 06 '18 03:10 duianto