Permalink
Browse files

Alias more commands

  • Loading branch information...
1 parent 6b7d2c5 commit 578ced982e01796b328d597fe8e53e33b3a16986 @wycats wycats committed Aug 9, 2010
Showing with 53 additions and 5 deletions.
  1. +53 −5 vimrc
View
@@ -36,6 +36,7 @@ map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
" make and python use real tabs
autocmd FileType make set noexpandtab
autocmd FileType python set noexpandtab
+autocmd BufRead,BufNewFile {Gemfile,Rakefile,Thorfile} set ft=ruby
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
@@ -58,9 +59,7 @@ cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
-function ChangeDirectory(dir)
- execute "cd " . a:dir
-
+function s:UpdateNERDTree()
if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1
NERDTree
@@ -69,5 +68,54 @@ function ChangeDirectory(dir)
endif
endfunction
-command -nargs=1 -complete=file ChangeDir :call ChangeDirectory(<f-args>)
-cabbrev cd <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'ChangeDir' : 'cd')<CR>
+function s:CommandCabbr(abbreviation, expansion)
+ 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.