Showing posts with label gvim. Show all posts
Showing posts with label gvim. Show all posts

Wednesday, April 11, 2007

vi replace with confirmation and replace with regex group

Search from every line, replace confirmation (with [y]es)
:%s/search_string/replace_string/gc

Replace with regex group:
:%s/<img alt="\(.\+\)"\ssrc=.\+/\1/gc

Vi simple tutorial

Some examples:
You have [admin, admin1, user3], and you would like to change it to ['admin','admin1','user3']; here your are:%s\(\w\+\)/'\1'/gc

Thursday, April 5, 2007

Gvim: encoding puzzles.

You can reload a file using a different encoding if vim wasn't able to detect the correct encoding:
:e ++enc=<encoding>
for example:
:e ++enc=utf-8

Choose a font type like Courier New.

You can achieve both of these by adding the following lines in your gvim startup configuration file .vimrc:

set enc=utf-8
set guifont=Courier_New:h11:cDEFAULT

How to comment multiple lines in vim?

Place cursor at the beginning of the first line you want to change.
Press Ctrl+v
Move the cursor down to the last line you want to change.
Press I (The capital letter after H and before J)
Type in the text you wish to insert
Press Esc

Now all lines selected should show the inserted text.

Want to insert new line in file?
try \r, like:
%s/,/,\r/gc

Wednesday, March 21, 2007

Copy, paste, and cut text block in VI

Copy block in vi:
Mark Beginning of Block : mx set mark x (x may be any letter)
Mark End of Block and "Copy'' : y`x yank from here to mark x into buffer
Mark End of Block and "Cut'' : d`x delete from here to mark x into bufferFor the whole file try:

Goto to line one: 1G
Sort from current line to end of file: !Gsort<cr>
Or if you want to think of it as one command: 1G!Gsort<cr>

Sort a range:
Move Cursor to last line to sort
mark the line with mark 'a': ma
move cursor to first line to sort
sort from current line to mark 'a': !'asort<cr>

Now what does the special chars above mean.

'!' is the vi filter command, it is followed by a movement command
that says what is being filtered. That is followed by the actual
filter cmd. The filter cmd can be any executable. In this case sort.
Since vi does not know how long the filter command name is, you have
to hit carriage return to initiate the filter.

G by itself means go to the end of the file

ma means set mark a to this line. (marks a-z exist)

'a means goto mark a.

Tuesday, February 27, 2007

GVim: changing DOS style end of line to UNIX, or vise-versa

How to use GVim to change DOS style end of line to UNIX, or vise-versa?
To save the file in DOS style:
:set fileformat=dos
:w
To save the file in UNIX style:
:set fileformat=unix
:w
Please refer to here.