1 syntax on                       " turns syntax highlighting on
  2 colorscheme default             " defines the color scheme of the syntax highlighting
  3 
  4 set nocompatible                " (cp) use Vim defaults (much better)
  5 set ruler                       " (ru) show the cursor position at all times
  6 set showcmd                     " (sc) display an incomplete command in the lower right
  7 set history=50                  " (hi) keep 50 lines of command history
  8 set number                      " (nu) show line numbers
  9 set showmatch                   " (sm) briefly jump to matching bracket when inserting one
 10 set autoindent                  " (ai) turn on auto-indenting (great for programers)
 11 set copyindent                  " (ci) when auto-indenting, use the indenting format of the previous line
 12 set tabstop=4                   " (ts) width (in spaces) that a <tab> is displayed as
 13 set shiftwidth=4                " (sw) width (in spaces) used in each step of autoindent (aswell as << and >>)
 14 "set smarttab                   " (sta) 'shiftwidth' used in front of a line, but 'tabstop' used otherwise
 15 set textwidth=80                " (tw) number of columns before an automatic line break is inserted (see formatoptions)
 16 set formatoptions=croq          " (fo) influences how vim automatically formats text
 17 set backspace=indent,eol,start  " (bs) allows backspacing beyond starting point of insert mode, indents and line breaks
 18 set nrformats+=alpha            " (nf) adds alpha chars to list that gets incremented/decremented with ^A/^X
 19 set listchars+=tab:>-           " (lcs) strings used in 'list' mode to show hidden characters (default=eol:$)
 20 set listchars+=trail:-
 21 set winminheight=0              " (wmh) the minimal height of the window when it's not the current window
 22 
 23 "set nowrap                     " allows text to continue off the window (need horizontal scrolling)
 24 set linebreak                   " (lbr) wrap long lines at a space instead of in the middle of a word
 25 set sidescroll=5                " (ss) the minimal number of columns to scroll horizontally
 26 set listchars+=precedes:<       " (lcs) when 'nowrap', character to indicate that line continues off the page
 27 set listchars+=extends:>
 28 
 29 set wrapscan                    " (ws) allows search to wrap to top of document when the bottom has been hit
 30 set incsearch                   " (is) highlights what you are searching for as you type
 31 set hlsearch                    " (hls) highlights all instances of the last searched string
 32 set ignorecase                  " (ic) ignores case in search patterns
 33 set smartcase                   " (scs) don't ignore case when the search pattern has uppercase
 34 set infercase                   " (inf) during keyword completion, fix case of new word (when ignore case is on)
 35 
 36 set foldcolumn=6                " (fdc) width of fold column (to see where folds are)
 37 set foldmethod=indent           " (fdm) creates a fold for every level of indentation
 38 set foldlevel=99                " (fdl) when file is opened, don't close any folds
 39 set foldenable                  " (fen) enables or disables folding
 40 
 41 "set backup                     " (bk) will create a backup before overwriting a file
 42 "set backupext=.bkup            " (bex) defines the extension used in a backup file (default is '~')
 43 
 44 let html_use_css = 1            " the ':%TOhtml' command generates html without <font> tags
 45 
 46 
 47 " File Specific Settings
 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 "au FileType xhtml,html,htm,php,xml setlocal expandtab      " (et) expand tabs to spaces (use :retab to redo entire file)
 53 au FileType xhtml,html,htm,php,xml setlocal softtabstop=2   " (sts) makes spaces feel like tabs (like deleting)
 54 
 55 au FileType c,h,java,js setlocal mps+==:;                   " allow the match pairs operation (%) to work with '=' and ';'
 56 
 57 au FileType c,h setlocal cindent                            " enable the intelligent cindent (cin) feature for the following files
 58 au FileType java,js setlocal smartindent                    " enable the smartindenting (si) feature for the following files
 59 
 60 au FileType txt setlocal fo+=tn
 61 
 62 " before writing to any file, this function call will remove any extra white space at the end of a line
 63 "au! BufWrite,FileWritePre * call RemoveWhiteSpace()
 64 
 65 
 66 
 67 
 68 
 69 " Abbreviations
 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" &ldquo;&rdquo;<left><left><left><left><left><left>
 78 abbreviate r" &rdquo;
 79 abbreviate l' &lsquo;
 80 abbreviate r' &rsquo;
 81 abbreviate "" &quot;&quot;<left><left><left><left><left>
 82 
 83 abbreviate <? <?php?><left><left>
 84 
 85 
 86 
 87 
 88 " Miscellaneous Settings
 89 " ------------------------------------------------------------
 90 
 91 " (dict) dictionary used for keyword completion
 92 " to use: while in insertion mode and in the middle of a word, type <ctrl-n> and <ctrl-p>
 93 set dictionary-=/usr/share/dict/words dictionary+=/usr/share/dict/words
 94 set complete-=k complete+=k
 95 
 96 " (tsr) thesaurus used for keyword completion
 97 " to use: while in insertion mode and at the BEGINNING of a word, type <ctrl-x> then <ctrl-n>
 98 "set thesaurus-=/usr/share/dict/mobythes.aur thesaurus+=/usr/share/dict/mobythes.aur
 99 "set complete-=k complete+=k
