Find file
Fetching contributors…
Cannot retrieve contributors at this time
229 lines (187 sloc) 6.61 KB
" Bare bones vim settings
" This file can be used on a remote server that you don't have a home directory.
" Simply do the following on the server:
"$ curl -o /tmp/_vimrc
" This might work if you don't have a .vim/ or .viminfo in the current user's
" home directory
"$ export MYVIMRC=/tmp/_vimrc
"$ vim
" If this doesn't work, you can call it manually when you use vim
"$ vim filename.ext -u /tmp/_vimrc
set nocompatible "disable vi compatibility for better features
"-- Find --
set path=** "set find path to current directory
set,.html,.css,.js,.scss,.less "add sufixes so you don't have to type whole filenames
"-- Autocomplete on command mode --
set wildmode=full "autocomplete filenames, help, etc.
set wildmenu "shows autocomplete options in a nice menu list
set wildignore=*.swp,*.bak,*.pyc "ignore certain file types in autocompletion
"-- Syntax --
filetype on "auto detect filetype
syntax on "syntax highlighting
"-- Custom leader key mapping --
let mapleader = "," "much easier than \, but you make the default command 'Repeat
"latest f, t, F or T in opposite direction' slower, but that's ok
"-- Spaces and Indenting --
set backspace=indent,eol,start "set backspace behavior (so it can backspace over auto-indent, newline, etc.)
set expandtab "replace tabs with spaces
set tabstop=2 "use 4 spaces to represent a tab
set softtabstop=2
set shiftwidth=2 "use 4 spaces for auto indent (use >> or << to indent current line)
set autoindent
"-- UI --
set shortmess=atI " Don't show the intro message when starting vim
set title " set the terminal title
set background=dark
set ruler "show status line
set rulerformat=%10(%l,%c%V%)
set laststatus=2 "always show status line
set cursorline "highlight current line
set number "show line numbers
set numberwidth=5
set hlsearch "highlight search keywords
" automatic set relative number for current buffer, and absolute numbers for inactive ones
function! UpdateNumbers(state)
if a:state == 'enter'
if buffer_name('%') !~# 'NERD_tree_.\+'
if exists('&relativenumber')
set relativenumber
if buffer_name('%') !~# 'NERD_tree_.\+'
set number
autocmd BufEnter * call UpdateNumbers('enter')
autocmd BufLeave * call UpdateNumbers('leave')
" toggle line numbers (loops between relative, absolute, and no numbers)
function! NumberToggle()
if(&relativenumber == 1)
set number
if(&number == 1)
set invnumber
set relativenumber
nnoremap <silent> <leader>r :call NumberToggle()<cr>
" show trailing spaces, tabs, and end of lines
set listchars=tab:>-,trail:.,eol:$,nbsp:_
nmap <silent> <leader>s :set nolist!<CR>
" easier completion mode
imap <c-k> <c-x>
" set minimum window height to 0 instead of 1
set wmh=0
"-- Search --
set incsearch "dynamically search term as you type (incremental search)
set ignorecase "case-insensitive search
set smartcase "make search case sensitive if there's an uppercase letter in the keyword
"-- Navigation --
" easier way to get to beginning end of line
map H ^
map L $
" quick way to escape insert mode
inoremap kj <ESC>
" <C-Space> only works with gui
imap <C-SPACE> <ESC>
" in most terminals, Ctrl+Space is sent as a null character
imap <nul> <ESC>
" make <tab> jump you to the matching bracket in normal or visual modes
nmap <tab> %
vmap <tab> %
"--- windows ---
" quick window switching
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
" Zooms/maximize current window. If it's already zoomed, even size all windows
let g:ZoomWin=0
function! ToggleZoom()
if winnr('$') != 1 " only zoom if there's more than one window
if winnr() != g:ZoomWin " and current window is not zoomed
" zoom cur window
let g:ZoomWin = winnr()
exe "normal \<c-w>_\<c-w>|"
else " otherwise restore windows
let g:ZoomWin = 0
exe "normal \<c-w>="
map <silent> <Leader>, :call ToggleZoom()<cr>
"--- Tabs ---
nnoremap <leader>[ :tabprevious<CR>
nnoremap <leader>] :tabnext<CR>
"--- Files/Buffers ---
" quicker saving
map <Leader>w :w<cr>
" quicker closing of file
map <Leader>q :q<cr>
" quicker way to quit vim (if all files saved)
map <c-d> :qa<cr>
" close file and delete its buffer
map <Leader>d :bd<cr>
" quick list of buffers
map <Leader>b :buffers<cr> ".vimrc will overwrite this with a better plugin
" edit completion with current file's dictory
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" toggle diff mode for current buffer // thanks to
nnoremap <silent> <Leader>D :call DiffToggle()<CR>
function! DiffToggle()
if &diff
"-- Command Line -- removed emacs binding. Now I'm using:
" <C-b>/<C-e> to go to beggining/end of the line
" <S-Left>/<S-Right> to jump between words
" <C-f> to go into a command line buffer mode
" regular vim keys to edit the command (or find previous commands)
" <C-c> to exit and go back into command line
"-- Utilities --
" toggle paste mode
map <Leader>p :set invpaste<CR>
" hide search highlights
nnoremap <silent> <Esc><Esc> :noh<cr>
" keep visual selection after indenting
vnoremap < <gv
vnoremap > >gv
" toggle between UPPER, lower, and Title case
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
let result = toupper(a:str)
return result
vnoremap ~ ygv"=TwiddleCase(@")<CR>Pgv
" map 'Oo' to return to a newline above your current position
" (useful when you want to close brackets and still continue editing)
inoremap Oo <ESC>ko
" remap Ctrl+A and Ctrl+X to +/- for easy increment/decrement of numbers
nnoremap + <c-a>
nnoremap - <c-x>
" creates a line separator line below the current line
" use any character key after calling this to pick which char to fill the line
" eg: using <leader>1= will create a line like
" =============
nnoremap <leader>1 yypVr