William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

vim .exrc file

vim: .exrc file

I google from web to get this helpful .exrc example and the explanation:

What follows is my .exrc file for various versions of vi, and some more related stuff. I have yet to look through the vim documentation exhasutively to see if there are any more useful options — this is just stuff I have gleaned from random places on the Internet and from friends.

Plain vanilla vi (as on Solaris)
set nu ” show line numbers
set ts=4 ” tabs take up four columns
set sw=4 ” set shiftwidth (>> or <<) to 4 columns set showmatch ” show matches of ()’s, {}’s, and []’s
set showmode ” show what mode (e.g. INSERT) you’re in
set autoindent ” indent to the extent of the previous line

syntax enable ” enables syntax highlighting
set nu ” show line numbers
set ts=4 ” tabs take up four columns
set sw=4 ” set shiftwidth (>> or <<) to 4 columns
set title
” sets title of terminal in menubar to that of file currently being edited
set expandtab ” tabs aren’t really tabs, but many spaces
set softtabstop=4 ” delete four spaces when you delete a “tab”
set ignorecase ” perform case-insensitive searches…
set smartcase ” … unless there are capitalized characters in the search pattern
set mousehide ” hide the mouse when editing
set exrc ” eliminates the possibility of another .exrc getting confused with mine on multi-user systems
set backspace=indent,eol,start “explicitly makes the backspace work when at the beginning of a line
set bg=light “this almost always looks better — take this out or set it to dark if things look funny
set nohlsearch “no annoying search highlighting

” for common typos
command! Q quit
command! W write
command! Wq wq

Vim Python
set autoindent ” indent to the extent of the previous line

Vim C/C++/Java
set cindent ” indenting for C-style languages
set showmatch ” show matches of ()’s, {}’s, and []’s

For Text (Vim 7.0 only)
setlocal spell spelllang=en_us ” English(US) spellcheck on (Vim 7.x only)
set tw=0 wrap linebreak ” don’t split words between lines, only wrap at end of word
“lots of abbreviations (varies depending on the subject material)
ab STIA Science, Technology and International Affairs

How to produce nicely formatted C code in Vim (From p.221 of Learning the vi editor):
set nocp incsearch
set cinoptions=:0,p0,t0
set cinwords=if,else,while,do,for,switch,case
set formatoptions=tcqr
set cindent
syntax on
source ~/.exrc

Options set when vim 6.4/7 starts on my system (Ubuntu Linux):
helplang=en ” language to display help in
ruler ” show row and column in bottom right
ttyfast ” indicates a fast terminal connection
viminfo=’20,”50 ” configuration info
history=50 ” number of : commands and previous search patters to be remembered
scroll=32 ” number of lines to scroll with CRTL-U and CTRL-D commands
ttymouse=xterm2 ” mouse codes
backspace=indent,eol,start “explicitly makes the backspace work when at the beginning of a line
fileencodings=ucs-bom,utf-8,latin1 ” list of character encodings considered when starting to edit a file
printoptions=paper:letter ” controls format and output of printing
runtimepath=~/.vim,/usr/share/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vimcurrent,/usr/share/vim/vimfiles/after,/usr/share/vim/addons/after,~/.vim/after ” list of directories which will be searched for runtime files
suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc ” Files with these suffixes get a lower priority when multiple files match a wildcard.

Cool stuff that I have seen various places but I didn’t find particularly useful (maybe someone else will):
set list “replaces all EOLs and TABs with $ and ^I
“auto-complete of brackets
inoremap [ [] <left>
inoremap ( () <left>
inoremap { {} <left>
inoremap ” “” <left>
inoremap ‘ ” <left>

To see the options vi(m) has enabled, enter :set
To get help with options in Vim, enter :help set or :set all for regular vi
Or just :help for the help contents… Vim has excellent documentation

Besides these, the ‘abbr‘, ‘map‘ sees quite powerful. For example, the following strange codes help me a lot:

abbr _href <a href=""></a>
abbr _img <img src="" border="0" width="" height="" alt="[image]" align="top">
ab get_jquery <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
ab get_bcss <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
ab get_bjs  <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
map ,html5  o<!DOCTYPE html>^M<head>^M  <meta charset="utf-8">^M<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">^M<title></title>^M<meta name="description" content="">^M<meta name="viewport" content="width=device-width">^M<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>^M<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">^M<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>^M
map ,body5 o  <body>^M  <div class="container">^M    <div class="row">^M      <div class="span4">^M</div>^M</div>^M</div>^M</body>^M<script></script>^M</html>^[

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: