Thursday, May 27, 2021

Re: Insert non-rectangular selection

On Di, 25 Mai 2021, Andre Tann wrote:

> Hi all,
>
> I repeatedly have the following situation, and wonder how it can be handled
> better than I do it now. These lines must be merged
>
> /path;text
> /path;text
> /path;text
>
> with these:
>
> /subdir
> /longsubdir
> /longlongsubdir
>
> Result:
>
> /path/subdir;text
> /path/longsubdir;text
> /path/longlongsubdir;text
>
>
> What I do now is to mark and yank the second block, go to the first
> semicolon, and press P. Result is:
>
> /path/subdir ;text
> /path/longsubdir ;text
> /path/longlongsubdir;text
>
> But this is obviously not what I want. How can I avoid the extra blanks?

I have this annoyance a few times as well. I would go with the already
mentioned `:s` approach to remove the whitespace, afterwards. However, I
was wondering, if we not could do any better any perhaps have something
like a `zp` command, that does not add any trailing spaces.

diff --git a/src/normal.c b/src/normal.c
index 92135c18c..25f8233bb 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -2973,6 +2973,10 @@ dozet:
}
break;

+ // "zp", "zP" in block mode put without addind trailing spaces
+ case 'P':
+ case 'p': nv_put(cap);
+ break;
#ifdef FEAT_FOLDING
// "zF": create fold command
// "zf": create fold operator
@@ -7407,11 +7411,13 @@ nv_put_opt(cmdarg_T *cap, int fix_indent)
}
else
dir = (cap->cmdchar == 'P'
- || (cap->cmdchar == 'g' && cap->nchar == 'P'))
- ? BACKWARD : FORWARD;
+ || ((cap->cmdchar == 'g' || cap->cmdchar == 'z')
+ && cap->nchar == 'P')) ? BACKWARD : FORWARD;
prep_redo_cmd(cap);
if (cap->cmdchar == 'g')
flags |= PUT_CURSEND;
+ else if (cap->cmdchar == 'z')
+ flags |= PUT_BLOCK_INNER;

if (VIsual_active)
{
diff --git a/src/register.c b/src/register.c
index 6ba4e896d..afa83cba8 100644
--- a/src/register.c
+++ b/src/register.c
@@ -1497,6 +1497,7 @@ copy_yank_reg(yankreg_T *reg)
* "flags": PUT_FIXINDENT make indent look nice
* PUT_CURSEND leave cursor after end of new text
* PUT_LINE force linewise put (":put")
+ * PUT_BLOCK_INNER in block mode, do not add trailing spaces
*/
void
do_put(
@@ -1845,12 +1846,17 @@ do_put(

yanklen = (int)STRLEN(y_array[i]);

- // calculate number of spaces required to fill right side of block
- spaces = y_width + 1;
- for (j = 0; j < yanklen; j++)
- spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0);
- if (spaces < 0)
+ if (flags & PUT_BLOCK_INNER)
spaces = 0;
+ else
+ {
+ // calculate number of spaces required to fill right side of block
+ spaces = y_width + 1;
+ for (j = 0; j < yanklen; j++)
+ spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0);
+ if (spaces < 0)
+ spaces = 0;
+ }

// insert the new text
totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces;
diff --git a/src/vim.h b/src/vim.h
index 368cf3256..ef86312da 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1068,6 +1068,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define PUT_LINE 8 // put register as lines
#define PUT_LINE_SPLIT 16 // split line for linewise register
#define PUT_LINE_FORWARD 32 // put linewise register below Visual sel.
+#define PUT_BLOCK_INNER 64 // in block mode, do not add trailing spaces

// flags for set_indent()
#define SIN_CHANGED 1 // call changed_bytes() when line changed

Mit freundlichen Grüßen
Christian
--
Werfen Sie leere Konservendosen nicht weg! Bewahren Sie sie auf! Nach
einigen Jahren haben Sie dann eine schöne Sammlung alter Konservendosen.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210527075859.GB1800871%40256bit.org.

No comments: