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 communitySay 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?
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)
– Niels
May 3 '20 at 17:44
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".
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. – statox Dec 30 '16 at 10:3317a*<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.) – Aaron Thoma Jan 14 '17 at 16:36