February 24, 2011

Vim: How to insert and remove tabs while in Insert Mode

This tip was picked up from Daily Vim.

Here are some handy shortcuts that you can utilize while you're in insert mode.

<CTRL> + T: Adjusts current line one indent right
<CTRL> + D: Adjusts current line one indent left

 

Posted at 12:41 PM in VIM | Permalink | Comments (0) | TrackBack

January 07, 2011

VIM: How to Replace Text in Multiple Files

Today, I found a good article on using VIM to replace some text in multiple documents.   In my case, I needed to change the copyright year from 2010 to 2011 on about 15 html files.  Two (2) VIM commands made this a breeze.

:args *.html
:argdo %s/2010/2011/gec | update

Thanks,

 

Chris

 

Posted at 06:25 PM in VIM | Permalink | Comments (0) | TrackBack

October 11, 2010

VIM: How to Sort and Remove Duplicate Lines

In VIM, you can quickly sort a list of lines and remove all the duplicates by running the following command:

:sort u

Other options for using the command.

Chris

 

 

Posted at 08:49 PM in VIM | Permalink | Comments (0) | TrackBack

September 29, 2010

VIM: How to Insert the Current Date

In VIM on Windows, one can insert the current date into the buffer by issue the following command.

!! date /t

or

:r! date/t

The first command replaces the current line with the output from "date /t."  The second command inserts a new line with the date.

--Chris

Posted at 08:06 PM in VIM | Permalink | Comments (0) | TrackBack

September 11, 2010

VIM: How to convert CSV data to tab delimited data

Lets say you working on some data in a Vim buffer/window and you would like to convert this data from comma delimited to tab delimited so you can paste the tab delimited data directly into Excel.

Run the following ex command

:%s/,/\t/g

:   Ex mode command
%   Process command on the entire buffer
s   search and replace command
/,/\t/  search for any commas, and replace with a <tab> character.

g   process command globally

To paste the data from GVim to Excel, you would.

  1. In normal mode, type:  ggVG          Like Ctrl-A on windows
  2. You should now have the entire buffer selected
  3. While still in normal mode, type: "+y       Like Ctrl-C on windows
  4. You should now have the data on the windows clipboard
  5. Switch to Excel, Ctrl-V to paste the data from the clipboard.
--Chris

Posted at 12:44 PM in VIM | Permalink | Comments (0) | TrackBack

September 10, 2010

VIM: How to center the screen on the current line.

If you would like to center your current VIM windows (screen) without having to reach for the mouse, then type the following VIM commands in normal mode.

zz    (Which should center current line in middle of screen)

zt    (top screen)

zb    (bottom screen)

--Chris

Posted at 11:45 AM in VIM | Permalink | Comments (0) | TrackBack

September 06, 2010

Vim Casts: Short Videos on using VIM

While attending the Lone Star Ruby Conference, someone mentioned a web site called Vim Casts, that shows off how to use Vim text editor.

--Chris

Posted at 12:55 PM in VIM | Permalink | Comments (0) | TrackBack