-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gvimrc
120 lines (94 loc) · 2.67 KB
/
.gvimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
set guifont=Menlo\ Bold:h11
" Project Tree
autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
let explicitDirectory = isdirectory(a:directory)
let directory = explicitDirectory || empty(a:directory)
if explicitDirectory
exe "cd " . a:directory
endif
if directory
NERDTree
wincmd p
bd
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(...)
let stay = 0
if(exists("a:1"))
let stay = a:1
end
if exists("t:NERDTreeBufName")
let nr = bufwinnr(t:NERDTreeBufName)
if nr != -1
exe nr . "wincmd w"
exe substitute(mapcheck("R"), "<CR>", "", "")
if !stay
wincmd p
end
endif
endif
if exists("CommandTFlush")
CommandTFlush
endif
endfunction
" Utility functions to create file commands
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
" Public NERDTree-aware versions of builtin functions
function ChangeDirectory(dir, ...)
execute "cd " . a:dir
let stay = exists("a:1") ? a:1 : 1
NERDTree
if !stay
wincmd p
endif
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")
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
call s:UpdateNERDTree()
endfunction
function Edit(file)
if exists("b:NERDTreeRoot")
wincmd p
endif
execute "e " . a:file
ruby << RUBY
destination = File.expand_path(VIM.evaluate(%{system("dirname " . a:file)}))
pwd = File.expand_path(Dir.pwd)
home = pwd == File.expand_path("~")
if home || Regexp.new("^" + Regexp.escape(pwd)) !~ destination
VIM.command(%{call ChangeDirectory(system("dirname " . a:file), 0)})
end
RUBY
endfunction
" Define the NERDTree-aware aliases
call s:DefineCommand("cd", "ChangeDirectory")
call s:DefineCommand("touch", "Touch")
call s:DefineCommand("rm", "Remove")
call s:DefineCommand("e", "Edit")