Say I have a comment like this:
//This is a comment
And I want to make it like this:
//*****************
//This is a comment
//*****************
Is there an easy way to insert a character repeatedly until even with the next/previous line?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this community
v
$
r
*
y y p / P Duplicate line to below/above
2 l Move to position from where to overwrite (in this case 3rd column ← 2 to the right)
v $ Select till end of line
r Replace all selected characters by char…
*
.
to repeat the pattern on the other line! If you copy the line above and below, use v$r*
on one of the lines, navigate to the other and press .
(don't have enough rep for a comment)
At the occasion°:
" Insert the rest of the line below the cursor.
" Mnemonic: Elevate characters from below line
:inoremap <A-e>
\<Esc>
\jl
\y$
\hk
\p
\a
" Insert the rest of the line above the cursor.
" Mnemonic: Y depicts a funnel, through which the above line's characters pour onto the current line.
:inoremap <A-y>
\<Esc>
\kl
\y$
\hj
\p
\a
… is built-in: :help i_CTRL-E
:
CTRL-E Insert the character which is below the cursor. CTRL-Y Insert the character which is above the cursor.
° Not what the question text was about, but what other users might be looking for here, going from the current question title "insert until even with next line".
ylP
to duplicate the char the cursor is on; and yhp
to duplicate the one to the left. You can add a count before the p
/P
. You could put for example the following mappings for Insert mode in your vimrc: :inoremap <A-l> <Esc>lylPi|:inoremap <A-h> <Esc>ylpa
(By the way, in Normal mode, you can flip chars with xp
)
Mar 8, 2022 at 2:06
ibox<key>This is a comment
(where <key> is a key you define to trigger snippets) and that will create a box of the right size withthis is a comment
inside.17a*<Esc>
would be something you could use In a similar situation where you know the number of characters you need, or the exact number doesn't matter because it doesn't have to be evenly aligned with another line.)