Skip to content

Instantly share code, notes, and snippets.

@poc7667
Forked from napcs/.vimrc
Last active August 29, 2015 14:22
Show Gist options
  • Save poc7667/ce7116ff54667f8b754c to your computer and use it in GitHub Desktop.
Save poc7667/ce7116ff54667f8b754c to your computer and use it in GitHub Desktop.
" This is the main file that loads up the other configuration files.
if has('win32') || has ('win64')
let $VIMHOME = $HOME."/vimfiles"
else
let $VIMHOME = $HOME."/.vim"
endif
source $VIMHOME/vundle
source $VIMHOME/vimrc_main

My keybindings

Normal mode commands

  • ,<spacebar> switches between the two most recent files
  • ,sp toggles spell check on and off.
  • ,l toggles whitespace character visibility
  • ,g will attempt to launch the program for the current file
  • ,r reloads the Vim configuration
  • F3 switches to the previous tab
  • F4 switches to the next tab
  • F5 toggles highlighted search terms on and off
  • ,x deletes the line without saving it to the clipboard
  • ,o creates blank line below cursor without insert mode
  • ,O creates blank line above cursor without insert mode

Window movement

  • CTRL+j moves down
  • CTRL+k moves up
  • CTRL+h moves left
  • CTRL+l moves right

INSERT mode commands:

  • jj in INSERT mode will exit INSERT mode and save the file
  • jk in INSERT mode exits INSERT mode

Nerdtree (File explorer sidebar)

  • ,d opens and closes the tree
    • press Enter to open the file
    • press i to open the file in a horizontal split
    • press s to open the file in a vertical split
    • press m when on a node to get the menu to add, delete, rename files.

CtrlP Fuzzy finder

  • ,f opens the search window. Type part of the filename to locate it.
    • Press Ctrl-K and Ctrl-j to go up and down the list
    • Press F5 to refresh file list
  • ,b opens search window for buffers only.

NERDCommenter

Use VISUAL mode to select text. Then press:

  • ,cc to comment out selected text
  • ,cu to uncomment selected text

Ragtag

  • Ctrl-x / in insert mode closes the open tag. Press again to close outer tag.

In the following table:

  • ^ is the cursor position
  • <C-x> is Ctrl+x
Text Command result
<p>^ <C-x> / <p></p>^
p^ <C-x> Space <p>^</p>
div^ <C-x> Enter <div>\n^\n</div>
^ <C-x> @ Stylesheet link tag
^ <C-x> $ Script tag
user.name^ <C-x> + <%= user.name %>

Snippets

HTML

  • `html5 generates an html5 skeleton
  • 'html5t` generates a simplified HTML5 skeleton
  • ijs generates script blocks for inline JS
  • image generates image tag with alt
  • csslink generates a link tag for CSS
  • jqueryref generates a call to load jQuery from CDN
  • jslink generates link to call external JS
  • textfield generates label and input type="text"
  • textfieldbr generates label and input type="text" with a <br> between
  • textarea generates label and textarea
  • textareabr generates label and textarea with a <br> between
  • emailfield generates label and input type="email"
  • emailfieldbr generates label and input type="email" with a <br> between
  • select generates label and select and a default <option>
  • selectbr generates label and select with a <br> between, with a default <option> between
  • number generates label and input type="number"
  • numberbr generates label and input type="number" with a <br> between
  • checkbox generates label and input type="checkbox"
  • checkboxbr generates label and input type="checkbox" with a <br> between
  • radio generates label and input type="radio"
  • radiobr generates label and input type="radio" with a <br> between
  • lorem drops in some lorem ipsum text

Grunt

  • gruntfile creates skeleton for Gruntfiles
  • gtask creates skeleton for a task
  • gnpm generates grunt.loadNPMTasks
  • ginitconfig generates the initConfig code skeleton
  • gconfig generates the grunt.config modular style of config
  • gll generates grunt.log.writeln
  • gw generates grunt.warn
  • gcg generates grunt.config.get

