Skip to content

Instantly share code, notes, and snippets.

0410dc929cd88232a75fe0cd33a0bbf1cf050cc6aa93912393251a997df4ead4b1f0e71a14586594dbdb242f74b4acec05e1e76957ac7f75ae7b323e30b6c8499e;nortss
@kien
kien / gist:3748204
Created September 19, 2012 07:35
dyn tabline + unique bufname
" Unique Bufname {{{
fu! s:update_buflist(bufnr)
let bufname = bufname(str2nr(a:bufnr))
if bufname == ''
retu
en
let slash = exists('+ssl') && !&ssl ? '\' : '/'
" Check if the new buffer has a duplicate
let bufname = fnamemodify(bufname, ':t')
if exists('s:buflist_short') && exists('s:buflist') && !count(s:buflist_short, bufname)
@kien
kien / async.vim
Created July 3, 2012 07:35
async.vim
if exists('loaded_ctrlpasync') || &cp || version < 700
fini
en
let loaded_ctrlpasync = 1
let s:locked = 0
fu! s:async(path)
if !has('clientserver') || s:locked | retu | en
let svid = get(filter(split(serverlist(), "\n"), 'v:val !=? v:servername'), 0, '')
@kien
kien / bufsync.vim
Created June 24, 2012 13:06
bufsync.vim
" Sharing the buffer list between Vim instances
" Usage:
" Run :BufSyncServer in the main Vim instance
" Run :BufSyncClient in the client instance(s)
" Option:
let s:buflist = 'path/to/cachefile'
" Commands:
@kien
kien / localrc.vim
Created June 3, 2012 07:07
finding local vimrc
" require Vim 7.1.299+
fu! s:localrc(...)
let path = a:0 ? expand('%:p:h', 1) : getcwd()
if path =~ '^.\+://'
retu
en
let rc = findfile('.lvimrc', path.';')
if rc != '' && filereadable(rc)
exe 'so' fnameescape(rc)
@kien
kien / mrudirs.vim
Created June 2, 2012 15:09
mru working directories
fu! s:savecwd()
if !exists('g:CWDS')
let g:CWDS = []
en
let cwd = getcwd()
let idx = index(g:CWDS, cwd)
if idx >= 0
cal remove(g:CWDS, idx)
@kien
kien / vcsdir.vim
Created March 23, 2012 13:08
VCS directory extension
" =============================================================================
" File: autoload/ctrlp/vcsdir.vim
" Description: VCS directory extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions = ['vcsdir']
" Create A Command:
@kien
kien / .vimrc
Created February 10, 2012 16:17
Indent text object
func! s:indentobj(i, ...)
let ls = { 0: 1, 1: line('.'), 2: line('$') }
if getline(ls[1]) =~ '^\s*$' | retu | en
let idt = max([indent(ls[1]) - &sw * ( v:count1 - 1 ), 0])
for [idx, rs] in items({ 0: range(ls[1], 1, -1), 2: range(ls[1], ls[2]) })
for line in rs | if getline(line) !~ '^\s*$' && indent(line) < idt
cal extend(ls, { idx : line }) | brea
en | endfo
endfo
exe 'keepj norm! '.( ls[0] + a:i ).'GV'.( ls[2] - ( a:i || a:0 ) ).'G'
@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
@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