Skip to content

Instantly share code, notes, and snippets.

@kconragan
Created January 11, 2012 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kconragan/1597572 to your computer and use it in GitHub Desktop.
Save kconragan/1597572 to your computer and use it in GitHub Desktop.
vimrc
" Map Leader
let mapleader = ","
imap jj <Esc> " map jj to escape
:map <leader>dd "_dd " Map ',dd' to delete line and put in black-hole register
nmap <leader>w :w!<cr> " Shortcut
" Fast editing of the .vimrc
map <leader>e :e! ~/.vimrc<cr>
" Initiate Pathogen
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vimrc
" Visuals ********************************************************************
colorscheme solarized " Color scheme
set background=dark
set title "Set window title
set scrolloff=5 "Number of lines visible above/below cursor
set sidescrolloff=2
set ruler "Display current position of cursor
set cursorline "Highlight current line
set nu "Line Numbers"
set numberwidth=4 "Gutter width for line numbers
set guifont=DroidSansMonoDotted:h13
set shortmess=atI "Abbreviate status messages
set cmdheight=2 "The commandbar height
" Miscelaneous Settings **************************************************************
set hidden
set showmatch "show matching brackets/parenthesis"
nnoremap ' `
nnoremap ` '
set history=1000 "Remember 100 lines of history
set undolevels=1000 "Many levels of undo
set wildignore=*.pyc
set wildmenu "Command-line completion
set visualbell "Turn off audible bell
set autoread "Automatically read a file changed from outside Vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile
" Tabs & Line Spacing *********************************************************
set nowrap "Wrap long lines"
set autoindent "Indent at the same level of the previous line"
set expandtab "Use soft tabs"
set shiftwidth=2 "Tab width"
set softtabstop=2 "Tab width"
" Searching *******************************************************************
set incsearch "find as you type"
set ignorecase "case insensitive search"
set smartcase "case sensitive search when UC present"
set hlsearch "Highlight search terms
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR> " Clear searches with the space key
noremap <F4> :set hlsearch! hlsearch?<CR> " Toggle search highlighting (but don't clear)
" Invisible characters *********************************************************
set listchars=trail:.,tab:>-,eol:$
set nolist
:noremap <Leader>i :set list!<CR> " Toggle invisible chars
:nnoremap <silent> <Leader>ii :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" Commonly typed patterns ******************************************
imap < <><Left>
imap strj ${JSON.stringify()}<Left><Left>
imap ascript <acre:script></acre:script><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
imap ablock <acre:block def="foo()"></acre:block><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
imap $$ $("");<Left><Left><Left>
imap cll console.log();<Left><Left>
" Insert New Line *************************************************************
map <S-Enter> O<ESC> " awesome, inserts new line without going into insert mode
map <Enter> o<ESC>
runtime macros/matchit.vim
" Intuitive backspacing in insert mode ***************************************
set backspace=indent,eol,start
" Syntax Highlight ***********************************************************
" File-type highlighting and configuration.
" Run :filetype (without args) to see what you may have
" to turn on yourself, or just set them all to be sure.
syntax on
filetype on
filetype plugin on
filetype indent on
set listchars=tab:>-,trail:·,eol:$
nmap <silent> <leader>s :set nolist!<CR>
au BufRead,BufNewFile *.less setfiletype css
au BufRead,BufNewFile *.mjt setfiletype html
au BufRead,BufNewFile *.page setfiletype html
au BufRead,BufNewFile *.template setfiletype html
au BufRead,BufNewFile *.sjs setfiletype javascript
au BufRead,BufNewFile *.controller setfiletype javascript
au BufRead,BufNewFile *.ajax set ft javascript
au! BufRead,BufNewFile *.json set filetype=json foldmethod=syntax
" Supertab {
" let g:SuperTabDefaultCompletionType = "context"
" let g:SuperTabContextDefaultCompletionType = "<c-x><c-o>"
" }
au FileType html,xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vim
" Omni Completion *************************************************************
autocmd FileType html :set omnifunc=htmlcomplete#CompleteTags
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
" Sessions ********************************************************************
" Sets what is saved when you save a session
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
"Use TAB to complete when typing words, else inserts TABs as usual.
"Uses dictionary and source files to find matching words to complete.
"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
function! Tab_Or_Complete()
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endif
endfunction
":inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
""let g:snips_trigger_key_backwards='<c-R>'
" Shortcuts for easily opening/switching between files ***********************
" This automatically changes you to current working directory
" and provides options for new buffer, split, tabs, etc.
" Open in new buffer
map <leader>ew :e <C-R>=expand("%:p:h") . "/" <CR>
" Open in split pane
map <leader>es :sp <C-R>=expand("%:p:h") . "/" <CR>
" Open in vertically-split pane
map <leader>ev :vsp <C-R>=expand("%:p:h") . "/" <CR>
" Open in new tab
map <leader>et :tabe <C-R>=expand("%:p:h") . "/" <CR>
"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
" map Ctrl-A, Ctrl-E, and Ctrl-K in *all* modes. map! makes the mapping work in
" insert and commandline modes too.
map <C-A> <Home>
map <C-E> <End>
map! <C-A> <Home>
map! <C-E> <End>
"Delete trailing white space, useful for Python ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
" Informative status line
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [LINE=%04l/%L]\ [COL=%04v]\ [%p%%]
set laststatus=2
map <Leader>f :NERDTreeToggle<CR> ",f toggles NERDTree
iab sss ${_(''<Left>
iab vvv $("");<Left><Left><Left>
iab ccll console.log(
command! -nargs=* Wrap set wrap linebreak nolist
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
endif
if has("gui_macvim")
map <Leader>g <Plug>PeepOpen
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment