Skip to content

Instantly share code, notes, and snippets.

@cbadke
Forked from napcs/.vimrc
Last active April 24, 2017 16:08
Show Gist options
  • Save cbadke/fe5f5e16f0e0da2467d5 to your computer and use it in GitHub Desktop.
Save cbadke/fe5f5e16f0e0da2467d5 to your computer and use it in GitHub Desktop.
Set up Vim on Mac, Linux, or Windows. For Mac and Linux: sh <(curl -s https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/vim.sh) For Windows: iex ((new-object net.webclient).DownloadString('https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/vim.ps1'))
" 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

  • ,sp toggles spell check on and off.
  • ,l toggles whitespace character visibility
  • ,r reloads the Vim configuration
  • ,g will attempt to launch the program for the current file
  • <C-h> previous buffer
  • <C-l> next buffer
  • <C-s> save

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 %>
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
},
"settings": {
"ecmascript": 6,
"jsx": true
},
"plugins": [
"react"
],
"rules": {
"strict": 0,
"quotes": 0,
"no-unused-vars": 0,
"camelcase": 0,
"no-underscore-dangle": 0
}
}
# 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\autoload -type directory
new-item vimfiles\backup -type directory
new-item vimfiles\bundle -type directory
# Grab the Vundle plugin from Git
git clone git://github.com/gmarik/vundle.git vimfiles/bundle/vundle
# fetch my configs from Github
Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/.vimrc' -OutFile '_vimrc'
Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/vimrc_main' -OutFile 'vimfiles/vimrc_main'
Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/vundle' -OutFile 'vimfiles/vundle'
Invoke-WebRequest -Uri 'https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/eslintrc' -OutFile '.eslintrc'
# Run Vim for the first time and try to run BundleInstall
vim +PluginInstall +qall
npm install -g eslint
npm install -g babel-eslint
npm install -g eslint-plugin-react
# 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 ../..
# Finally, put the config files in.
curl -k https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/.vimrc > .vimrc
curl -k https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/vimrc_main > .vim/vimrc_main
curl -k https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/vundle > .vim/vundle
curl -k https://gist.githubusercontent.com/cbadke/fe5f5e16f0e0da2467d5/raw/eslintrc > .eslintrc
vim +PluginInstall +qall
npm install -g eslint
npm install -g babel-eslint
npm install -g eslint-plugin-react
" 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 numberwidth=5
if has('win32') || has ('win64')
hi CursorLine ctermbg=1 guibg=#005366
hi CursorColumn ctermbg=1 guibg=#005366
endif
set cursorline "underline the current line in the file
set colorcolumn=80
set hidden " allow unsaved background buffers and remember marks/undo for them
set history=10000 " remember more commands and search history
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 smartcase "make searches case-sensitive only if they contain upper-case characters
hi Search guibg=LightBlue ctermbg=LightBlue
nnoremap <cr> :nohlsearch<cr>
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 up the backup directories to a central place.
set backupdir=$VIMHOME/backup/
set directory=$VIMHOME/backup/
" keep search pattern in center of screen
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" ----------- Visual Configuration ----------------------------------
set background=dark "make vim use colors that look good on a dark background
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 the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" Highlight trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" ----------- Shortcut Key Configuration ----------------------------------
let mapleader = "," "remap leader to ',' which is much easier than '\'
" 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("$")
" Spell check toggle
map <leader>sp :setlocal spell! spelllang=en_us<CR>
" Use leader l to rapidly toggle `set list`
nmap <leader>l :set list!<CR>
" reload configuration file
map <Leader>r :so $MYVIMRC<CR>
nmap <C-h> :bp<cr> " Ctrl-h goes to previous buffer
nmap <C-l> :bn<cr> " Ctrl-l goes to next buffer
nmap <C-s> :w<cr> " Ctrl-s saves
imap <C-s> <esc>:w<cr>i
" ARROW KEYS ARE UNACCEPTABLE - vim hard mode!
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
" ----------- Launch configs ---------------------------------------
autocmd FileType ruby nmap <Leader>g :!ruby "%"<cr>
autocmd FileType java nmap <Leader>g :!javac "%"<cr>
if has('win32') || has ('win64')
autocmd FileType html nmap <Leader>g :silent ! start chrome "%"<cr>
elseif has('mac')
autocmd FileType html nmap <Leader>g :!open "%"<cr>
endif
autocmd FileType js nmap <Leader>g :!node "%"<cr>
autocmd FileType sh nmap <Leader>g :!sh "%"<cr>
" ----------- Autocommand ---------------
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" ----------- Plugin Configuration ----------------------------------
let g:jsx_ext_required = 0 " Allow JSX in normal JS files
let g:syntastic_javascript_checkers = ['eslint']
" ----------- 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'
" colours!
Bundle 'groenewege/vim-less'
" Powershell syntax highlighting (in Windows)
if has('win32') || has ('win64')
Bundle 'PProvost/vim-ps1'
endif
" markdown support and in-browser previewing
Bundle 'tpope/vim-markdown'
" HTML support
Bundle 'tpope/vim-ragtag'
" better support for wrapping things with parens, quotes, braces
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-repeat'
" Syntax checking
Bundle 'scrooloose/syntastic'
" Shows colors in your css
Bundle 'ap/vim-css-color'
"Git support
Bundle 'airblade/vim-gitgutter'
" Strip whitespace
Bundle 'itspriddle/vim-stripper'
" jsx highlighting
Bundle 'mxw/vim-jsx'
Bundle 'pangloss/vim-javascript'
" Swift highlighting
Plugin 'keith/swift.vim'
Plugin 'ctrlpvim/ctrlp.vim'
call vundle#end() " required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment