Created
September 30, 2013 07:00
-
-
Save ffjia/6760203 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
" Functions | |
" ================ | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Make script executable | |
function SetScriptExecutable() | |
" TODO make shell script executable first | |
if synIDattr(synID(1,1,1),"name")=="perlSharpBang" | |
execute ':!(if [ \! -x '.expand("<afile>").' ]; then chmod u+x '.expand("<afile>").'; fi)' | |
"elseif exists("b:is_sh") || exists("b:is_kornshell") || exists("b:is_bash") | |
"elseif synIDattr(synID(1,1,1),"name")=="shComment" | |
"execute ':!(if [ \! -x '.expand("<afile>").' ]; then chmod u+x '.expand("<afile>").'; fi)' | |
endif | |
endfunction | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function ShDetected() | |
map <silent> <F4> :!./%<CR> | |
map <silent> <F5> :set formatoptions-=r<CR>i#!/usr/bin/env bash<CR>#<CR># $Id$<CR><CR># "Reserved" Exit codes<CR># 1 General Error<CR># 2 Misuse of shell built-ins<CR># 126 Command invoked cannot execute<CR># 127 Command not found<CR># 128 Invalid argument to exit<CR># 130 Script terminated by Control-C<CR><CR><CR><CR><CR># __END__<Esc>3k<Esc>:set filetype=sh<CR>:set formatoptions+=r<CR>i | |
" Check syntax with Bash | |
map <F9> :!bash -n %<CR> | |
" Adjust case indent | |
let g:sh_indent_case_labels=1 | |
endfunction | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function PerlDoc(keyword) | |
if a:keyword=~"::" | |
" Module name; | |
execute ':!perldoc '.a:keyword | |
elseif a:keyword=~"^perl" | |
" Perl pod | |
execute ':!perldoc '.a:keyword | |
else | |
" Perl function | |
execute ':!perldoc -f '.a:keyword | |
endif | |
endfunction | |
function PerlTidy() | |
let Sou=expand("%") | |
if !executable("perltidy") | |
echohl WarningMsg | |
echo 'perltidy does not exist or is not executable!' | |
echohl None | |
return | |
else | |
let pos1=line(".") | |
silent execute ":update" | |
silent execute "%!perltidy 2> /dev/null" | |
exe ':'.pos1 | |
echo "File \"".Sou."\" reformatted." | |
endif | |
endfunction | |
function PerlDetected() | |
" Look up in perldoc | |
map <F1> :call PerlDoc(expand("<cword>"))<CR> | |
" Run by perl (autosave first) | |
map <F4> :w<CR>:!perl '%'<CR> | |
map <silent> <F5> :set formatoptions-=r<CR>i#!/usr/bin/env perl<CR>#<CR># $Id$<CR><CR>use strict;<CR>use warnings;<CR>use Smart::Comments '###';<CR><CR><CR><CR><CR>__END__<Esc>3k<Esc>:set filetype=perl<CR>:set formatoptions+=r<CR>i | |
" Running tests against Test::Harness | |
map <F7> :!prove -vl %<CR> | |
" Call perltidy | |
nmap <silent> <F10> <Esc>:call PerlTidy()<CR> | |
" Check syntax with Perl | |
map <F9> :!perl -cw %<CR> | |
set equalprg=perltidy | |
endfunction | |
function! RemoveTrailingSpace() | |
if $VIM_HATE_SPACE_ERRORS != '0' && | |
\(&filetype != 'mail') | |
normal m` | |
silent! :%s/\s\+$//e | |
normal `` | |
endif | |
endfunction | |
" Key Mapping Settings | |
" ==================== | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" F1 -> ? | |
" F2 -> ? | |
" F3 -> Turn off highlighted matches | |
nmap <silent> <F3> :nohlsearch<CR> | |
imap <silent> <F3> <C-O>:nohlsearch<CR> | |
" F4 -> ? | |
" F5 -> ? | |
" F6 -> Insert filename | |
map <F6> i<C-R>=expand("%:t")<Esc><Esc> | |
map! <F6> <C-R>=expand("%:t")<CR> | |
" F7 -> Test | |
" F8 -> Spell Check | |
" F9 -> Syntax check | |
"map <F9> :!php5 -l %<CR> | |
map <F9> :!ruby -c %<CR> | |
" F10 -> Debug/Perltidy | |
" F11 -> Switch on/off paste mode | |
set pastetoggle=<F11> | |
" F12 -> Toggle line number | |
nmap <F12> :set number!<CR> | |
imap <F12> <C-O>:set number!<CR> | |
" http://stackoverflow.com/questions/2147875/what-vim-commands-can-be-used-to-quote-unquote-words | |
" http://vim.wikia.com/wiki/Simple_Macros_to_quote_and_unquote_a_word | |
nnoremap <Leader>q" ciw"<C-r>""<Esc> | |
vnoremap <Leader>q" c"<C-r>""<Esc> | |
nnoremap <Leader>q' ciw'<C-r>"'<Esc> | |
vnoremap <Leader>q' c'<C-r>"'<Esc> | |
map <Leader>qd daW"=substitute(@@,"'\\\|\"","","g")<CR>P | |
" General Settings | |
" ================ | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set nocompatible " be iMproved | |
filetype off " required! | |
set rtp+=~/.vim/bundle/vundle/ | |
call vundle#rc() | |
" let Vundle manage Vundle | |
" required! | |
Bundle 'gmarik/vundle' | |
" My Bundles here: | |
" | |
" original repos on github | |
Bundle 'tpope/vim-fugitive' | |
Bundle 'tpope/vim-rails.git' | |
Bundle 'Lokaltog/vim-powerline' | |
Bundle 'rodjek/vim-puppet' | |
Bundle 'mattn/webapi-vim' | |
Bundle 'mattn/gist-vim' | |
Bundle 'jpalardy/vim-slime' | |
" vim-scripts repos | |
"Bundle 'L9' | |
"Bundle 'FuzzyFinder' | |
Bundle 'The-NERD-tree' | |
Bundle 'Solarized' | |
Bundle 'Tabular' | |
Bundle 'ack.vim' | |
Bundle 'Syntastic' | |
" non github repos | |
Bundle 'git://git.wincent.com/command-t.git' | |
" git repos on your local machine (ie. when working on your own plugin) | |
"Bundle 'file:///Users/gmarik/path/to/plugin' | |
filetype plugin indent on " required! | |
filetype on | |
" | |
" Brief help | |
" :BundleList - list configured bundles | |
" :BundleInstall(!) - install(update) bundles | |
" :BundleSearch(!) foo - search(or refresh cache first) for foo | |
" :BundleClean(!) - confirm(or auto-approve) removal of unused bundles | |
" | |
" see :h vundle for more details or wiki for FAQ | |
" NOTE: comments after Bundle command are not allowed.. | |
set hlsearch | |
set incsearch | |
"colorscheme wombat | |
syntax enable | |
set background=dark | |
colorscheme solarized | |
set expandtab | |
set shiftwidth=4 | |
set softtabstop=4 | |
set vb t_vb= | |
" Only do this part when compiled with support for autocommands | |
if has("autocmd") | |
filetype plugin indent on | |
" Remove trailing spaces | |
autocmd BufWritePre * call RemoveTrailingSpace() | |
" File type related autosetting | |
autocmd FileType perl call PerlDetected() | |
autocmd FileType sh call ShDetected() | |
autocmd BufNewFile,BufRead *.rb set softtabstop=2 | set shiftwidth=2 | |
autocmd FileType ruby set softtabstop=2 | set shiftwidth=2 | |
autocmd FileType puppet set softtabstop=2 | set shiftwidth=2 | |
autocmd BufNewFile,BufRead *.wiki set filetype=confluencewiki | |
"autocmd BufWritePost *.md,*.markdown :silent !cat %:p | curl -X PUT -T - http://localhost:8090/ | |
endif | |
"autocommands:"{{{ | |
" When editing a file, always jump to the last known cursor position. | |
" Don't do it when the position is invalid or when inside an event handler | |
" (happens when dropping a file on gvim). | |
autocmd BufReadPost * | |
\ if line("'\"") > 0 && line("'\"") <= line("$") | | |
\ exe "normal g`\"" | | |
\ endif | |
"}}}e | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" VIM7 specific settings | |
if version >= 700 | |
set cursorline | |
"hi CursorLine cterm=bold ctermfg=yellow ctermbg=DarkBlue | |
"set spell | |
"let spell_auto_type="tex,mail" | |
set spelllang=en_us | |
set spellsuggest=best,15 | |
nmap <silent> <F8> :set spell!<CR> | |
imap <silent> <F8> <C-O>:set spell!<CR> | |
nmap <C-Tab> :tabnext<CR> | |
else | |
set showmatch | |
"set matchtime=15 | |
endif | |
set laststatus=2 | |
set encoding=utf-8 | |
let g:Powerline_symbols='fancy' | |
let g:solarized_termcolors=256 | |
"http://stackoverflow.com/questions/1447334/how-do-you-add-nerdtree-to-your-vimrc | |
autocmd VimEnter * if !argc() | NERDTree | endif | |
let g:syntastic_check_on_open=1 | |
let g:syntastic_mode_map={ 'mode': 'active', | |
\ 'active_filetypes': ['json', 'ruby', 'perl', 'puppet', 'sh', 'yaml'], | |
\ 'passive_filetypes': ['haml'] } | |
let g:syntastic_puppet_puppetlint_args="--no-80chars-check --no-documentation-check" | |
let g:ackprg='ag --nogroup --nocolor --column' | |
" http://stackoverflow.com/questions/10553875/alter-path-in-vim-macvim-so-as-to-find-the-right-ruby-binary | |
set shell=bash\ -i | |
"let g:instant_markdown_slow=1 | |
let g:gist_clip_command = 'pbcopy' | |
let g:gist_detect_filetype = 1 | |
let g:gist_open_browser_after_post = 1 | |
let g:slime_target = "tmux" | |
let g:slime_default_config = {"socket_name": "default", "target_pane": "1"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment