Skip to content

Instantly share code, notes, and snippets.

@kien
kien / blockcolor.vim
Created October 11, 2011 21:09
Block color or Shaded indenting (Vim)
" <leader>B to toggle. The value of guibg must be hexadecimal.
" http://www.reddit.com/r/vim/comments/l8gua/code_block_background_color_is_there_a_way_to/
nn <silent> <leader>B :cal BlockColor(8, 0x101010)<cr>
func! BlockColor(max, step, ...) "{{{
let [max, bufnr] = [a:max, bufnr('%')]
" Colors
if !exists('g:colors_name') | let g:colors_name = 'default' | endif
if !exists('g:bc_highl') || ( exists('g:bc_highl') && g:bc_highl != g:colors_name )
@kien
kien / .vimrc
Created October 30, 2011 11:50
" Timestamping {{{
function! s:LastModified()
if &modified
let cursor = getpos(".")
sil! undoj
keepj exe '1,'.line("$").'s#^\(.\{,10} Last Modified « \)[^«»]\+\( »[^«»]*\)#\1'.
\ strftime('%a, %d %b %Y %X').'\2#e'
cal histdel("search", -1)
cal setpos(".", cursor)
endif
@kien
kien / com.vim
Created November 13, 2011 16:51
" List user-defined commands that don't have a mapping assigned to them.
" Run ":so %".
func! s:UnmappedCommands()
let lst = s:Lst()
for each in range(1, len(lst) - 1)
let str2 = matchstr(lst[each], '[^ ]\+', 4).' '
" Echo each line
echon each.':'
echoh Function
@kien
kien / html_matchtag.vim
Created November 22, 2011 17:42
html_matchtag.vim
" Vim plugin for showing matching html tags.
" Maintainer: Greg Sexton <gregsexton@gmail.com>
" Credits: Bram Moolenar and the 'matchparen' plugin from which this draws heavily.
if exists("b:did_ftplugin")
fini
en
let s:selfclosing = ['meta', 'link', 'img', 'input', 'area', 'base', 'br',
\ 'hr', 'param', 'col']
@kien
kien / script.vim
Created December 23, 2011 14:26
autoload/ctrlp/script.vim
" =============================================================================
" File: autoload/ctrlp/script.vim
" Description: Find loaded vimscripts (:scriptnames)
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" Init {{{1
if exists('g:loaded_ctrlp_script') && g:loaded_ctrlp_script
fini
en
@kien
kien / .vimrc
Created January 3, 2012 04:14 — forked from AndrewRadev/windows.vim
Repeatable <c-w> and family
" Repeatable <c-w> and family
nn <silent> <c-w> <esc>:cal wincmd#init()<cr>
nn <silent> _. <esc>:cal wincmd#repeat('act')<cr>
nn <silent> _; <esc>:cal wincmd#repeat('cur')<cr>
@kien
kien / oldfiles.vim
Created January 6, 2012 23:42
autoload/ctrlp/oldfiles.vim
" =============================================================================
" File: autoload/ctrlp/oldfiles.vim
" Description: Find files saved in viminfo: jumplist, changelist, marks ...
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['oldfiles']
" Create A Command:
@kien
kien / .vimrc
Created January 7, 2012 04:06
Repeatable g, z, [ and ] mappings
" Repeatable g, z, [ and ] mappings
nn <silent> g :<c-u>cal keycmd#init('g', v:register)<cr>
nn <silent> z :<c-u>cal keycmd#init('z', v:register)<cr>
nn <silent> [ :<c-u>cal keycmd#init('[', v:register)<cr>
nn <silent> ] :<c-u>cal keycmd#init(']', v:register)<cr>
nn <silent> _g :cal keycmd#repeat('g')<cr>
nn <silent> _z :cal keycmd#repeat('z')<cr>
nn <silent> _[ :cal keycmd#repeat('[')<cr>
nn <silent> _] :cal keycmd#repeat(']')<cr>
@kien
kien / gist:1610859
Created January 14, 2012 09:49
Custom statusline example
" File: after/plugin/ctrlp.vim
" Description: Custom statusline example
" Make sure ctrlp is installed and loaded
if !exists('g:loaded_ctrlp') || ( exists('g:loaded_ctrlp') && !g:loaded_ctrlp )
fini
en
" ctrlp only looks for this
@kien
kien / .vimrc
Created February 4, 2012 12:12
Set the working directory to the project's root
" Set the working directory to the project's root, or to the parent directory
" of the current file if a root can't be found.
func! s:etwd()
let cph = expand('%:p:h', 1)
if match(cph, '\v^<.+>://') >= 0 | retu | en
for mkr in ['.git/', '.hg/', '.vimprojects']
let wd = call('find'.(mkr =~ '/$' ? 'dir' : 'file'), [mkr, cph.';'])
if wd != '' | let &acd = 0 | brea | en
endfo