Archive for the ‘vi’ Category

VIM: Converting Tabs to spaces

Friday, March 25th, 2005

Converting tabs to spaces

http://www.vim.org/tips/tip.php?tip_id=12

To insert space characters whenever the tab key is pressed, set the
'expandtab' option:

set expandtab

With this option set, if you want to enter a real tab character use
Ctrl-V key sequence.

To control the number of space characters that will be inserted when
the tab key is pressed, set the 'tabstop' option. For example, to
insert 4 spaces for a tab, use:

set tabstop=4

After the 'expandtab' option is set, all the new tab characters entered
will be changed to spaces. This will not affect the existing tab
characters. To change all the existing tab characters to match the
current tab settings, use

:retab

To change the number of space characters inserted for indentation, use
the 'shiftwidth' option:

set shiftwidth=4

For example, to get the following coding style,
- No tabs in the source file
- All tab characters are 4 space characters

use the following set of options:

set tabstop=4
set shiftwidth=4
set expandtab

Add the above settings to your .vimrc file.

To get more help on these options, use
:help tabstop
:help shiftwidth
:help expandtab

.vimrc options to assist with perl coding

Sunday, January 16th, 2005

Edit the .vimrc file and add the following:





” F2 close current window (commonly used with my F1/F3 functions)

noremap :close

” perl -cw buffer, using a temp file, into a new window

function! PerlCW()

let l:tmpfile1 = tempname()

let l:tmpfile2 = tempname()

execute “normal:w!” . l:tmpfile1 . “\

execute “normal:! perl -cw “.l:tmpfile1.” \> “.l:tmpfile2.” 2\>\&1

+ \

execute “normal:new\

execute “normal:edit ” . l:tmpfile2 . “\

endfunction

” perl buffer, using a temp file, into a new window

function! PerlOutput()

let l:tmpfile1 = tempname()

let l:tmpfile2 = tempname()

execute “normal:w!” . l:tmpfile1 . “\

execute “normal:! perl “.l:tmpfile1.” \> “.l:tmpfile2.” 2\>\&1 \
+R>”

execute “normal:new\

execute “normal:edit ” . l:tmpfile2 . “\

endfunction

” Settings for editing perl source (plus bind the above two functions)

function! MyPerlSettings()

if !did_filetype()

set filetype=perl

endif

set textwidth=78

set expandtab

set tabstop=4

set shiftwidth=4

set cindent

set comments=:#

set formatoptions=croql

set keywordprg=man\ -S\ 3

noremap :call PerlCW()

noremap :call PerlOutput()

endfunction

if has(“eval”)

augroup SetEditOpts

au!

autocmd FileType perl :call MyPerlSettings()

augroup END

endif

endif

VIM option file

Sunday, January 16th, 2005

Setting VIM options:

http://babbage.cs.qc.edu/courses/cs701/Handouts/using_vim.html



The installation program normally puts a file named .vimrc in your home directory. On Windows, the file will be named _vimrc, and will be in the directory where Vim was installed. For example, when I installed version 6.1, it was placed in D:\Utils\Vim\vim61, and the _vimrc file was put in D:\Utils\Vim. Also, the Windows environment variable, VIM, was set to D:\Utils\Vim.

The standard .vimrc file supplied with the Vim distribution is not quite correct for use in this course. You need to set the tab width to something small, you must set the option to replace tabs with spaces, and you need to tell vim to wrap lines longer than 72 characters.

I also have some keyboard shortcuts that I like to use, mostly so I can enter certain commands while I am in insert mode. Here are links to two .vimrc files, one for Windows and one for Unix that you may use as a model for your own. Feel free to modify them as you wish, but be sure not to change the expandtab and tw options!

Other example .vimrc files:

http://tabo.aurealsys.com/code/vimrc.html

Excellent page for explanation of some .vimrc options

http://www.stripey.com/vim/

Turn that irritating beep off: set visualbell