JavaScript

  • object generates skeleton for object literal
  • objectkey generates the skeleton for an object as a key
  • anon generates anonymous function
  • listen generates .addEventListener
  • keyval generates a sinple key: value snippet
  • dce is document.createElement
  • dgt is document.getElementsByTagName
  • dgi is 'document.getElementById`
  • 'acisappendChild`
  • fo is a simple for loop`
  • prompt is a prompt box
  • number is the Number function
  • tof is toFixed
  • dw is document.write
  • dw" is document.write("")
  • todo puts in a TODO with datestamp
  • note puts in a NOTE with datestamp
  • fixme puts in a FIXME with datestamp

Ruby

  • todo puts in a TODO with datestamp
  • note puts in a NOTE with datestamp
  • fixme puts in a FIXME with datestamp
# Powershell script to install my configuration for Windows
# You need to install Git so it's available on the command line. Use Chocolatey
# or something else, but ensure it's installed so you can run Git from the command line.
#
# Then download this file and run it in your %HOME% directory
#
# powershell -NoProfile -ExecutionPolicy unrestricted vim.ps1
#
# This is very experimental.
# set up folders
new-item vimfiles -type directory
new-item vimfiles\backup -type directory
new-item vimfiles\bundle -type directory
if (-not (test-path "tmp") ) {
new-item tmp -type directory
}
if (-not (test-path "tmp\backup") ) {
new-item tmp\backup -type directory
}
# fetch my configs from Github
(New-Object System.Net.WebClient).DownloadFile(
"https://gist.githubusercontent.com/napcs/532968/raw/.vimrc" ,"_vimrc")
(New-Object System.Net.WebClient).DownloadFile(
"https://gist.githubusercontent.com/napcs/532968/raw/vimrc_main","vimfiles/vimrc_main")
(New-Object System.Net.WebClient).DownloadFile(
"https://gist.githubusercontent.com/napcs/532968/raw/vundle","vimfiles/vundle")
# Grab the Vundle plugin from Git
$gitargs = @('clone', 'git://github.com/gmarik/vundle.git', 'vimfiles/bundle/vundle')
& 'git' $gitargs
# Run Vim for the first time and try to run BundleInstall
$vundleargs = @('+PluginInstall', '+qall')
& 'gvim' $vundleargs
# Script to install vim configuration files
# Tested with OSX and Ubuntu.
#
# Easiest way to use this is to run this from your home folder in Terminal:
#
# curl https://gist.githubusercontent.com/napcs/532968/raw/vim.sh | sh
#
# You'll need Vim, Git and Curl installed to use this script with Bash.
# Create initial directories
mkdir -p .vim/autoload
mkdir -p .vim/backup
mkdir -p .vim/bundle
cd .vim/bundle
git clone git://github.com/gmarik/vundle.git
cd ../..
# create temp folder for backups
mkdir -p tmp/backup
# Finally, put the config files in.
curl -k https://gist.githubusercontent.com/napcs/532968/raw/.vimrc > .vimrc
curl -k https://gist.githubusercontent.com/napcs/532968/raw/vimrc_main > .vim/vimrc_main
curl -k https://gist.githubusercontent.com/napcs/532968/raw/vundle > .vim/vundle
vim +PluginInstall +qall
" Cross-platform Vim Configuration goes in this file
"
" Contents
" Main configuration
" Visual Configuration
" Shortcut Key Configuration
" Plugin Configuration
" Private Configuration
" ----------- Main Configuration ----------------------------------
set nocompatible "don't need to keep compatibility with Vi
filetype plugin indent on "enable detection, plugins and indenting in one step
syntax on "Turn on syntax highlighting
set encoding=utf-8 "Force UTF-8 encoding for special characters
set ruler "Turn on the ruler
set number "Show line numbers
set cursorline "underline the current line in the file
set cursorcolumn "highlight the current column. Visible in GUI mode only.
set colorcolumn=80
set background=dark "make vim use colors that look good on a dark background
set showcmd "show incomplete cmds down the bottom
set showmode "show current mode down the bottom
set foldenable "enable folding
set showmatch "set show matching parenthesis
set noexrc "don't use the local config
"set virtualedit=all "allow the cursor to go in to "invalid" places
set incsearch "find the next match as we type the search
set hlsearch "hilight searches by default
set ignorecase "ignore case when searching
set shiftwidth=2 "number of spaces to use in each autoindent step
set tabstop=2 "two tab spaces
set softtabstop=2 "number of spaces to skip or insert when <BS>ing or <Tab>ing
set expandtab "spaces instead of tabs for better cross-editor compatibility
set smarttab "use shiftwidth and softtabstop to insert or delete (on <BS>) blanks
set shiftround "when at 3 spaces, and I hit > ... go to 4, not 5
set nowrap "no wrapping
set backspace=indent,eol,start "allow backspacing over everything in insert mode
set cindent "recommended seting for automatic C-style indentation
set autoindent "automatic indentation in non-C files
set copyindent "copy the previous indentation on autoindenting
set noerrorbells "don't make noise
set wildmenu "make tab completion act more like bash
set wildmode=list:longest "tab complete to longest common string, like bash
"set mouse-=a "disable mouse automatically entering visual mode
set mouse=a "enable mouse automatically entering visual mode
set hidden "allow hiding buffers with unsaved changes
set cmdheight=2 "make the command line a little taller to hide 'press enter to viem more' text
set clipboard=unnamed "Use system clipboard by default
set splitright "splits open on the right.
set splitbelow "splits open below existing window..
set exrc "enable per-directory .vimrc files
set secure "disable unsafe stuff from local .vimrc files
" Set up the backup directories to a central place.
set backupdir=$HOME/tmp/backup//
set directory=$HOME/tmp/backup//
" ----------- Visual Configuration ----------------------------------
try
colorscheme mycontrast
catch
colorscheme murphy
endtry
set statusline=%f%m%r%h%w[%l][%{&ff}]%y[%p%%][%04l,%04v][%n]
" | | | | | | | | | | | |
" | | | | | | | | | | | + current
" | | | | | | | | | | | buffer
" | | | | | | | | | | + current
" | | | | | | | | | | column
" | | | | | | | | | +-- current line
" | | | | | | | | +-- current % into file
" | | | | | | | +-- current syntax in
" | | | | | | | square brackets
" | | | | | | +-- current fileformat
" | | | | | +-- number of lines
" | | | | +-- preview flag in square brackets
" | | | +-- help flag in square brackets
" | | +-- readonly flag in square brackets
" | +-- rodified flag in square brackets
" +-- full path to file in the buffer
" Use a bar-shaped cursor for insert mode, even through tmux.
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" ----------- Shortcut Key Configuration ----------------------------------
let mapleader = "," "remap leader to ',' which is much easier than '\'
"Switch to previous file with ',spacebar'
nmap <leader><SPACE> <C-^>
" Open Taglist with [,s]
map <Leader>s :TlistToggle<CR>
" Use leader x to remove the current line but not erase buffer
map <Leader>x "_dd
" Use leader l to rapidly toggle `set list`
nmap <leader>l :set list!<CR>
" Exit insert mode with jk
imap jk <Esc>
" reload configuration file
map <Leader>r :so $MYVIMRC<CR>
" Exit insert mode and save with jj
imap jj <Esc>:w<CR>
"CTags
map <Leader>ct :!ctags -R --exclude=.git --exclude=log --exclude=.svn --verbose=yes * <CR>
" mapping to make movements operate on 1 screen line in wrap mode
function! ScreenMovement(movement)
if &wrap
return "g" . a:movement
else
return a:movement
endif
endfunction
onoremap <silent> <expr> j ScreenMovement("j")
onoremap <silent> <expr> k ScreenMovement("k")
onoremap <silent> <expr> 0 ScreenMovement("0")
onoremap <silent> <expr> ^ ScreenMovement("^")
onoremap <silent> <expr> $ ScreenMovement("$")
nnoremap <silent> <expr> j ScreenMovement("j")
nnoremap <silent> <expr> k ScreenMovement("k")
nnoremap <silent> <expr> 0 ScreenMovement("0")
nnoremap <silent> <expr> ^ ScreenMovement("^")
nnoremap <silent> <expr> $ ScreenMovement("$")
" Supports pasting in from the clipboard
" https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode
function! WrapForTmux(s)
if !exists('$TMUX')
return a:s
endif
let tmux_start = "\<Esc>Ptmux;"
let tmux_end = "\<Esc>\\"
return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end
endfunction
let &t_SI .= WrapForTmux("\<Esc>[?2004h")
let &t_EI .= WrapForTmux("\<Esc>[?2004l")
function! XTermPasteBegin()
set pastetoggle=<Esc>[201~
set paste
return ""
endfunction
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()
" Navigate tabs
map <F3> :tabp<CR>
map <F4> :tabn<CR>
" Turn text search highlight on/off with F5 key
map <F5> :set hls!<bar>set hls?<CR>
" double percentage sign in command mode is expanded
" to directory of current file - http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" insert blank line above in Normal mode
nnoremap <Leader>O mzO<esc>`z
" insert blank line below in Normal mode
nnoremap <Leader>o mzo<esc>`z
" Sort CSS properties alphabetically
nnoremap <leader>css :g#\({\n\)\@<=#.,/}/sort<cr>
" -- Number toggling
function! NumberToggle()
if(&relativenumber == 1)
set number
else
set relativenumber
endif
endfunc
nnoremap <F6> :call NumberToggle()<cr>
" Spell check toggle
map <leader>sp :setlocal spell! spelllang=en_us<CR>
" ----------- Plugin Configuration ----------------------------------
" ---- NERDTree configuration
" Open NERDTree with [,d]
map <Leader>d :NERDTreeToggle<CR>
let NERDTreeShowLineNumbers=1
let NERDTreeMinimalUI=1
let g:nerdtree_tabs_focus_on_files=1
let g:nerdtree_tabs_open_on_console_startup=1
" ---- CTRL-P configuration
" Open fuzzy finder with leader,f
map <Leader>f :CtrlP<CR>
" Fuzzy finder for buffers
map <Leader>b :CtrlPBuffer<CR>
" Exclude files from ctrl-p finder
let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
" ---- ack
" Open ack and ackg
map <Leader>A :AckG
map <Leader>a :Ack
" ---- vimux configs
let VimuxHeight = "33" "this is percentage
" Inspect runner pane
map <Leader>vi :InspectVimTmuxRunner<CR>
" Close vim tmux runner opened by RunVimTmuxCommand
map <Leader>vq :CloseVimTmuxRunner<CR>
" If text is selected, save it in the v buffer and send that buffer it to tmux
vmap <Leader>vs "vy :call RunVimTmuxCommand(@v . "\n", 0)<CR>
" Select current paragraph and send it to tmux
nmap <Leader>vs vip<LocalLeader>vs<CR>
" ----------- Mustache / Handlebars ---------------------------------
let g:mustache_abbreviations = 1
" ----------- Syntastic ---------------------------------
let g:syntastic_mode_map = { 'mode': 'active' }
let g:syntastic_ruby_checkers = ['mri', 'rubocop']
let g:syntastic_cucumber_cucumber_args="--profile syntastic"
" ---- Syntax inspector via vimcasts
" Show syntax highlighting groups for word under cursor with CtrlShiftR
nmap <C-S-R> :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" ----------- Dispatch configs ---------------------------------------
autocmd FileType coffee let b:dispatch = 'coffee -c %'
nnoremap <F9> :Dispatch<CR>
" ----------- Launch configs ---------------------------------------
if has('win32') || has ('win64')
let $CLEAR_COMMAND="cls"
else
let $CLEAR_COMMAND="clear"
endif
autocmd FileType ruby nmap <Leader>g :!"$CLEAR_COMMAND"; ruby "%"<cr>
autocmd FileType go nmap <Leader>g :!"$CLEAR_COMMAND"; go run "%"<cr>
autocmd filetype java nmap <Leader>g :!"$CLEAR_COMMAND"; javac "%" && java "%:r"<cr>
if has('win32') || has ('win64')
autocmd FileType html nmap <Leader>g :silent ! start firefox "%"<cr>
elseif has('mac')
autocmd FileType html nmap <Leader>g :!open "%"<cr><cr>
endif
autocmd FileType js nmap <Leader>g :!"$CLEAR_COMMAND"; node "%"<cr>
autocmd FileType coffee nmap <Leader>g :!"$CLEAR_COMMAND"; coffee "%"<cr>
autocmd FileType markdown nmap <Leader>g :!mark "%"<cr>
autocmd FileType groovy nmap <Leader>g :!"$CLEAR_COMMAND"; groovy "%"<cr>
autocmd FileType sh nmap <Leader>g :!"$CLEAR_COMMAND"; sh "%"<cr>
autocmd FileType python nmap <Leader>g :!"$CLEAR_COMMAND"; python "%"<cr>
autocmd FileType elixir nmap <Leader>g :!"$CLEAR_COMMAND"; elixir "%"<cr>
" Elixir tests should run mix
autocmd BufEnter *_test.exs nmap <Leader>g :!"$CLEAR_COMMAND"; mix test<cr>
kkkkk
" ----------- Private Configuration ----------------------------------
set nocompatible " be iMproved
filetype off " required!
set rtp+=$VIMHOME/bundle/vundle/
call vundle#begin($VIMHOME.'/bundle')
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" For Ruby / Rails dev
Bundle 'tpope/vim-rails'
Bundle 'vim-ruby/vim-ruby'
Bundle 'tpope/vim-cucumber'
Bundle 'tpope/vim-haml'
Bundle 'tpope/vim-rake'
" CoffeeScript support
Bundle 'kchmck/vim-coffee-script'
" Fuzzy finder
Bundle 'kien/ctrlp.vim'
" File tree
Bundle 'scrooloose/nerdtree'
" Support Block comments in visual mode with ,cc and ,cu
Bundle 'scrooloose/nerdcommenter'
" better support for ending statements in Ruby/C/Lua/etc
Bundle 'tpope/vim-endwise'
" better support for wrapping things with parens, quotes, braces
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-repeat'
" align variables and operators.
Bundle 'tsaleh/vim-align'
" HTML support
Bundle 'tpope/vim-ragtag'
" Markdown
Bundle 'tpope/vim-markdown'
" Tmux related
Bundle 'benmills/vimux'
Bundle 'jgdavey/vim-turbux'
Bundle 'christoomey/vim-tmux-navigator'
" launch build processes and other things in splits or tmux.
Bundle 'tpope/vim-dispatch'
" Ack (better searching)
Bundle 'geekq/ack.vim'
" Sets project root to wherever the root of the repository is.
Bundle 'airblade/vim-rooter'
" My custom color scheme
Bundle 'napcs/vim-mycontrast'
" Snippet support
Bundle "MarcWeber/vim-addon-mw-utils"
Bundle "tomtom/tlib_vim"
Bundle "garbas/vim-snipmate"
Bundle "honza/vim-snippets"
Bundle 'napcs/my-vim-snippets'
Bundle 'carlosgaldino/elixir-snippets'
" Tagbar support for showing CTags
Bundle 'majutsushi/tagbar'
" Database support. Run queries and stuff
Bundle 'vim-scripts/dbext.vim'
" Support for Go.
Bundle "jnwhiteh/vim-golang"
" Support for Grunt
Bundle 'mklabs/grunt.vim'
" Syntax checking
Bundle 'scrooloose/syntastic'
" Tab completion for variables and other things
Bundle 'ervandew/supertab'
"Easy navigation with ,,
Bundle 'Lokaltog/vim-easymotion'
" Shows colors in your css
Bundle 'ap/vim-css-color'
" Elixir support
Bundle 'elixir-lang/vim-elixir'
"Git support
Bundle 'tpope/vim-fugitive'
Bundle 'airblade/vim-gitgutter'
" Shell support
Bundle 'xolox/vim-misc'
Bundle 'xolox/vim-shell'
" Handlebars support
Bundle 'mustache/vim-mustache-handlebars'
" JavaScript libraries like jquery, etc
Bundle 'othree/javascript-libraries-syntax.vim'
" Strip whitespace
Bundle 'itspriddle/vim-stripper'
call vundle#end() " required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment