Skip to content

Instantly share code, notes, and snippets.

@c9s
Created May 26, 2009 03:29
Show Gist options
  • Save c9s/117872 to your computer and use it in GitHub Desktop.
Save c9s/117872 to your computer and use it in GitHub Desktop.
" SVK VIM Plugin Improve
" Author: Cornelius (c9s) <cornelius.howl (at) gmail.com>
" Version: 0.11
" original version is from Olekasandr Tymoshenko
" ------------------------------
" Language: SVK commit file
" Maintainer: Oleksandr Tymoshenko <[email protected]>
" URL: http://gonzo.kiev.ua/files/vim/ftplugin/svk.vim
" Revision: $Id$
" Filenames: svk-commit*.tmp
" Last Change: 2009 Apr 08
" Version: 0.1
" In SVK commit file one can add files that are not under source control
" by changing file status from '?' to 'A'. These plugin automates it adding
" Two keyboard shorcats C-A for adding file and C-X for un-adding it
" Only do this when not done yet for this buffer
if (exists("b:did_ftplugin"))
finish
endif
let b:did_ftplugin = 1
" Actions
function! SVK_add_file()
if <SID>_match_flag()
call <SID>_replace_flag('A')
call <SID>_nextline()
endif
endfunction
function! SVK_revert_file()
if <SID>_match_flag()
call <SID>_replace_flag('R')
call <SID>_nextline()
endif
endfunction
function! SVK_delete_file()
if <SID>_match_flag()
call <SID>_replace_flag('D')
call <SID>_nextline()
endif
endfunction
function! SVK_remove_file()
if <SID>_match_flag()
call <SID>_replace_flag('?')
call <SID>_nextline()
endif
endfunction
function! <SID>_replace_flag(flag)
silent execute 's/^[?AMDR]/' . a:flag . '/'
endfunction
function! <SID>_match_flag()
return getline(".") =~ "^[AMDR\?]"
endfunction
function! <SID>_nextline()
call cursor(line(".") + 1, 1)
endfunction
nmap <buffer> <silent> <C-A> :call SVK_add_file()<CR>
nmap <buffer> <silent> <C-R> :call SVK_revert_file()<CR>
nmap <buffer> <silent> <C-D> :call SVK_delete_file()<CR>
nmap <buffer> <silent> <C-X> :call SVK_remove_file()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment