 |
HowToForums.net An Open Source of Knowledge
|
View previous topic :: View next topic |
Author |
Message |
jacob Site Admin


Joined: 16 Mar 2006 Posts: 73 Location: USA
|
Posted: Thu Jul 06, 2006 10:17 pm Post subject: HowTo Vim copy, paste, select text, syntax highlighting... |
|
|
This HowTo Vim is a quick crash course refference on the essentials to get you started with VIM...
"Vim is an advanced text editor that seeks to provide the power of the de-facto Unix editor 'Vi', with a more complete feature set. It's useful whether you're already using vi or using a different editor."
-- http://www.vim.org/
A breif on Modes...
Vim uses "modes" to do certain functions, like "insert", "copy", "Search and Replace" etc...
So to go into Normal mode aka "read only" mode, which is the default when you start up simply press <ESC>...
Now the list below explains what keys bring you to a certain mode from Normal mode.
So to switch between the modes below make sure to <ESC>...if you are not sure, press <ESC> twice.
Basics:
To enter Vim (from the % prompt) type: vim FILENAME <ENTER>
Code: |
i insert text mode
:q! <ENTER> to trash all changes.
:w <ENTER> to save.
:wq <ENTER> to save the changes and exit.i
|
Copy & Select Text aka Yank
Code: |
v Visual - move with <Up>,<Down>, <Left>, <Right> (the arrow keys)
or with <Home>, <End>, <Page Up / Down> to select the text you
wish to handle.
+y Copy the selected text.
d Cut the selected text.
ggVG Select all - I know this one is a bit harsh to remember,
one alternative would be just to copy the file ;-)
|
*NOTE: when using a key like "+" in the sequence, you will need to use shift.
Paste aka Put:
Code: |
p Puts the deleted text AFTER the cursor
(if a line was deleted it will go on the line below the cursor).
|
Delete aka Cut:
*NOTE: You can paste anything that is deleted... in vim "delete" and "cut" is the same.
Code: |
dw To delete from the cursor to the end of a word type.
d$ To delete from the cursor to the end of a line type.
dd To delete a whole line type.
|
Change & Replace
Code: |
r To replace the character under the cursor, type r and then the
character which will replace the original.
cw To change from the cursor to the end of the word
c$ To change to the end of a line.
|
Undo:
Code: |
u To undo previous actions. (lowercase u)
U To undo all the changes on a line. (capital U)
CTRL-R To undo the undo's aka "Redo"
|
Search & Search and Replace aka "Find and Replace"
Code: |
/someword [ENTER] This would search for "someword".
Then to find the next, type n...and previous would be <SHIFT> + n.
:%s/old/new/gc Search & Replace with confirmation.
|
Execute External Commands from within Vim
Code: |
:!<command>
:!ls This would execute "ls" from Vim.
|
Vim Syntax Highlighting
To make your Vim a bit more prettier and use full enable "syntax highlighting"...
To do so
1. Find & Edit your vimrc file. in Ubuntu it would be: /etc/vim/vimrc
2. Remove the quotation marks from the line that says:
3. At the end of the file, insert a line like below:
Code: |
colorscheme evening
|
Other Usefull refrerence links:
vim & gvim - http://www.vim.org
http://www.vi-improved.org/
http://www.vi-improved.org/wiki/index.php/IrcFaq
vimtutor - http://linuxcommand.org/man_pages/vimtutor1.html
cream - a windows key like version of gvim -- http://cream.sourceforge.net/ _________________ JB
--
"You only see what your eyes want you to see" |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|