Tuesday, January 14, 2014

Copying and pasting text to Vim [Was: Do developers use vim exclusively or alternate with an IDE?]

On 14.01.14 11:36, Sam Bituser wrote:
> Copying and pasting text from outside of the editor. E.g. modifying an HTML
> page by swapping odd bits of text from another document. It just feels
> clunky to me and I often find myself using eclipse instead.

For me, Vim works just like any other application, as far as pasting
goes. If the other app is a GUI, then with the mouse:

a) Highlight the text to be copied - one word or a thousand.
b) Move cursor over the Vim window and whack the middle mouse button.

Vim just stays in insert mode, so alternation between typing and pasting
is seamless. Going back to edit the imported cruft costs one Esc, as
always. I'm having trouble seeing any clunkiness there, other than
having to reach for the mouse. ;-)

OK, I tend to leave autoindent on, and so have to set "paste" in Vim
beforehand, to avoid staircase text while pasting, and then set nopaste
afterwards. To minimise keystrokes, I have in .vimrc:

set pastetoggle=<F12>

When needing to paste "odd bits of text from another document",
interspersed with some hand typing, having paste set defeats automatic
line wrapping. It is easiest to leave the long lines, complete the
pasting, hit <F12> again, and _then_ format the paragraph, e.g. with gq}
Again to save keystokes, I have:

noremap ^W gq}

(Yup, I don't use Vim's windows, whatever they are. Buffers will do me.)
Maybe Alt-W would better suit some - I find "W for Width" mnemonic.
(But I have Alt-W mapped to insert the "[Was: ..... ]" gumpf in email
Subject lines, so I only need to type the new subject.)

> If I have an class that I want to call a method of I generally like to know
> what the overloads are and the order of the parameters. I've got used to
> using intellisense in VS. I don't know if it just laziness that I would
> like it or if people normally require it or not.

I install Exhuberant Ctags, spit out a tags file, then with the cursor
on the function name, hit ^] to jump to the function definition. Then ^o
takes you back. OK, I haven't tried it with C++ methods, and wonder if
overloading can be handled this way.

> "Peeking" at files real quick seems like a lot of work. Normally I do
> vsplit :o file.ext them Ctrl w w to change to the split, take a quick look
> and :q. This problem normally arises when browsing an unfamiliar repo. I
> have NERDtree but I don't think I'm using it enough. This is where the
> mouse and eclipse come in. I tend to move through a tree of files faster
> with a mouse.

If it's a lot of work, then it might be worth using an easier "Peeking" method.
What works for me is to:

$ cd src/ ; vim * include/*

Now to peek in keyboard.c while I'm in os.c, type :bu key<CR>
(Hit Tab before <CR> if you'd really like to see Vim expand the partial
name you've provided.)

If "key" wasn't unique, then tab between alternatives after <CR>.

To return to os.c after peeking, whack ^ , or hit ^o enough times to
retrace the "Peeking" movements.

BONUS1: Oops, I forgot some of what I saw, and need to "Re-Peek":
Whack ^ , do your re-peeking, whack ^, done.

BONUS2: Each file is displayed full-window-size, i.e. no squinting
through a shrunken half-window or less, which inevitably shows
less than you need to see, necessitating extra scrolling up and
down to get the whole picture through the gaps in the picket
fence.

> (I do apologise if I replied incorrectly. I've read the rules, but I am new
> to mailing lists!)

The Vim ML isn't as pernickety as some, tending more to helpfulness.
However, the benefits of bottom posting, and in replies only quoting
the text which is being responded to, are appreciated on most lists.
(See sig)

Erik
(Who realises that on MSW it would be cd src\ , having sometimes worked
in the same room as users of it.)

--
> A: Yes.
> >Q: Are you sure?
> >>A: Because it reverses the logical flow of conversation.
> >>>Q: Why is top posting frowned upon?

--
--
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.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment