Reputation: 83
sorry if this isn't exactly a programming question.
I mainly use Vim to edit my programs. So my question to all the Vim experts out there is:
is there a way to select and scroll in Vim? I want to copy a bunch of code, and in the pass I have always copied everything I can view on the vim screen then paste it to where-ever, then scroll down then copy and paste..repeat..until done. Is there a way I can efficiently copy a large block of code?
Formatting lines of code- you know when you copy and paste some code sometime 10 lines of code turn into 30 really messy lines of code? well, is there a command to reformat the code? In the pass I manually go back and properly indent everything which sometime is super repetitive when you got 500 lines. I saw on other sites something about the command being 1G = G
can someone confirm that? when I try it in my command line, I get a error E464: ambiguous use of user-command line
which I have no idea what that even means.
I do know there is a help command in Vim,but I have no idea where to even start when there is something like 200 txt files and frankly this is faster :)
Upvotes: 1
Views: 208
Reputation: 72639
The vim way is to entirely forget selection using the mouse for more than a screenful, but to set a mark, move to the other end of the desired text, then yank to mark:
mm
y'm
P
or p
Upvotes: 2
Reputation: 172570
Your questions are around basic use of vi / Vim. Do yourself a favor and go through a Vim tutorial; you'll find many on the web, and Vim comes with it's own introduction, vimtutor.
On Unix, if Vim has been properly installed, you can start it from the shell:
vimtutor
On MS-Windows you can find it in the Program/Vim menu. Or execute vimtutor.bat in the $VIMRUNTIME directory.
Also, learn how to look up commands and navigate the built-in :help
; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.
Upvotes: 3
Reputation: 1589
This whole answer is only helpful if you can use register +
as clipboard. Try "+yy
in VIM, try to paste it in another application to see if you can use the clipboard, if you can:
You should really read the manuals and other help:
To yank lines (simple) : http://vim.wikia.com/wiki/Moving_lines_up_or_down
To address lines: Addressing in VIM
That is to start with.
Some examples of what you can do:
:.,+50y a
yank 50 lines from current and 50 ahead to register a, use A
instead to append to register A.
:.,/some pattern/y A
yank (append) from current to first line that match /some pattern/ to register a.
"Ay/some pattern<CR>
will do the same thing.
Once you learn how you should address, it's easy to combine commands with addressing, e.g. the "indenting command" =
:
=}
auto indent to the end of current paragraph
=/some pattern<CR>
auto indent to line matching /some pattern/
Mark something in Visual mode and type =
it will auto indent the selected text.
And so on... So read manuals, you will have a great use of it.
In the above examples you can use register +
to "yank" to the clipboard instead of register a
.
Upvotes: 1