Showing posts with label Vim. Show all posts
Showing posts with label Vim. Show all posts

Thursday, July 26, 2007

VIM Tip

Convert any file to html file using vim from command prompt :
vim -c ":runtime! syntax/2html.vim | :wq | :q " <FILENAME>
File Created: <FILENAME>.html

Example:
vim -c ":runtime! syntax/2html.vim | :wq | :q " a.c

will create a file "a.c.html"

Monday, May 29, 2006

Vim Movements

Moving Around
k (up),
h(left) l (right).
j (down)
(Ex 5k,j,3l )

Word Movement
w (Forward Word Movement Ex. f,5f )
b (Backword Word Movement Ex. b,2b)
e (Forward Word Movement at the end of word Ex. e,3e )
ge (Backword Word Movement at the end of word Ex. ge,3ge )

Moving to the Start or End of a Line
$(End Of Line Ex. $,2$)
^(Start Of Line Ex. ^,3^)

Searching Along a Single Line
f<Charcter> (Searching Charcter Forward Ex. fa, 2fv)
F<Charcter> (Searching Charcter Backword Ex. Fg,2Ft)
t<Charcter> (Search till Forward )
T<Charcter> (Search till Backword)

Moving to a Specific Line
<Line No.>G (Go to Line No.)
CTRL-G (Where I am in the File)
g CTRL-G (Count col, line, words and bytes)
CTRL-O Jump to previous location.
<TAB> Jump to next location (line 10).

Where are you in File
:set number
:set nonumber

Scrolling Up and Down
CTRL-U (scrolls up half a screen of text.)
CTRL-Y (scrolls up a line of text.)
CTRL-B (scrolls up a entire screen at a time.)
CTRL-D (scrolls down half a screen of text.)
CTRL-E (scrolls down one line.)
CTRL-F (scrolls down one screen of text.)
z<Enter> (screen line on the top)
88z<Enter> positions line 88 at the top.
zt (Leaves the cursor where it is.)
z- (scrolls line to the end of the screen)
zb (Leaves the cursor where it is)
z. (Center of the screen)
zz (Leaves the cursor where it is .)

:set scroll=10
:set scrolljump=5
:set scrolloff=3

Deleting
x delete character under the cursor (short for "dl")
X delete character before the cursor (short for "dh")
dw (Delete Word Ex. dw,3dw,d3w,3d2w,d$,d^,df> )
dd (Delete Line Ex. dd,3dd)
D (Delete up to end of line. )(short for "d$")
diw delete word under the cursor (excluding white space)
daw delete word under the cursor (including white space)
dG delete until the end of the file
dgg delete until the start of the file

Arthemetic
CTRL-A Incrmenting Number (123, 0177, 0x1f,-98)
CTRL-X Decrementing Number

:set nrformats=""

Changing Text
cw (Change Word Ex cw,c2w)
C stands for c$ (change to end of the line)
s stands for cl (change one character)
S stands for cc (change a whole line)

The . Command
It repeats the last delete or change command.

Joining Lines
J (Join Lines to One. Ex J,3J)
gJ (Join Lines without Spaces)

Replacing Charcter
r<Charcter> (Replace Charater Under Cursour. Ex. ru,5ra,3r<Enter> )
R<Charcter>

Changing Case
~ (Change Case of Character Ex. ~,12~,~fq)
U (Make the text Uppercase)
u (Make the text Lowercase)
g~motion (It does not depend on tildeop)
g~~ or g~g~ (Changes case of whole line)
gUmotion (All uppercase)
gUU (Changes to uppercase for whole line)
gUw (Changes to uppercase for word)
guw (Changes to lowercase for word)

Vim Folding Tips

# folding : hide sections to allow easier comparisons

zf{motion} or {Visual}zf :Operator to create a fold.
zf'a : fold to mark
zF :Create a fold for N lines.
zd :Delete one fold at the cursor.
zD :Delete folds recursively at the cursor.
zE :Eliminate all folds in the window.
zo :Open one fold.
zO :Open all folds recursively.
zc :Close one fold.
zC :Close all folds recursively.
za :When on a closed fold: open it.and vice-versa.
zA :When on a closed fold: open it recursively.and vice-versa.
zR :Open all folds.
zM :Close all folds:
zn :Fold none: reset 'foldenable'. All folds will be open.
zN :Fold normal: set 'foldenable'. All folds will be as they were before.
zi :Invert 'foldenable'.

[z :Move to the start of the current open fold.
]z :Move to the end of the current open fold.
zj :Move downwards. to the start of the next fold.
zk :Move upwards to the end of the previous fold.

My vimrc: Open a c/cpp/java/perl programm. Press <F6> and see the power of
vim :-)

nmap <F6> /}<CR>zf%<ESC>:nohlsearch<CR>

Vaibhav.

Vim and HTML

HTML and vim Tips:

:runtime! syntax/2html.vim :convert txt to html
:%s#<[^>]\+>##g : delete html tags, leave text

My vim.rc : Type a word and press ",," without quote

imap <silent> ,, <ESC>"_yiw:s/\(\%#\w\+\)/<\1> <\\\1>/<cr><c-o><c-l>f>a

Vaibhav.