Skip to content

Instantly share code, notes, and snippets.

@koirikivi
Created February 17, 2014 12:11
Show Gist options
  • Save koirikivi/9049486 to your computer and use it in GitHub Desktop.
Save koirikivi/9049486 to your computer and use it in GitHub Desktop.
Messy vimrc
" Based on http://www.derekwyatt.org/vim/the-vimrc-file/the-absolute-bare-minimum
" Also lots of other sources and personal experimentation
execute pathogen#infect()
" Forget being compatible with good ol' vi
set nocompatible
" Comment color more readable
hi Comment ctermfg=darkgray
set t_Co=256
set background=dark
"colorscheme desert
color grb256
hi LineNr ctermfg=242 guifg=#3D3D3D guibg=black
hi Comment ctermfg=242 guifg=#3D3D3D guibg=black
" Case insensitive searches
set ignorecase
" ...but not when search pattern contains uppercase characters
set smartcase
" Underline search results
set hlsearch
hi Search term=underline cterm=underline ctermfg=NONE ctermbg=NONE guifg=NONE guibg=NONE
" remember a couple of commands more
set history=500
" No sql maps
let g:omni_sql_no_default_maps = 1
" Tags in .ctags
set tags=./.ctags,.ctags,../.ctags
set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
" Get that filetype stuff happening
filetype on
filetype plugin on
filetype indent on
" Turn on that syntax highlighting
syntax on
" Autocommands, wrapped so not done twice if the rc file is sourced again
if !exists("autocommands_loaded")
let autocommands_loaded = 1
" PEP8: Maximum 79 characters per line for python
autocmd FileType python set textwidth=79
autocmd FileType html set syntax=htmldjango textwidth=0
autocmd FileType htmldjango set textwidth=0
" Execution
autocmd FileType python nmap <leader>x :!python %<cr>
autocmd FileType javascript nmap <leader>x :!node %<cr>
autocmd FileType c nmap <leader>x :!gcc -Wall -Wextra % && ./a.out<cr>
autocmd FileType cpp nmap <leader>x :!g++ -Wall -Wextra % && ./a.out<cr>
autocmd FileType scala nmap <leader>x :!scala %<cr>
autocmd FileType java nmap <leader>x :w<cr>:!javac -Xlint:deprecation % && java %:r<cr>
" Lint
autocmd FileType javascript nmap <leader>,c :!jshint %<cr>
autocmd FileType php nmap <leader>,c :!php -l %<cr>
" Translation
autocmd FileType htmldjango nmap <leader>u viws"i{% trans <esc>lf"a %}<esc>
autocmd FileType htmldjango vmap <leader>u s"i{% trans <esc>lf"a %}<esc>
endif
" Line Numbers
set number
" Allow hidden buffers to exist -- essential
set hidden
" Don't update the display while executing macros
set lazyredraw
" At least let yourself know what mode you're in
set showmode
" Enable enhanced command-line completion. Presumes you have compiled
" with +wildmenu. See :help 'wildmenu'
set wildmenu
" Map shift-tab to unindent (insert mode)
imap <S-Tab> <ESC><<i
" F8 removes unwanted whitespace
nnoremap <silent> <F8> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" Hilight extra whitespace
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
match ExtraWhitespace /\s\+\%#\@<!$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhitespace /\s\+$/
" Hilight current line
set cursorline
" hi CursorLine term=underline cterm=underline ctermbg=234 guibg=#121212
hi CursorLine term=NONE cterm=NONE ctermbg=234 guibg=#121212
" Custom leader commands
let mapleader = ","
" Teemun tabihöskä
nmap <leader>t :tabe %:p:h/
" Sama mutta bufferille
nmap <leader>e :e %:p:h/
" Ja windowille
" Ylemmät globeille
nmap <leader>gt :tabe **/
nmap <leader>ge :e **/
nmap <leader>gw :new **/
" Open django source files quickly
"nmap <leader>dt :tabe ../kaleva-virtualenv/lib/python2.6/site-packages/django/**/
"nmap <leader>dt :tabe venv/lib/python2.7/site-packages/django/**/
nmap <leader>dt :tabe $VIRTUAL_ENV/lib/python*/site-packages/
" Nerdtree localille
nmap <silent> <leader>nd :NERDTree %:p:h<cr>
" Scrolling through buffers?
nmap <leader>b :b <c-i>
" python debugger -- now with IPDB!
nmap <silent> <leader>pdb oimport ipdb; ipdb.set_trace()<esc>
" lame django tempate python debugger
nmap <silent> <leader>ddb o{% load debug_tags %}{% pdb_context %}<esc>
" Let's make it easy to edit this file (mnemonic for the key sequence is
" 'm'odify 'v'imrc)
nmap <silent> <leader>mv :tabe $MYVIMRC<cr>
" And to source this file as well (mnemonic for the key sequence is
" 's'ource 'v'imrc)
nmap <silent> <leader>sv :so $MYVIMRC<cr>
" http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
" Slightly modified
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
echo a:cmdline
let expanded_cmdline = a:cmdline
for part in split(a:cmdline, ' ')
if part[0] =~ '\v[%#<]'
let expanded_part = fnameescape(expand(part))
let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
endif
endfor
vertical botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
"call setline(1, 'You entered: ' . a:cmdline)
"call setline(2, 'Expanded Form: ' .expanded_cmdline)
"call setline(3,substitute(getline(2),'.','=','g'))
execute 'silent $read !'. expanded_cmdline
1d
setlocal nomodifiable
execute 'redraw'
endfunction
func! DeleteLintTmpBufferIfExists()
if bufloaded("/tmp/vimlint")
bdelete /tmp/vimlint
endif
endfunction
" With lint:
nmap <silent> <leader>dolint :call DeleteLintTmpBufferIfExists()<cr>:!echo -e "PEP8:" > /tmp/vimlint<cr>:!pep8 % >> /tmp/vimlint<cr>:!echo -e "\nPyFlakes:" >> /tmp/vimlint<cr>:!pyflakes % >> /tmp/vimlint<cr>:!echo -e "\nPyLint:" >> /tmp/vimlint<cr>:!pylint % -r n -i y \| grep -v "************* Module" >> /tmp/vimlint<cr>
nmap <silent> <leader>ptabopenlint :tabe /tmp/vimlint<cr>
nmap <silent> <leader>pvsplitopenlint ,v:e /tmp/vimlint<cr>
" Without lint:
" nmap <silent> <leader>fl :call DeleteLintTmpBufferIfExists()<cr>:!echo -e "PEP8:" > /tmp/vimlint<cr>:!pep8 % >> /tmp/vimlint<cr>:!echo -e "\nPyFlakes:" >> /tmp/vimlint<cr>:!pyflakes % >> /tmp/vimlint<cr>:tabe /tmp/vimlint<cr>
" Disregard that, always with lint >:D
nmap <silent> <leader>ft ,dolint,ptabopenlint
nmap <silent> <leader>fl ,dolint,pvsplitopenlint
" Python eval
" TODO: change the binding
"nmap <silent> <C-p> :!python %<cr>
" Try to remove ugly flashes on <cr> from supertab
" Incidentally also removes completion by <cr>
let g:SuperTabCrMapping = 0
" Should be compiled with python support on
"let g:SuperTabDefaultCompletionType = "context"
" Clear last search
nnoremap <silent> <leader>c :let @/ = ""<cr>
command! Spacestotabs s/ /<Tab>/g
"""""""""""""""""""""""
" IMBA GIT COMMAND LINE
command! Blame call GitBlame()
function! GitBlame()
call s:RunShellCommand("git blame % -L " . line("."))
setlocal syntax=git
endfunction
command! ShowLine call GitShowLineCommit()
function! GitShowLineCommit()
call s:RunShellCommand("git show `git blame % -L " . line(".") . " | head -1 | awk -F' ' '{print \$1}'`")
setlocal syntax=git
endfunction
command! BlameFile call GitBlameFile()
function! GitBlameFile()
normal ggzt
setlocal scrollbind
syncbind
call s:RunShellCommand("git blame % -L 0")
setlocal syntax=git
setlocal scrollbind
syncbind
endfunction
command! Log call GitLog()
function! GitLog()
call s:RunShellCommand("git log -p %")
setlocal syntax=git
endfunction
command! Status call GitStatus()
function! GitStatus()
call s:RunShellCommand('git status')
setlocal syntax=git
endfunction
command! Diff call GitDiff()
function! GitDiff()
call s:RunShellCommand('git diff %')
setlocal syntax=git
endfunction
command! DiffPrev call DiffPrev()
function! DiffPrev()
call s:RunShellCommand('git log --oneline % | head -n 2 | tail -n 1 ; git diff HEAD^^ %')
setlocal syntax=git
"6/^[+-]
endfunction
" END IMBA GIT COMMAND LINE
"""""""""""""""""""""""""""
" Django template translation tool
nmap <leader>w "yyiw:call Where("<C-r>y")<cr>
" TODO: escaping quotes
vmap <leader>w "yy:call Where("<C-r>y")<cr>
"command! Where call Where()
function! Where(string)
let cmd = 'git grep -ne ' . shellescape(a:string)
call s:RunShellCommand("echo " . cmd . ";" . cmd)
"call s:RunShellCommand(cmd)
endfunction
nmap <leader>l :call OpenTodoTxt()<cr>
function! OpenTodoTxt()
if bufloaded("~/.todo/todo.txt")
b ~/.todo/todo.txt
else
tabe ~/.todo/todo.txt
tabm 0
endif
endfunction
if has("autocmd")
filetype plugin on
autocmd FileType todo set syntax=todo foldmethod=indent
endif
set switchbuf=usetab
command! Todo tabe ~/todo
" Easier up/down moving and scrolling
map § 4j
map ± 4k
"hi Error term=NONE cterm=NONE ctermfg=NONE ctermbg=NONE gui=undercurl guisp=NONE
hi ErrorMsg term=standout cterm=reverse
hi ModeMsg ctermfg=14 ctermbg=0 term=NONE cterm=NONE
" Split movement
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
nmap <leader>v :vsplit<cr><C-w>l
nmap <leader>rs :vertical resize 80<cr>
" Tab movement
nmap { gT
nmap } gt
" Super motionz!
" nmap <silent><Space> /[A-Z0-9_.,;:{}()\[\]`'"\\/]<cr>
" sudo write hack
" http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work
command! Sudow w !sudo tee > /dev/null %
command! GotoNonAscii /[^\x00-\x7F]
command! DeleteNonAscii %s/[^\x00-\x7F]//g
"set mouse=a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment