|
Customising vi for for programming in C
|
| Author |
Message |
dipakzope
LG Baby

Posts: 2
Group: Registered
Joined: Feb 2008
Status:
Offline
Reputation: 0
Thank 0
1 was given thank in 1 posts
|
Customising vi for for programming in C
You can customise your vi editor by modifying .vimrc file in your home directory.
the sample .vimrc file looks like this (below.) You can easily modify this file as you want.
set cindent
set tabstop=4
set nowrap
map <S-F1> :map<CR>
map <F2> :w!<CR>
map <S-F2> :wqa!<CR>
map <F3> :q<CR>
map <S-F3> :qa!<CR>
map <F4> :%s/<C-R>=expand("<cword>")<CR>/<C-R>=expand("<cword>")<CR>/cg<Left><Left><Left>
map <S-F4> :cope<CR><C-w>w:grep <C-R>=expand("<cword>")<CR> *<Left><Left>
map <F6> <C-Y>
map <F7> <C-E>
map <S-F6> :tprevious<CR>
map <S-F7> :tnext<CR>
map <S-F5> <<
map <S-F8> >>
map <F5> :cprevious<CR>
map <F8> :cnext<CR>
map <S-F11> :cnewer<CR>
map <S-F12> :colder<CR>
map <F9> :set number<CR>
map <S-F9> :set nonumber<CR>
map <F10> :set wrap<CR>
map <S-F10> :set nowrap<CR>
"map <F11> :call SetMyCTagsPath()<CR>
"map <S-F11> :call UnsetMyCTagsPath()<CR>
map <F11> <C-w>w
map <F12> <C-G>
[Please visit again to see conditional mapping and writing functions in .vimrc file.]
This post was last modified: 02-28-2008 02:56 PM by dipakzope.
|
|
| 02-28-2008 02:52 PM |
|
|
Thanks given by |
anant (02-28-2008 08:55 PM) |
| Rate Post | |
anant
Administrator
      
Posts: 42
Group: Administrators
Joined: Jan 2008
Status:
Offline
Reputation: 0
Thank 1
0 was given thank in 0 posts
|
RE: Customising vi for for programming in C
Thanks for the wonderful trick buddy, but can you please explain the function of each line
like what each line in vimrc do for the user.
DoNt LeArN tO hAcK, HaCk To LeArN
http://anantshri.com
|
|
| 02-28-2008 08:55 PM |
|
|
Thanks given by |
|
| Rate Post | |
dipakzope
LG Baby

Posts: 2
Group: Registered
Joined: Feb 2008
Status:
Offline
Reputation: 0
Thank 0
1 was given thank in 1 posts
|
RE: Customising vi for for programming in C
Sure..!
I would like to do that, but instead of explaining meaning of each and every line, a lazy person like me ;-) would suggest to refer vi help for the commands which are not explained here.... vi have made it simple for you - start vi editor, go to command line by pressing ':', type 'help' followed by the command.
here are the meaning of few lines which you may find difficult to get help for..
please have a look at this line:
map <F4> :%s/<C-R>=expand("<cword>")<CR>/<C-R>=expand("<cword>")<CR>/cg<Left><Left><Left>
words and there meanings are as follows:
map maps the key (2nd parameter) with the command (rest mesh)
<F4> the F4 key on the keyboard
: command starts here. ': means go to command line
% entire file
s search the pattern after first '/' and replace with one after 2nd '/'
<C-R> equivalent to pressing cntrl+R. means "insert the contents of"
expand expands wildcards or special keywords to a string.
<cword> word under the cursor.
<CR> carrige return
c confirm before substitution
g make all changes on current line.
<Left> left arrow key from the keyboard.
Now lets look at this:
map <S-F4> :cope<CR><C-w>w:grep <C-R>=expand("<cword>")<CR> *<Left><Left>
:cope open cope window (to see current list of search results / errors)
grep similer to grep command
lines starting with a duble cote ' " ' is considered as a comment. (leading white spaces are ignored.)
for example:
"map <F11> :call SetMyCTagsPath()<CR>
anyway, here SetMyCTagsPath() is a user defined function. And hey, you got the way to call functions.. (using call command ofcourse)
This post was last modified: 02-29-2008 02:58 PM by dipakzope.
|
|
| 02-29-2008 02:46 PM |
|
|
Thanks given by |
|
| Rate Post | |