5

I often press:

  • <Ctrl> V to go into visual block mode and highlight a column
  • hit <shift>-i (to insert at the beginning of the line), type a few things (at this point, I see my changes on the first line, but not any others).
  • and then hit <Esc> to go back to normal mode.

After I hit <Esc>, I see the stuff I inserted get put in each of the other lines.

What I would like is to visually see my changes on each line, as I type, rather than only on the first line. Is that possible?

Go into Visual Block, select a bunch of lines enter image description here

Hit <Shift> i enter image description here

Add some text - This is the part I'd like to be changed. I'd like for the spaces to be immediately visible on all lines, not just the first line. enter image description here

Hit Escape - Now the spaces are added on every line. I'd like for this to happen sooner. enter image description here

I know that I could have done what I did in this example with >>. I chose a simplified example to illustrate the thing I'd like to change.

Thanks!

1 Answer 1

1

Try adding this to your vimrc:

nmap <buffer> <silent> <expr> <F12> InsertCol() imap <buffer> <silent> <expr> <F12> InsertCol() function! InsertCol() let w:first_call = exists('w:first_call') ? 0 : 1 "if w:first_call " startinsert "endif try let char = getchar() catch /^Vim:Interrupt$/ let char = "\<Esc>" endtry if char == '^\d\+$' || type(char) == 0 let char = nr2char(char) endif " It is the ascii code. if char == "\<Esc>" unlet w:first_call return char endif redraw if w:first_call return char."\<Esc>gvA\<C-R>=Redraw()\<CR>\<F12>" else return char."\<Esc>gvlA\<C-R>=Redraw()\<CR>\<F12>" endif endfunction function! Redraw() redraw return '' endfunction 

Then press Ctrl-vI as usual, and then press F12. It will insert and show all lines changed for each keystroke.

Note: The script would be better if pressing F12 would go into insert mode, instead of requiring you to press I each time. Maybe the startinsert command in combination with vnoremap could do this.

4
  • Sweet! vmap I I<F12> along with your script does the job. Do you know if there's a way to make the cursor appear on the line while the insert's happening? Commented Jan 4, 2016 at 5:41
  • This page appears to offer a solution to the cursor problem: vim.wikia.com/wiki/… Commented Jan 4, 2016 at 5:49
  • Yes, it works -- add this to make the cursor appear on the line: imap <F12>ignore-me <Nop> Commented Jan 4, 2016 at 5:53
  • That doesn't work for me. Commented Jan 5, 2016 at 6:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.