Skip to content

Instantly share code, notes, and snippets.

@xaptronic
Created April 24, 2012 03:42
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 xaptronic/2476224 to your computer and use it in GitHub Desktop.
Save xaptronic/2476224 to your computer and use it in GitHub Desktop.
my vimrc file
*.swp
.*.swp
..*.un~
.*.un~
" http://stevelosh.com/blog/2010/09/coming-home-to-vim/#using-the-leader for
" http://stackoverflow.com/questions/164847/what-is-in-your-vimrc
" more awesome options
set nocompatible
let mapleader = ";"
let g:CommandTMaxFiles=50000
let g:indent_guides_guide_size = 1
set statusline=[%{getcwd()}]\
set statusline+=%t\
set statusline+=%y
set statusline+=[%{strlen(&fenc)?&fenc:'none'},%{&ff}]
set statusline+=%h
set statusline+=%#identifier#
set statusline+=%m
set statusline+=%*
set statusline+=%r
set statusline+=%=
set statusline+=%c,%l/%L\ %P
set statusline+=\ %{StatuslineCurrentHighlight()}
set autoindent
set smartindent
set expandtab
set smarttab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set scrolloff=5
set encoding=utf-8
set showmode
set showcmd
set hidden
set wildmenu
set wildmode=list:longest,full
set novisualbell
if has("cursorline")
set cursorline
endif
set ttyfast
set ruler
set backspace=indent,eol,start
set laststatus=2
" close buffers when closing tabs
set nohidden
if exists("+relativenumber")
set relativenumber
else
set number
endif
"set undofile
set pastetoggle=<F2>
if has("mouse")
set mouse=a
endif
set ignorecase
set smartcase
set incsearch
set showmatch
set hlsearch
set wildignore+=.git
set guifont=Monospace\ 11
set guioptions-=T
set guioptions-=m
"set formatoptions+=or
let g:clipbrdDefaultReg = '+'
highlight MatchParen ctermbg=4
" sudo save
command W w !sudo tee % > /dev/null
" Key mappings
noremap <leader>j :CommandTJump<cr>
noremap tpcode :lcd ~/.tpcode/tp<cr>
noremap taseo :lcd ~/.tpcode/ta-seo<cr>
noremap tripm :lcd ~/.tpcode/tripmix<cr>
noremap <leader>code :lcd ~/.tpcode/
" get into regular search of \v (regex)
nnoremap <leader>/ /\v
vnoremap <leader>/ /\v
" search for selection
vnoremap // y/<C-R>"
" stub a substitution for selection
vnoremap s/ y:s/<C-R>"/
nnoremap <leader>a :Ack
" clear highlighting on search
nnoremap <leader><space> :noh<cr>
" tabbing fun
nnoremap <C-t> :tabnew<cr>
nnoremap <leader>w :tabclose<cr>
nnoremap <leader>W :enew<cr>
nnoremap + <C-w>+
nnoremap - <C-w>-
nnoremap <C-n> <C-w>8<
nnoremap <C-p> <C-w>8>
" insert new line above or below
nnoremap <leader>o o<esc>
nnoremap <leader>O O<esc>
" disable arrow keys and vim like a boss
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" x deletes text by putting it into the blackhole register _
noremap x "_x
noremap X "_X
" cut/copy and paste (read: dont yank on paste)
vnoremap p "_xP
" cut/copy paste from clipboard
vnoremap <leader>y "+y
nnoremap <leader>p "+p
vnoremap <leader>p "+p
nnoremap <leader>P "+P
" text formatting
vnoremap < <gv
vnoremap > >gv
vnoremap <leader>t :Tabularize/
" close all buffers
nnoremap <leader>q :bufdo bd<cr>
nnoremap <leader>c :bd<cr>
" Look hawt
" set t_Co=256
silent! color grb
" silent! colorscheme jellybeans
syntax on
"au BufNewFile,BufRead *.tt setf tt2
au BufNewFile,BufRead *.tt setf tt2html
au BufNewFile,BufRead *.less setf css
"return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
let name = synIDattr(synID(line('.'),col('.'),1),'name')
if name == ''
return ''
else
return '[' . name . ']'
endif
endfunction
" indent guides
"function! ToggleIndentGuidesTabs()
" if exists('b:iguides_tabs')
" setlocal nolist
" let &l:listchars = b:iguides_tabs
" unlet b:iguides_tabs
" else
" let b:iguides_tabs = &l:listchars
" setlocal listchars=tab:┆\ "protect the space
" setlocal list
" endif
"endfunction
" https://gist.github.com/734422
nnoremap <leader>i :call ToggleIndentGuides()<CR>
function! ToggleIndentGuides()
if exists('b:indent_guides')
call matchdelete(b:indent_guides)
unlet b:indent_guides
else
let pos = range(1, &l:textwidth, &l:shiftwidth)
call map(pos, '"\\%" . v:val . "v"')
let pat = '\%(\_^\s*\)\@<=\%(' . join(pos, '\|') . '\)\s'
let b:indent_guides = matchadd('CursorLine', pat)
endif
endfunction
" active indent guides by default
call ToggleIndentGuides()
" Alignment by character
command! -nargs=? -range Align <line1>,<line2>call AlignSection('<args>')
vnoremap <silent> <Leader>= :Align =<CR>
vnoremap <silent> <Leader>: :Align :<CR>
function! AlignSection(regex) range
let extra = 1
let sep = empty(a:regex) ? '=' : a:regex
let maxpos = 0
let section = getline(a:firstline, a:lastline)
for line in section
let pos = match(line, ' *'.sep)
if maxpos < pos
let maxpos = pos
endif
endfor
call map(section, 'AlignLine(v:val, sep, maxpos, extra)')
call setline(a:firstline, section)
endfunction
function! AlignLine(line, sep, maxpos, extra)
let m = matchlist(a:line, '\(.\{-}\) \{-}\('.a:sep.'.*\)')
if empty(m)
return a:line
endif
let spaces = repeat(' ', a:maxpos - strlen(m[1]) + a:extra)
return m[1] . spaces . m[2]
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment