Skip to content

Commit

Permalink
Alias more commands
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Aug 9, 2010
1 parent 6b7d2c5 commit 578ced9
Showing 1 changed file with 53 additions and 5 deletions.
58 changes: 53 additions & 5 deletions vimrc
Expand Up @@ -36,6 +36,7 @@ map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
" make and python use real tabs " make and python use real tabs
autocmd FileType make set noexpandtab autocmd FileType make set noexpandtab
autocmd FileType python set noexpandtab autocmd FileType python set noexpandtab
autocmd BufRead,BufNewFile {Gemfile,Rakefile,Thorfile} set ft=ruby


" allow backspacing over everything in insert mode " allow backspacing over everything in insert mode
set backspace=indent,eol,start set backspace=indent,eol,start
Expand All @@ -58,9 +59,7 @@ cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
autocmd VimEnter * NERDTree autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p autocmd VimEnter * wincmd p


function ChangeDirectory(dir) function s:UpdateNERDTree()
execute "cd " . a:dir

if exists("t:NERDTreeBufName") if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1 if bufwinnr(t:NERDTreeBufName) != -1
NERDTree NERDTree
Expand All @@ -69,5 +68,54 @@ function ChangeDirectory(dir)
endif endif
endfunction endfunction


command -nargs=1 -complete=file ChangeDir :call ChangeDirectory(<f-args>) function s:CommandCabbr(abbreviation, expansion)
cabbrev cd <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'ChangeDir' : 'cd')<CR> execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction

function s:FileCommand(name, ...)
if exists("a:1")
let funcname = a:1
else
let funcname = a:name
endif

execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
endfunction

function s:DefineCommand(name, destination)
call s:FileCommand(a:destination)
call s:CommandCabbr(a:name, a:destination)
endfunction

function ChangeDirectory(dir)
execute "cd " . a:dir
call s:UpdateNERDTree()
endfunction

function Touch(file)
execute "!touch " . a:file
call s:UpdateNERDTree()
endfunction

function Remove(file)
let current_path = expand("%")
let removed_path = fnamemodify(a:file, ":p")

echo current_path . ", " . removed_path
echo getbufvar("%", "&modified")
if (current_path == removed_path) && (getbufvar("%", "&modified"))
echo "You are trying to remove the file you are editing. Please close the buffer first."
else
execute "!rm " . a:file
endif
endfunction

function Edit(file)
execute "e " . a:file
call ChangeDirectory(system("dirname " . a:file))
endfunction

call s:DefineCommand("cd", "ChangeDirectory")
call s:DefineCommand("touch", "Touch")
call s:DefineCommand("rm", "Remove")
call s:DefineCommand("e", "Edit")

0 comments on commit 578ced9

Please sign in to comment.