mdelatorre

Vim configuration file

May 24th, 2012 (edited)
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 9.57 KB | None | 0 0
  1. " Function that returns the type of system. You need to
  2. " change this to the correct type: linux, mac, windows
  3. fun! MySys()
  4.     return 'mac'
  5. endfun
  6.  
  7. " Pathogen plugin configuration
  8. "call pathogen#runtime_append_all_bundles()
  9.  
  10. " Makes Vim not compatible with vi
  11. set nocompatible
  12.  
  13. " No lines are checked for set commands. Prevent security exploits.
  14. set modelines=0
  15.  
  16. " Sets how many lines of history Vim has to remember
  17. set history=300
  18.  
  19. " Enable filetype plugin and indent for specific file types
  20. filetype plugin on
  21. filetype indent on
  22.  
  23. " Auto read a file if it is changed from the outside
  24. set autoread
  25.  
  26. " Set numbers for lines
  27. set number
  28.  
  29. " Number of spaces that a <Tab> in the file counts for.
  30. set tabstop=4
  31.  
  32. " Number of spaces to use for each step of (auto)indent.
  33. set shiftwidth=4
  34.  
  35. " Number of spaces that a <Tab> counts for while performing
  36. " editing operations, like inserting a <Tab> or using <BS>.
  37. set softtabstop=4
  38.  
  39. " Use the appropriate number of spaces to insert a <Tab>.
  40. " If linecharstring:tab is used tab marks will not be shown
  41. " because they have been converted into spaces.
  42. set expandtab
  43.  
  44. " List mode: Show tabs as CTRL-I is displayed, display $ after
  45. " end of line.  Useful to see the difference between tabs and
  46. " spaces and for trailing blanks.
  47. set list
  48.  
  49. " Strings to use in 'list' mode and for the :list command.  
  50. " It is a comma separated list of string settings.
  51. " tab:xy - Two chars to be used to show a tab. First used one
  52. "          second is repeated to fill the space of the tab
  53. " eol:c - Char to show at the end of each line
  54. set listchars=tab:»\ ,eol:
  55.  
  56. " Sets the character enconding to Unicode UTF8
  57. set encoding=utf-8
  58.  
  59. if has("gui_running")
  60.     set mouse=a             " enable the mouse
  61.     set guioptions-=T       " remove the toolbar
  62.     set t_Co=256            " number of colors
  63.     colorscheme murphy      " set a colorscheme
  64. else
  65.     colorscheme slate
  66. endif
  67.  
  68.  
  69. " Try to set the language to Spanish
  70. try
  71.     language es_ES
  72.     catch
  73. endtry
  74.  
  75. " This gives the end-of-line (<EOL>) formats that will be tried
  76. " when starting to edit a new buffer and when reading a file
  77. " into an existing buffer
  78. set fileformats=unix,dos,mac
  79.  
  80. " Minimal number of screen lines to keep above and below the cursor.
  81. set scrolloff=4
  82.  
  83. " Copy indent from current line when starting a new line (<CR>
  84. " in Insert mode or when using the "o" or "O" command).
  85. set autoindent
  86.  
  87. " Do smart autoindenting when starting a new line.  Works for
  88. " C-like programs, but can also be used for other languages.
  89. set smartindent
  90.  
  91. " Enables automatic C program indenting. When you don't like
  92. " the way 'cindent' works, try the 'smartindent'
  93. set cindent
  94.  
  95. " If in Insert, Replace or Visual mode put a message on
  96. " the last line.
  97. set showmode
  98.  
  99. " Indicates when a line is wrapped by prefixing wrapped lie
  100. " with the choosen character.
  101. :set showbreak=>\
  102.  
  103. " When off a buffer is unloaded when it is |abandon|ed.  
  104. " When on a buffer becomes hidden when it is |abandon|ed.
  105. set hidden
  106.  
  107. " When is on, command-line completion operates in an
  108. " enhanced mode.
  109. set wildmenu
  110.  
  111. " No error beeps on errors
  112. set noerrorbells
  113.  
  114. " Use visual bell instead of beeping.
  115. set novisualbell
  116.  
  117. " No visual flashes on the display
  118. set vb t_vb=
  119.  
  120. " Completion mode that is used for the character specified with
  121. " 'wildchar'. It is a comma separated list of up to four parts.
  122. " list:longest - When more than one match, list all matches and
  123. " complete till longest common string.
  124. " set wildmode=list:longest
  125.  
  126. " Highlight the screen line of the cursor with CursorLine
  127. " set cursorline
  128.  
  129. " Indicates a fast terminal connection.  More characters will
  130. " be sent to the screen for redrawing, instead of using
  131. " insert/delete line commands.
  132. set ttyfast
  133.  
  134. " Show the line and column number of the cursor position,
  135. " separated by a comma.
  136. " set ruler
  137.  
  138. " Sets a ruler with a steroid format.
  139. " set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%)
  140.  
  141. "  Show (partial) command in the last line of the screen.
  142. set showcmd
  143.  
  144.  
  145. " The value of this option influences when the last window will
  146. " have a status line:  0: never 1: only if there are at least
  147. " two windows 2: always
  148. if has('statusline')
  149.     set laststatus=2
  150.  
  151. " Broken down into easily includeable segments
  152. set statusline=%<%f\                      " Filename
  153. set statusline+=%w%h%m%r                  " Options
  154. "set statusline+=%{fugitive#statusline()} " Git Hotness
  155. set statusline+=\ [%{&ff}/%Y]             " filetype
  156. set statusline+=\ [%{getcwd()}]           " current dir
  157. set statusline+=\ [A=\%03.3b/H=\%02.2B]   " ASCII / Hex value of char
  158. set statusline+=%=%-14.(%l,%c%V%)\ %p%%   " Right aligned file nav info
  159. endif
  160.  
  161. " Influences the working of <BS>, <Del>, CTRL-W and CTRL-U in
  162. " Insert mode. This is a list of items, separated by commas
  163. set backspace=indent,eol,start
  164.  
  165.  
  166. " Do not redraw while executing macros
  167. set nolazyredraw
  168.  
  169. " Enable highlighting of text depending on filetype
  170. syntax enable
  171.  
  172.  
  173. " Set font according to system
  174. if MySys() == "mac"
  175.     set guifont=Menlo:h14
  176.     set shell=/bin/bash
  177. elseif MySys() == "windows"
  178.       set guifont=Bitstream\ Vera\ Sans\ Mono:h10
  179. elseif MySys() == "linux"
  180.     set guifont=Monospace\ 10
  181.     set shell=/bin/bash
  182. endif
  183.  
  184.  
  185. " COLORS
  186. "
  187. " Highlighting used for eol, extends and precedes
  188. highlight NonText ctermfg=lightgray guifg=lightgray
  189.  
  190. " Highlighting used for nbsp, tab and trail
  191. highlight SpecialKey ctermfg=lightgray guifg=lightgray
  192.  
  193. " Change the <leader> key from the default "\" to "," (comma)
  194. let mapleader = ","
  195. let g:mapleader = ","
  196.  
  197. " MANAGE LONG LINES OF TEXT
  198. "
  199. " Lines longer than the width of the window will wrap and
  200. " displaying continues on the next line
  201. set wrap
  202.  
  203. " Maximum width of text that is being inserted.  A longer line
  204. " will be broken after white space to get this width
  205. set textwidth=79
  206.  
  207. " This is a sequence of letters which describes how automatic
  208. " formatting is to be done.
  209. " q = Allow formatting of comments with "gq".
  210. " r = Auto insert the current comment leader after hitting
  211. "     <Enter> in Insert mode.
  212. " n = When formatting text, recognize numbered lists.
  213. " 1 = Don't break a line after a one-letter word.  It's
  214. "     broken before it instead (if possible).
  215. set formatoptions=qrn1
  216.  
  217. " Comma separated list of screen columns that are highlighted
  218. " with ColorColumn 'hl-ColorColumn'
  219. " NEW in Vim 7.3
  220. " set colorcolumn=85
  221.  
  222.  
  223. " SEARCHING AND MOVING
  224. "
  225. " Ignore case in search patterns.  Also used when searching
  226. " in the tags file.
  227. set ignorecase
  228.  
  229. " Override the 'ignorecase' option if the search pattern
  230. " contains upper case characters.
  231. set smartcase
  232.  
  233. " When on, the ":substitute" flag 'g' is default on.  
  234. " This means that all matches in a line are substituted instead
  235. " of one.  When a 'g' flag is given to a ":substitute" command,
  236. " this will toggle the substitution to one match.
  237. set gdefault
  238.  
  239. " While typing a search command, show where the pattern, as it
  240. " was typed so far, matches.  The matched string is highlighted.
  241. set incsearch
  242.  
  243. " When a bracket is inserted, briefly jump to the matching one.  
  244. " The jump is only done if the match can be seen on the screen.
  245. set showmatch
  246.  
  247. " When there is a previous search pattern, highlight all
  248. " its matches.
  249. set hlsearch
  250.  
  251. " MAPPINGS
  252. "
  253. " Insert a character in normal mode in the current char position
  254. :nnoremap s :exec "normal i".nr2char(getchar())."\e"<cr>
  255.  
  256. " Insert a character in normal mode in the next char  position
  257. :nnoremap S :exec "normal a".nr2char(getchar())."\e"<cr>
  258.  
  259. " Fix Vim’s horribly broken default regex “handling” by
  260. " automatically inserting a \v before any string you search for.
  261. " This makes Vim regex work like Perl/Python regex formatting.
  262. nnoremap / /\v
  263. vnoremap / /\v
  264.  
  265. " Map the <tab> key to the "%" key to make the <tab> key match
  266. " bracket pairs. Which makes a lot easier to move in source code.
  267. nnoremap <tab> %
  268. noremap <tab> %
  269.  
  270. " This mapping makes it easy to clear the highlighting of a
  271. " previous search
  272. noremap <leader><space> :noh<cr>
  273.  
  274. " Remap the F1 key to ESC. This will avoid getting the help
  275. " when trying aiming for escape.
  276. inoremap <F1> <ESC>
  277. nnoremap <F1> <ESC>
  278. vnoremap <F1> <ESC>
  279.  
  280. " Remap the ';' key to do the same thing as the ':' key.
  281. " Will save one less key to type.
  282. nnoremap ; :
  283.  
  284. " Save the file on losing focus
  285. autocmd FocusLost * :wa
  286.  
  287. " Source changes to vimrc immediately
  288. autocmd BufWritePost ~/.vimrc :source ~/.vimrc
  289.  
  290. " Add file extensions so they are handled with the
  291. " correct filetype
  292. autocmd BufRead,BufNewFile *.module set filetype=php
  293. autocmd BufRead,BufNewFile *.install set filetype=php
  294. autocmd BufRead,BufNewFile *.inc set filetype=php
  295.  
  296. " Activate code completion for a programming language.
  297. autocmd FileType php set omnifunc=phpcomplete#CompletePHP
  298.  
  299. " LEADER COMMANDS
  300. "
  301. " Strip all trailing whitespaces on the current file
  302. nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<cr>
  303.  
  304. " Fold tag function to fold a section of text that is
  305. " between a pair of HTML tags
  306. nnoremap <leader>ft Vatzf
  307.  
  308. " Re-hardwrap paragraphs of text.
  309. nnoremap <leader>q gqip
  310.  
  311. " Reselect the text that was just pasted so you can
  312. " perform commands (like indentation) on it
  313. nnoremap <leader>v V`]
  314.  
  315. " Open your ˜/.vimrc file in a vertically split window so
  316. " you can add new settings on the fly
  317. nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
  318.  
  319. " Fast save a file
  320. nnoremap <leader>w :w!<cr>
  321.  
  322. " WINDOW MAPPINGS
  323. "
  324. " Mapping to open a new vertical split and switch
  325. " over to it.
  326. nnoremap <leader>w <C-w>v<C-w>l
  327.  
  328. " Mappings to facilitate moving around your splits.
  329. nnoremap <C-h> <C-w>h
  330. nnoremap <C-j> <C-w>j
  331. nnoremap <C-k> <C-w>k
  332. nnoremap <C-l> <C-w>l
Add Comment
Please, Sign In to add comment