100 
101 
102 
103 
104 
105 " Key Mappings
106 " ------------------------------------------------------------
107 
108 " allows moving between split windows much faster and more intuitive
109 map <C-J> <C-W>j<C-W>_
110 map <C-K> <C-W>k<C-W>_
111 
112 " <F2> applies a rot13 dmca-grade encryption scheme to your file
113 map <F2> mzggg?G`z      "(seems to be faster than mzggVGg?`z)
114 
115 " <F3> appends the current date and time after the cursor
116 map  <F3> a<C-R>=strftime("%c")<CR><Esc>
117 imap <F3>  <C-R>=strftime("%c")<CR>
118 
119 " <F6> sorts a paragraph of numbers using the external 'sort' program
120 map <F6> {V}k:!sort<CR>
121 
122 " <F7> toggles hidden characters
123 map  <F7> :set list!<CR>
124 imap <F7> <ESC>:set list!<CR>a
125 
126 " <F9> toggles word wrap
127 map  <F9> :set wrap!<CR>
128 imap <F9> <ESC>:set wrap!<CR>a
129 
130 " <F8> toggles whether the last searched string is highlighted
131 map  <F8> :set hls!<CR>
132 imap <F8> <ESC>:set hls!<CR>a
133 
137 
138 
139 
140 
141 
142 " Functions
143 " ------------------------------------------------------------
144 
145 " Renames param1 tags to be param2 tags
146 function! RenameTag(param1, param2)
147     :%s/<\(\/\?\)a:param1\(\_s*\)/<\1a:param2\2/gci
148 endfunction
149 
150 " Strips the tag defined by the parameter (for html pages)
151 function! StripTag(TagName)
152     :%s/a:TagName/hello/gci
153     ":% s/<[^>]\+>//gci
154 endfunction
155 
156 " Reverses all the lines in the file (top to bottom)
157 function! ReverseLines()
158     :g/^/m0
159 endfunction
160 
161 " Removes the ^M character from the end of every line
162 function! RemoveM()
163     :%s/^M$//g
164 endfunction
165 
166 " Replaces the ^M character with a carraige return native to the system
167 function! ReplaceM()
168     :%s/^M/\r/g
169 endfunction
170 
171 " Removes superfluous white space from the end of a line
172 function! RemoveWhiteSpace()
173     :%s/\s*$//g
174     :'^
175     "`.
176 endfunction
177 
178 
179 
180 
181 
182 " Command Reference
183 " ------------------------------------------------------------
184 
185 " *                     - searches for word under cursor
186 " gd                    - finds definition of variable/function under cursor
187 " ga                    - prints the ascii value of character under cursor
188 " gf                    - opens file under the cursor (in split view)
189 " gi                    - goes to insert mode in the same spot as you last inserted
190 " ~                     - changes case of character
191 " :r !<cmd>             - reads the output of the shell <cmd> into the file
192 " :% s/hello/A/gc       - typical search and replace command
193 
194 " :% !tidy              - runs the code through the 'tidy' program
195 
196 " :runtime! syntax/2html.vim
197 " :10,40TOhtml
198 
199 " command reference ->  " za : fold toggle  toggles between a fold being opened and closed (zA does it recursively)
200 "                       " zc : fold close   close 1 fold under the cursor (zC does it recursively)
201                         " zo : fold open    open 1 fold under the cursor (zO does it recursively)
202                         " zm : fold more    increases foldlevel by 1 (zM opens all folds)
203                         " zr : fold reduce  decreses foldlevel by 1 (zR closes all folds)
204 
205 " :retab                - when expandtab is set, replace all tabs in the file with the # of spaces defined in 'shiftwidth'
206 " :retab!               - when expandtab is not set, replace the number of spaces in 'shiftwidth' with a tab
207 if has("cscope")
208     set csprg=/usr/bin/cscope
209     set csto=0
210     set cst
211     set nocsverb
212     " add any database in current directory
213     if filereadable("cscope.out")
214         cs add cscope.out
215     " else add database pointed to by environment
216     elseif $CSCOPE_DB != ""
217         cs add $CSCOPE_DB
218     endif
219     set csverb
220 
221     "   's'   symbol: find all references to the token under cursor
222     "   'g'   global: find global definition(s) of the token under cursor
223     "   'c'   calls:  find all calls to the function name under cursor
224     "   't'   text:   find all instances of the text under cursor
225     "   'e'   egrep:  egrep search for the word under cursor
226     "   'f'   file:   open the filename under cursor
227     "   'i'   includes: find files that include the filename under cursor
228     "   'd'   called: find functions that function under cursor calls
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