Skip to content

Instantly share code, notes, and snippets.

@pepicrft
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save pepicrft/2e230f74f6402d2f923c to your computer and use it in GitHub Desktop.

Select an option

Save pepicrft/2e230f74f6402d2f923c to your computer and use it in GitHub Desktop.
VIM First steps and plugins
########## TOOLS #####################
## VimGolf
Real Vim ninjas count every keystroke - do you?
http://www.vimgolf.com/
#VIM Screencast
http://derekwyatt.org/vim/tutorials/novice/
# Janus: Vim Distribution
https://github.com/carlhuda/janus
# Vimtutor
http://linuxcommand.org/man_pages/vimtutor1.html
########## PLUGINS #####################
# Matchit
http://www.vim.org/scripts/script.php?script_id=39
########## VIMRC #####################
set nocompatible
set number
set ruler
syntax on
" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set list
set listchars=tab:>-,trail:.,extends:>,precedes:<
" Open new split panes to right and bottom
set splitbelow
set splitright
" Don't use Ex mode, use Q for formatting
map Q gq
" Check with jshint
let g:syntastic_check_on_open=1
let g:syntastic_javascript_checkers = ['jshint']
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
set hlsearch
endif
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
" Search and substitute on all lines by default
set gdefault
" Automatically load .vimrc source when saved
autocmd BufWritePost .vimrc source $MYVIMRC
" Clear the search highlights
nnoremap <leader><space> :noh<cr>
" Matching bracket pairs
nnoremap <tab> %
vnoremap <tab> %
" Always use the very magic mode for regex
nnoremap / /\v
vnoremap / /\v
" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc
" CtrlP ignore
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
" Show menu with possible tab competions
set wildmenu
" Status bar
set laststatus=2
" Without setting this, ZoomWin restores windows in a way that causes
" equalalways behavior to be triggered the next time CommandT is used.
" This is likely a bludgeon to solve some other issue, but it works
set noequalalways
set encoding=utf-8
set autoindent
set showmode
set showcmd
" Enable Pathogen.vim for plugins
call pathogen#infect()
" NERDTree configuration
let NERDTreeIgnore=['\.rbc$', '\~$']
map <Leader>n :NERDTreeToggle<CR>
" Command-T configuration
let g:CommandTMaxHeight=20
" ZoomWin configuration
map <Leader><Leader> :ZoomWin<CR>
" CTags
map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
function s:setupMarkup()
call s:setupWrapping()
map <buffer> <Leader>p :Mm <CR>
endfunction
" make and python use real tabs
au FileType make set noexpandtab
au FileType python set noexpandtab
" Thorfile, Rakefile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby
" md, markdown, and mk are markdown and define buffer-local preview
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" load the plugin and indent settings for the detected filetype
filetype plugin indent on
" Strip all trailing whitespace in the current file
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
" Leader-T for CommandT
map <Leader>t :CommandT<CR>
" Leader-F for Ack
map <Leader>f :Ack<space>
map <Leader>j :e app/javascripts/
map <Leader>J :e app/assets/javascripts/
map <Leader>s :e app/assets/stylesheets/
map <Leader>a :e vendor/plugins/teambox_api_v2/app/controllers/api_v2/
" Yank to system clipboard
noremap <Leader>m "*Y
vnoremap <Leader>m "*y
" Use modeline overrides
set modeline
set modelines=10
" Default color scheme
color desert
"Directories for swp files
set backupdir=~/.vim/backup
set directory=~/.vim/backup
" Actually, fuck backups
set nobackup " Real man don't use backups
set nowritebackup
set noswapfile
" Set terminal title to filename
set title
" Include user's local vim config
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
" Pretty 256 colors
set t_Co=256
colorscheme ir_black
" Change JSLint highlight color for errors
hi clear SpellBad
hi SpellBad cterm=bold ctermfg=red
set statusline+=%{exists('g:loaded_fugitive')?fugitive#statusline():''}
" Enable mouse
set mouse=a
" Highlighting for non-text elements
highlight SpecialKey ctermfg=235
" Unimpaired configuration
" Bubble single lines
nmap <Up> [e
nmap <Down> ]e
" Bubble multiple lines
vmap <Up> [egv
vmap <Down> ]egv
" Indent lines
vmap <Left> <
nmap <Left> <<
nmap <Right> >>
vmap <Right> >
" Map ctrl-movement keys to window switching
map <C-k> <C-w><Up>
map <C-j> <C-w><Down>
map <C-l> <C-w><Right>
map <C-h> <C-w><Left>
" Delete without saving it to the registry. (Uses black hole registry)
noremap x "_x
vnoremap x "_x
" this is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
vnoremap p "_dp
" Copy to system clipboard
" http://stackoverflow.com/questions/54255/in-vim-is-there-a-way-to-delete-without-putting-text-in-the-register
noremap <Leader>y "*y
noremap <Leader>Y "*Y
vnoremap <Leader>y "*y
vnoremap <Leader>Y "*Y
" Paste from system clipboard
noremap <Leader>p "*p
noremap <Leader>P "*P
vnoremap <Leader>p "*p
vnoremap <Leader>P "*P
" Leader v to paste from system
noremap <Leader>v "+P`]
" Create a Gist for selection
noremap <Leader>g :'<,'>Gist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment