Created
September 2, 2014 01:18
-
-
Save shunchu/2f716db6a10eba481b71 to your computer and use it in GitHub Desktop.
.vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Use Vim settings, rather then Vi settings (much better!). | |
" This must be first, because it changes other options as a side effect. | |
set nocompatible | |
runtime autoload/pathogen.vim | |
call pathogen#infect() | |
call pathogen#helptags() | |
" EDITOR SETTINGS ======================================================== | |
" ======================================================================== | |
set nocompatible " disable vi-compatibility | |
set nobackup " don't create ~ backups | |
set nowritebackup " not sure... | |
set showcmd " what command are you doing? | |
set ruler " position in file | |
set noerrorbells " doesn't seem to work... see next line | |
set vb t_vb= " REALLY get rid of sounds | |
set background=dark " make sure we can see everything | |
set laststatus=2 " always show statusline | |
set report=0 " always show changes | |
"set list lcs=trail:~ " show trailing spaces as '~' | |
set softtabstop=2 " 'move over' instead of 'insert tab' | |
set shiftwidth=2 " size of 'tab' | |
set tabstop=2 " the actual display value? | |
set expandtab " replace all tabs with spaces | |
set smarttab " i don't know, good for python | |
set autoindent " auto-indent | |
set smartindent " smart indent | |
set foldenable " turn on code folding | |
set showmatch " show matching brackets | |
set incsearch " find-as-you-type | |
set wrapscan " wraparound searching | |
set hlsearch " highlight the search results | |
set history=50 " how many commands to remember | |
set number " line numbers | |
set numberwidth=2 " gutter's minimum size (will expand) | |
set guifont=Monaco:h12:cDEFAULT " does not affect terminal version | |
set backspace=indent,eol,start " makes backspace work normally | |
set wildmode=longest,list " bash-style autocomplete | |
set cursorline " highlight the current line in every window | |
set backupdir=~/tmp,/var/tmp " put the backup files in temp dirs | |
syntax on " syntax highlighting | |
filetype indent plugin on " file type detection | |
" COMMAND MAPPINGS ======================================================= | |
" ======================================================================== | |
" remove the F1-help key | |
map <F1> <Esc> | |
imap <F1> <Esc> | |
" these save a keystroke when flipping between buffers | |
map <C-H> <C-W>h | |
map <C-J> <C-W>j | |
map <C-K> <C-W>k | |
map <C-L> <C-W>l | |
" scrolls on SCREEN lines instead of FILE lines with normal movement keys | |
nmap j gj | |
nmap k gk | |
vmap j gj | |
vmap k gk | |
" properly auto-insert matched block delimiters | |
autocmd Syntax c,cpp,java,php,perl imap { {<CR>}<Esc>O | |
imap ( ()<Esc>i | |
imap [ []<Esc>i | |
inoremap } <c-r>=ClosePair('}')<CR> | |
inoremap ) <c-r>=ClosePair(')')<CR> | |
inoremap ] <c-r>=ClosePair(']')<CR> | |
autocmd Syntax html,xml inoremap < <lt>><ESC>i | inoremap > <c-r>=ClosePair('>')<CR> | |
" NERDTree =============================================================== | |
" ======================================================================== | |
let NERDTreeShowHidden=1 " Show hidden files in NerdTree | |
let g:nerdtree_tabs_open_on_console_startup=1 " To run NERDTreeTabs on console vim startup | |
let g:nerdtree_tabs_open_on_console_startup=1 " Open NERDTree on console vim startup | |
let g:nerdtree_tabs_smart_startup_focus=1 " On startup, focus NERDTree if opening a directory, focus file if opening a file. | |
let g:nerdtree_tabs_open_on_new_tab=1 " Open NERDTree on new tab creation (if NERDTree was globally opened by :NERDTreeTabsToggle) | |
let g:nerdtree_tabs_synchronize_view=1 " Synchronize view of all NERDTree windows (scroll and cursor position) | |
"autopen NERDTree and focus cursor in new document | |
autocmd VimEnter * NERDTree | |
autocmd VimEnter * wincmd p | |
" Close vim if the only window left open is a NERDTree | |
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif | |
map <F2> :NERDTreeToggle<CR> " Give a shortcut key to NERD Tree | |
" HIGHLIGHTS ============================================================= | |
" ======================================================================== | |
" highlight current line | |
:hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white | |
":hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white | |
":nnoremap <Leader>c :set cursorline! cursorcolumn!<CR> | |
" apply highlight only to current window | |
autocmd WinEnter * setlocal cursorline | |
autocmd WinLeave * setlocal nocursorline | |
" highlight after cursor moves | |
:nnoremap <silent> <Leader>l ml:execute 'match Search /\%'.line('.').'l/'<CR> | |
:colorscheme desert | |
" CUSTOM FUNCTIONS ======================================================= | |
" ======================================================================== | |
function ClosePair(char) | |
if getline('.')[col('.')-1] == a:char | |
return "\<Right>" | |
else | |
return a:char | |
endif | |
endf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment