Skip to content

Instantly share code, notes, and snippets.

@haixuanc
Last active August 26, 2015 19:36
Show Gist options
  • Save haixuanc/91938885e0d9be49f9f2 to your computer and use it in GitHub Desktop.
Save haixuanc/91938885e0d9be49f9f2 to your computer and use it in GitHub Desktop.
My Vim configuration
" -----------------------------------------------------------------------------
" Plugins
"
" - Solarized color theme
" - Powerline
" - NERDTree
" - NERDCommenter
" - Command-T
" - Vim better whitespace
" - JSHint
" - Vim node
" - Vim javascript
" -----------------------------------------------------------------------------
" Execute pathogen plugin at vim startup
execute pathogen#infect()
filetype plugin indent on
" -----------------------------------------------------------------------------
" Basic text editings
set nocompatible " disables the compatible mode. Runs the vim in enhanced mode.
syntax on " enables syntax hilighting for programming languages
set number " enables line numbering
set mouse=a " allows you to click around the text editor with your mouse to move the cursor
set showmatch " hlights the matching brackets in programming languages
set autoindent " enables auto indent when a new line is inserted
set smartindent " automatically indents lines after opening a bracket in a programming language
set smartcase " ignores case on search unless specified
set foldmethod=manual " lets you hide sections of code
set ignorecase " do case-insensitive search
set colorcolumn=80 " colorize the 80th column
set cursorline " highlight current line
" -----------------------------------------------------------------------------
" Word wrap without line breaks
set wrap
set linebreak
set nolist " list disables linebreak
set textwidth=0
set wrapmargin=0
set formatoptions-=t
" -----------------------------------------------------------------------------
" Tabs
set tabstop=4 " how much Vim gives to a tab
set shiftwidth=4 " assists code formatting
set expandtab " replace tab with spaces
set smarttab " improves tabbing
set backspace=2 " this makes backspace functions like it does in other programs
" -----------------------------------------------------------------------------
" Replace spaces with tabs
set noexpandtab
"%retab! " Retabulate the whole file
" -----------------------------------------------------------------------------
" Highlight search matches
set incsearch
set hlsearch
:nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR> " Press Space to turn off highlighting and clear any message already displayed
set viminfo^=h " Start Vim with no search highlighting
nnoremap <F8> :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR> " Highlight all occurrences
" -----------------------------------------------------------------------------
" Highligh visually selected text
set guioptions+=a
function! MakePattern(text)
let pat = escape(a:text, '\')
let pat = substitute(pat, '\_s\+$', '\\s\\*', '')
let pat = substitute(pat, '^\_s\+', '\\s\\*', '')
let pat = substitute(pat, '\_s\+', '\\_s\\+', 'g')
return '\\V' . escape(pat, '\"')
endfunction
vnoremap <silent> <F8> :<C-U>let @/="<C-R>=MakePattern(@*)<CR>"<CR>:set hls<CR>
" -----------------------------------------------------------------------------
" Disable folding for Markdown syntax highlighting
let g:vim_markdown_folding_disabled=1
" -----------------------------------------------------------------------------
" Use solarized theme
let g:solarized_termcolors=256
let g:solarized_termtrans=1
set background=dark
colorscheme solarized
set guifont=Liberation\ Mono:h12 " set fonts for gui vim
set guioptions=egmrt " hide the gui menubar
" -----------------------------------------------------------------------------
" NERDTree settings
" autocmd vimenter * NERDTree " open NERDTree automatically when vim starts up
autocmd vimenter * if !argc() | NERDTree | endif " open NERDTree automatically when vim starts up if no files were specified
map <C-n> :NERDTreeToggle<CR> " press ctrl+n to open NERDTree manually
set autochdir " change to the current work directory automatically
" cd C:\Users\IBM_ADMIN\DevSpace " change CWD to the specified path
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " close vm if the only window left open is a NERDTree
" -----------------------------------------------------------------------------
" jshint validation
nnoremap <silent><C-j> :JSHint<CR>
inoremap <silent><C-j> <C-O> :JSHint<CR>
vnoremap <silent><C-j> :JSHint<CR>
" -----------------------------------------------------------------------------
" Powerline
set encoding=utf-8
set laststatus=2
let g:Powerline_symbols="fancy"
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
" -----------------------------------------------------------------------------
" Move lines
nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
inoremap <C-j> <Esc>:m .+1<CR>==gi
inoremap <C-k> <Esc>:m .-2<CR>==gi
vnoremap <C-j> :m '>+1<CR>gv=gv
vnoremap <C-k> :m '<-2<CR>gv=gv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment