Archive

Archive for April, 2011

Resizing your vim buffer

April 28th, 2011 No comments

To resize your buffer up and down type the following:

<ctrl-w>- (that's minus)
<ctrl-w>+

To resize your buffer left and right, type the following:

<ctrl-w>< (that's a less than aligator symbol ;p )
<ctrl-w>>

You could make a mapping to do these without pressing the ctrl-w key combo first.
Something like this for the vertical stuff:

map + <c-w>+
map - <c-w>-

You have to put that in your .vimrc file.

Categories: Blog, Vim Related Tags:

How to quickly comment out entire sections of code

April 28th, 2011 No comments

Go to the first line and type the following:

^ to go to the beginning line. (probably want the top too)
Ctrl + Alt + V (to enter block highlight mode)
#j (where # is the number of lines to be commented out) Or just move the cursor manually.
I (capital i)
//
Press the esc key.
They should all be commented out now, with c++ style comments.

Categories: Blog, Vim Related Tags:

Remove trailing whitespace

April 28th, 2011 No comments

Last blog post, I mentioned you could clean up and reformat a file by using :retab.
This doesn’t remove unnecessary trailing whitespace though. To remove trailing whitespace, use the following:

:%s/\s\+$//
Categories: Blog, Vim Related Tags: ,

Quickly convert all tabs to spaces

April 26th, 2011 No comments

Make sure, in your .gvimrc file, that the following are set to your liking:

set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab

Then type the following within vim:

:set expandtab
:retab
Categories: Blog, Vim Related Tags: , ,

A few more vim tips

April 13th, 2011 No comments

retrieves a yanked/deleted entry before the last yanked/deleted entry

"0p - used to paste after yanking
"1p - used to paste after deleting
"2p - used to paste after deleting (2nd from last)

Ex: yank/delete something, then yank/delete something else. Then type “0p or “1p

Count the number of words in the file of <word>

:%s/<word>//gn
[I (capital i) - Shows the lines containing the word under the cursor
ga - displays the ascii, hex, and octal value of the character under the cursor
g<CTRL-G> - to see technical info about the file you are in
CTRL-i & Ctrl-o : trace movements forward & backwards in the file
Categories: Vim Related Tags: