User Tools

Site Tools


vimrc_outher

This is an old revision of the document!


vimrc
" =============================================================================
" Miller Medeiros .vimrc file
" -----------------------------------------------------------------------------
" heavily inspired by: @factorylabs, @scrooloose, @nvie, @gf3, @bit-theory.
" =============================================================================
 
 
 
" -----------------------------------------------------------------------------
" BEHAVIOR
" -----------------------------------------------------------------------------
 
set nocompatible            " Disable vi compatibility
 
filetype on                 " filetype must be 'on' before setting it 'off'
                            "   otherwise it exits with a bad status and breaks
                            "   git commit.
filetype off                " force reloading *after* pathogen loaded
 
" Use Pathogen to load bundles
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
 
syntax on
filetype plugin indent on   " enable detection, plugins and indent
 
 
" Local dirs (centralize everything)
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
 
 
" Change mapleader (easier to type), at the top since its used everywhere
let mapleader=","
 
set spelllang=en_us         " spell checking
set encoding=utf-8 nobomb   " BOM often causes trouble, UTF-8 is awsum.
" set encoding=latin1 nobomb   " BOM often causes trouble, UTF-8 is awsum.
 
 
" --- performance / buffer ---
set hidden                  " can put buffer to the background without writing
                            "   to disk, will remember history/marks.
set lazyredraw              " don't update the display while executing macros
set ttyfast                 " Send more characters at a given time.
 
 
" --- history / file handling ---
set history=999             " Increase history (default = 20)
set undolevels=999          " Moar undo (default=100)
set autoread                " reload files if changed externally
 
 
" --- backup and swap files ---
" I save all the time, those are annoying and unnecessary...
set nobackup
set nowritebackup
set noswapfile
 
 
" --- search / regexp ---
set gdefault                " RegExp global by default
set magic                   " Enable extended regexes.
set hlsearch                " highlight searches
set incsearch               " show the `best match so far' astyped
set ignorecase smartcase    " make searches case-insensitive, unless they
                            "   contain upper-case letters
 
 
 
" -----------------------------------------------------------------------------
" UI
" -----------------------------------------------------------------------------
 
 
set t_Co=256                " 256 colors terminal
 
let g:molokai_original=0
colorscheme molokai
 
 
" --- UI settings ---
 
 
if has('gui_running')
    "set guifont=Menlo:h13
    set gfn:Monaco:h13
    set transp=0
 
    " toolbar and scrollbars
    set guioptions-=T       " remove toolbar
    set guioptions+=L       " left scroll bar
    set guioptions+=r       " right scroll bar
    "set guioptions+=b      " bottom scroll bar
    "set guioptions-=h      " only calculate bottom scroll size of current line
    set shortmess=atI           " Don't show the intro message at start and
                                "   truncate msgs (avoid press ENTER msgs).
endif
 
 
set cursorline              " Highlight current line
set laststatus=2            " Always show status line
set number                  " Enable line numbers.
set numberwidth=5           " width of numbers line (default on gvim is 4)
set report=0                " Show all changes.
set showmode                " Show the current mode.
set showcmd                 " show partial command on last line of screen.
set showmatch               " show matching parenthesis
set splitbelow splitright   " how to split new windows.
set title                   " Show the filename in the window title bar.
 
set scrolloff=5             " Start scrolling n lines before horizontal
                            "   border of window.
set sidescrolloff=7         " Start scrolling n chars before end of screen.
set sidescroll=1            " The minimal number of columns to scroll
                            "   horizontally.
 
" add useful stuff to title bar (file name, flags, cwd)
" based on @factorylabs
if has('title') && (has('gui_running') || &title)
    set titlestring=
    set titlestring+=%f
    set titlestring+=%h%m%r%w
    set titlestring+=\ -\ %{v:progname}
    set titlestring+=\ -\ %{substitute(getcwd(),\ $HOME,\ '~',\ '')}
endif
 
 
" --- command completion ---
set wildmenu                " Hitting TAB in command mode will
set wildchar=<TAB>          "   show possible completions.
set wildmode=list:longest
set wildignore+=*.DS_STORE,*.db
 
 
" --- diff ---
set diffopt=filler          " Add vertical spaces to keep right
                            "   and left aligned.
set diffopt+=iwhite         " Ignore whitespace changes.
 
 
" --- folding---
set foldmethod=indent       "fold based on indent
set foldnestmax=3           "deepest fold is 3 levels
set nofoldenable            "don't fold by default
 
 
" --- list chars ---
" list spaces and tabs to avoid trailing spaces and mixed indentation
" see key mapping at the end of file to toggle `list`
set listchars=tab:▹\ ,trail:·,nbsp:⚋
set fillchars=fold:-
set list
 
 
" --- remove sounds effects ---
set noerrorbells
set visualbell
 
 
 
" -----------------------------------------------------------------------------
" KEYS
" -----------------------------------------------------------------------------
 
set backspace=indent,eol,start  " allow backspacing over everything.
set esckeys                     " Allow cursor keys in insert mode.
set nostartofline               " Make j/k respect the columns
"set virtualedit=all            " allow the cursor to go in to 'invalid' places
 
 
 
" -----------------------------------------------------------------------------
" INDENTATION AND TEXT-WRAP
" -----------------------------------------------------------------------------
 
set expandtab                   " Expand tabs to spaces
set autoindent smartindent      " auto/smart indent
set copyindent                  " copy previous indentation on auto indent
set softtabstop=4               " Tab key results in # spaces
set tabstop=4                   " Tab is 4 spaces
set shiftwidth=4                " The # of spaces for indenting.
set smarttab                    " At start of line, <Tab> inserts shift width
                                "   spaces, <Bs> deletes shift width spaces.
 
set wrap                        " wrap lines
set textwidth=79
"set colorcolumn=+1              " Show large lines
set formatoptions=qrn1          " automatic formating.
set formatoptions-=o            " don't start new lines w/ comment leader on
                                "   pressing 'o'
 
set nomodeline                  " don't use modeline (security)
 
set pastetoggle=<leader>p       " paste mode: avoid auto indent, treat chars
                                "   as literal.
 
 
 
" -----------------------------------------------------------------------------
" PLUGINS
" -----------------------------------------------------------------------------
 
" --- NERDTree ----
let NERDTreeIgnore=['.DS_Store']
let NERDTreeShowBookmarks=1         "show bookmarks on startup
let NERDTreeHighlightCursorline=1   "Highlight the selected entry in the tree
map <leader>nt :NERDTreeToggle<CR>
 
 
" --- NERDCommenter ---
 
let NERDSpaceDelims=1               " space around delimiters
let NERDRemoveExtraSpaces=1
 
 
" --- Syntastic : Linting / Error check ---
let g:syntastic_enable_signs=1      " Show sidebar signs.
let g:syntastic_auto_loc_list=2     " don't open location list automatically.
" close/open location list (errors)
noremap <silent><leader>lc :lcl<CR>
noremap <silent><leader>lo :lw<CR>
 
 
" --- autocomplete ---
set infercase
set completeopt=longest,menuone
set omnifunc=syntaxcomplete#Complete
set complete=.,w,b,u,U,t,i,d
" see autocommands at the end for more autocomplete settings
 
 
" --- supertab autocomplete ---
let g:SuperTabMappingForward = '<C-Space>'
let g:SuperTabMappingBackward = '<S-C-Space>'
let g:SuperTabLongestEnhanced = 1
 
 
" --- snipmate ---
let g:snips_trigger_key = '<C-Tab>'
let g:snips_author = 'Miller Medeiros'
 
 
" --- indent-guides ---
let g:indent_guides_guide_size = 1
let g:indent_guides_color_change_percent = 3
 
 
" --- EasyMotion ---
let g:EasyMotion_leader_key = '<Leader>m'
 
 
" --- Command-T ---
let g:CommandTMaxFiles=2000
let g:CommandTMaxHeight=12
map <silent><leader>tb :CommandTBuffer<CR>
 
 
" --- Strip trailing whitespace ---
function! StripWhitespace ()
    let save_cursor = getpos(".")
    let old_query = getreg('/')
    :%s/\s\+$//e
    call setpos('.', save_cursor)
    call setreg('/', old_query)
endfunction
 
" Trailing white space (strip spaces)
noremap <leader>ss :call StripWhitespace()<CR>
 
 
" --- matchit ---
runtime macros/matchit.vim          " enable matchit (better '%' key mapping)
 
 
" --- vim-css-color ---
let g:cssColorVimDoNotMessMyUpdatetime = 1
 
 
" --- Zoomwin ---
nmap <leader>z :ZoomWin<CR>
 
 
" --- LustyJuggler ---
let g:LustyJugglerSuppressRubyWarning = 1  " avoid error if running on terminal
 
 
" --- statline ---
" errors color
hi User3 guifg=#FFFFFF guibg=#FF0000 gui=bold ctermfg=15 ctermbg=1 cterm=bold
let g:statline_fugitive = 1
let g:statline_filename_relative = 1
 
 
" --- toggle indentation mode ---
 
function! ToggleExpandTab()
    if &et
        set noet softtabstop=0
    else
        execute "set et softtabstop=". &tabstop
    endif
endfunction
 
map <silent> <leader>et :call ToggleExpandTab()<CR>
 
 
" --- Show syntax highlighting groups for word under cursor ---
" http://vimcasts.org/episodes/creating-colorschemes-for-vim/
nmap <leader>sh :call <SID>SynStack()<CR>
function! <SID>SynStack()
  if !exists("*synstack")
    return
  endif
  echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
 
 
 
 
" -----------------------------------------------------------------------------
" KEY MAPPINGS
" -----------------------------------------------------------------------------
 
" mapleader set at the top of the file to avoid conflicts
 
 
" --- FIX/IMPROVE DEFAULT BEHAVIOR ---
 
" faster commands
nnoremap <space> :
nnoremap ; :
 
" avoid mistyping commands
command! W w
command! Bd bd
 
" movement by screen line instead of file line (for text wrap)
nnoremap j gj
nnoremap <down> gj
nnoremap k gk
nnoremap <up> gk
 
" automatic esc, really uncommon to type jj,jk
inoremap jj <ESC>
inoremap jk <Esc>
 
" Faster scrolling
nnoremap <C-e> 3<C-e>
nnoremap <C-y> 3<C-y>
 
" Move between splits
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
 
" Move windows around (only works on same row)
map <C-S-Right> <C-w>r
map <C-S-Left> <C-w>R
 
" Bubble single lines, similar to Eclipse (requires unimpaired.vim)
nmap <C-Up> [e
nmap <C-Down> ]e
 
" Bubble multiple lines, similar to Eclipse (requires unimpaired.vim)
vmap <C-Up> [egv
vmap <C-Down> ]egv
 
" Duplicate lines, similar to Eclipse
map <C-S-Up> YP
map <C-S-Down> YP
 
" 'fix' search regexp to be compatible with Perl format
nnoremap / /\v
vnoremap / /\v
 
" Use the damn hjkl keys
" map <up> <nop>
" map <down> <nop>
" map <left> <nop>
" map <right> <nop>
 
 
" --- COMMON STUFF / HELPERS ---
 
" Toggle show tabs and trailing spaces
nnoremap <leader>c :set nolist!<CR>
 
" Clear the search highlight
map <silent> \ :silent nohlsearch<CR>
 
" text wrap: Hard wrap paragraph text (similar to TextMate Ctrl+Q)
nnoremap <leader>tw gqip
 
" Open file (useful for HTML)
noremap <silent> <leader>o :!open %<CR>
 
" Reformat code
nnoremap <leader>rf gg=G
 
" I use retab too much and it's hard to type
nnoremap <leader>rt :retab!<CR>
 
" Pull word under cursor into LHS of a substitute (find and replace)
nmap <leader>fr :%s#\<<C-r>=expand("<cword>")<CR>\>#
 
" Insert/append a single character
noremap ,, i_<esc>r
noremap ;; a_<esc>r
 
" Visually select the text that was last edited/pasted
nmap <leader>v `[v`]
 
" fast Ack
nnoremap <leader>a :Ack<Space>
nnoremap <leader>aw :Ack<cword><CR>
 
 
" Open current buffer in a new split
map <leader>s <C-w>v<C-w>l
map <leader>i <C-w>s<C-w>j
 
" close window
map <leader>q :clo<CR>
 
" Toggle spelling hints
nmap <silent> <leader>ts :set spell!<CR>
 
" delete buffer but keep window open (requires bufkill.vim)
map <leader>bd :BD<CR>
 
" smarter next/prev buffer (requires bufkill.vim)
map <leader>bn :BF<CR>
map <leader>bp :BB<CR>
 
 
 
" -----------------------------------------------------------------------------
" FILE HANDLING
" -----------------------------------------------------------------------------
 
" borrowed from @bit-theory vimfiles and edited
augroup mm_buf_cmds
    " clear commands before resetting
    autocmd!
 
    " when vimrc is edited, reload it
    autocmd bufwritepost .gvimrc source %
    autocmd bufwritepost .vimrc source %
 
    " filetype
    autocmd BufNewFile,BufRead *.json setf json
    autocmd BufNewFile,BufRead *.hx setf haxe
 
    " Enable omnicomplete for supported filetypes
    autocmd FileType * if exists("+completefunc") && &completefunc == "" | setlocal completefunc=syntaxcomplete#Complete | endif
    autocmd FileType * if exists("+omnifunc") && &omnifunc == "" | setlocal omnifunc=syntaxcomplete#Complete | endif
augroup END
vimrc_outher.1753560545.txt.gz · Last modified: by wikiadm