What is vimrc
The vimrc file contains optional runtime configuration settings to
initialize Vim when it starts. On Unix,Linux based systems, the file is named .vimrc
,
You can customize Vim by putting suitable commands in your vimrc.
Here is a simple example:
**************************************
Hear are some my favourite command that i use in .vimrc file.
set autoindent " turn on auto-indenting (great for programmer)
set cursorline " show the current cursor postion all the time in all window
set colorcolumn=80 " set long vertical line at column 80
set ruler " show the cursor position all the time
syntax on " turn on syntax
set nu " set line no when you open any file using vim
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/
highlight ExtraWhitespace ctermbg=red guibg=red " highlight extra white space with red color in your vim file
************************************
some more command are below
1 syntax on
2 colorscheme default
3
4 set nocompatible
5 set ruler
6 set showcmd
7 set history=50
8 set number
9 set showmatch
10 set autoindent
11 set copyindent
12 set tabstop=4
13 set shiftwidth=4
14
15 set textwidth=80
16 set formatoptions=croq
17 set backspace=indent,eol,start
18 set nrformats+=alpha
19 set listchars+=tab:>-
20 set listchars+=trail:-
21 set winminheight=0
22
23
24 set linebreak
25 set sidescroll=5
26 set listchars+=precedes:<
27 set listchars+=extends:>
28
29 set wrapscan
30 set incsearch
31 set hlsearch
32 set ignorecase
33 set smartcase
34 set infercase
35
36 set foldcolumn=6
37 set foldmethod=indent
38 set foldlevel=99
39 set foldenable
40
41
42
43
44 let html_use_css = 1
45
46
47
48
49
50 au FileType xhtml,html,htm,php,xml setlocal tabstop=2
51 au FileType xhtml,html,htm,php,xml setlocal shiftwidth=2
52
53 au FileType xhtml,html,htm,php,xml setlocal softtabstop=2
54
55 au FileType c,h,java,js setlocal mps+==:;
56
57 au FileType c,h setlocal cindent
58 au FileType java,js setlocal smartindent
59
60 au FileType txt setlocal fo+=tn
61
62
63
64
65
66
67
68
69
70
71
72 abbreviate #i #include
73 abbreviate #d #define
74
75 abbreviate <a <a href=""></a><left><left><left><left><left>
76 abbreviate <i <img src="" /><left><left><left>
77 abbreviate l" “”<left><left><left><left><left><left>
78 abbreviate r" ”
79 abbreviate l' ‘
80 abbreviate r' ’
81 abbreviate "" ""<left><left><left><left><left>
82
83 abbreviate <? <?php?><left><left>
84
85
86
87
88
89
90
91
92
93 set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
94 set complete-=k complete+=k
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 map <C-J> <C-W>j<C-W>_
110 map <C-K> <C-W>k<C-W>_
111
112
113 map <F2> mzggg?G`z "(seems to be faster than mzggVGg?`z)
114
115
116 map <F3> a<C-R>=strftime("%c")<CR><Esc>
117 imap <F3> <C-R>=strftime("%c")<CR>
118
119
120 map <F6> {V}k:!sort<CR>
121
122
123 map <F7> :set list!<CR>
124 imap <F7> <ESC>:set list!<CR>a
125
126
127 map <F9> :set wrap!<CR>
128 imap <F9> <ESC>:set wrap!<CR>a
129
130
131 map <F8> :set hls!<CR>
132 imap <F8> <ESC>:set hls!<CR>a
133
137
138
139
140
141
142
143
144
145
146 function! RenameTag(param1, param2)
147 :%s/<\(\/\?\)a:param1\(\_s*\)/<\1a:param2\2/gci
148 endfunction
149
150
151 function! StripTag(TagName)
152 :%s/a:TagName/hello/gci
153
154 endfunction
155
156
157 function! ReverseLines()
158 :g/^/m0
159 endfunction
160
161
162 function! RemoveM()
163 :%s/^M$//g
164 endfunction
165
166
167 function! ReplaceM()
168 :%s/^M/\r/g
169 endfunction
170
171
172 function! RemoveWhiteSpace()
173 :%s/\s*$//g
174 :'^
175
176 endfunction
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207 if has("cscope")
208 set csprg=/usr/bin/cscope
209 set csto=0
210 set cst
211 set nocsverb
212
213 if filereadable("cscope.out")
214 cs add cscope.out
215
216 elseif $CSCOPE_DB != ""
217 cs add $CSCOPE_DB
218 endif
219 set csverb
220
221
222
223
224
225
226
227
228
229 nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
230 nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
231 nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
232 nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
233 nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
234 nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
235 nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
236 nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
237 endif
238