Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
6 total  XML / RSS feed 

Convert Mac to Unix line endings in VI

If you open a text file in VI and see one big line with lots of '^M' where the line endings are supposed to be, use this command to fix it.
(Enter the the ^M by hitting ctrl-v and then the return key.)

:1,$s/^M/\r/g

vi find/replaces for adding a table prefix to a SQL dump

Was importing a DB but wanted to prefix the tables, but the file was too large for TextMate. Here's all the vim substitutions

%s/DROP TABLE IF EXISTS `/DROP TABLE IF EXISTS `prefix_/g
%s/CREATE TABLE `/CREATE TABLE `prefix_/g
%s/INSERT INTO `/INSERT INTO `prefix_/g
%s/LOCK TABLES `/LOCK TABLES `prefix_/g
%s/ALTER TABLE `/ALTER TABLE `prefix_/g

vi - change and save settings to the editor

within home directory, edit the .exrc file with set commands

the following sets numbered lines and auto indent.
Full listing of set commands available within by using :set all in vi
set nu
set ai

How to count particular words in vim

From one of the comments in http://www.vim.org/tips/tip.php?tip_id=689

:%s/word/&/g


The above substitutes "word" for itself, and tells you the number of substitutions made.

Show line numbers in vi

:se nu

Remove ^M characters using vi

To remove all "^M" characters from a file, open it in vi and use this command:
:%s/^M//g

The "^M" in the above line has to be typed in by pressing CTRL+v and then CTRL+M.
« Newer Snippets
Older Snippets »
6 total  XML / RSS feed