forked from tony/vim-config-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.vim
More file actions
172 lines (151 loc) · 4.51 KB
/
Copy pathfunctions.vim
File metadata and controls
172 lines (151 loc) · 4.51 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
" A wrapper function to restore the cursor position, window position,
" and last search after running a command.
function! Preserve(command)
" Save the last search
let last_search=@/
" Save the current cursor position
let save_cursor = getpos(".")
" Save the window position
normal H
let save_window = getpos(".")
call setpos('.', save_cursor)
" Do the business:
execute a:command
" Restore the last_search
let @/=last_search
" Restore the window position
call setpos('.', save_window)
normal zt
" Restore the cursor position
call setpos('.', save_cursor)
endfunction
" Make tabs pretty
"
fu! SeeTab()
if !exists("g:SeeTabEnabled")
let g:SeeTabEnabled = 0
end
if g:SeeTabEnabled==0
set listchars=tab:>\ ,trail:-,precedes:<,extends:> " display the following nonprintable characters
if $LANG =~ ".*\.UTF-8$" || $LANG =~ ".*utf8$" || $LANG =~ ".*utf-8$"
try
set listchars=tab:»\ ,trail:·,precedes:…,extends:…
set list
catch
endtry
endif
let g:SeeTabEnabled=1
else
set listchars&
let g:SeeTabEnabled=0
end
endfunc
fu! NERDTreeFindPrevBuf()
if nerdtree#isTreeOpen()
execute ':NERDTreeClose'
elseif (!filereadable(bufname('%')) || (bufname('%') == '__Tag_List__') || (bufname('%') == '__Tagbar__'))
echo "Previous buf not valid or readable file."
execute ':NERDTree ' . getcwd()
else
execute ':NERDTreeFind'
endif
endfunction
fu! NerdTreeFindPrevBuf2()
if (bufname('%') == '__Tag_List__') || (bufname('%') == '__Tagbar__')
wincmd p " previous window
if !filereadable(bufname('%'))
wincmd h " mv one window to the left
endif
execute ':NERDTreeFind'
else
if !filereadable(bufname('%'))
echo "Previous buf not valid or readable file."
execute ':NERDTree ' . getcwd()
else
execute ':NERDTreeFind'
endif
endif
endfunction
" Execute 'cmd' while redirecting output.
" Delete all lines that do not match regex 'filter' (if not empty).
" Delete any blank lines.
" Delete '<whitespace><number>:<whitespace>' from start of each line.
" Display result in a scratch buffer.
function! s:Filter_lines(cmd, filter)
let save_more = &more
set nomore
redir => lines
silent execute a:cmd
redir END
let &more = save_more
new
setlocal buftype=nofile bufhidden=hide noswapfile
put =lines
g/^\s*$/d
%s/^\s*\d\+:\s*//e
if !empty(a:filter)
execute 'v/' . a:filter . '/d'
endif
0
endfunction
command! -nargs=? Scriptnames call s:Filter_lines('scriptnames', <q-args>
" Awesome vim {{{
" based off http://stackoverflow.com/questions/7135985/detecting-split-window-dimensions
" command! SplitWindow call s:SplitWindow()
" function! s:SplitWindow()
" let l:height=winheight(0) * 2
" let l:width=winwidth(0)
" if (l:height > l:width)
" :split
" else
" :vsplit
" endif
" endfunction
" " based off http://stackoverflow.com/questions/7135985/detecting-split-window-dimensions
" command! ChangeLayout call s:ChangeLayout()
" function! s:ChangeLayout()
" let l:height=winheight(0) * 2
" let l:width=winwidth(0)
" if (l:height > l:width)
" <C-w> <C-H>
" else
" <C-w> <C-J>
" endif
" endfunction
" Find and replace visual
" Source: http://stackoverflow.com/a/6171215
" Escape special characters in a string for exact matching.
" This is useful to copying strings from the file to the search tool
" Based on this - http://peterodding.com/code/vim/profile/autoload/xolox/escape.vim
function! EscapeString (string)
let string=a:string
" Escape regex characters
let string = escape(string, '^$.*\/~[]')
" let string = substitute(
" \ escape(string, '/\.*$^~[]'),
" \ '\_s\+',
" \ '\\_s\\+',
" \ 'g')
" Escape the line endings
let string = substitute(string, '\n', '\\n', 'g')
return string
endfunction
" Get the current visual block for search and replaces
" This function passed the visual block through a string escape function
" Based on this - http://stackoverflow.com/questions/676600/vim-replace-selected-text/677918#677918
function! GetVisual() range
" Save the current register and clipboard
let reg_save = getreg('"')
let regtype_save = getregtype('"')
let cb_save = &clipboard
set clipboard&
" Put the current visual selection in the " register
normal! ""gvy
let selection = getreg('"')
" Put the saved registers and clipboards back
call setreg('"', reg_save, regtype_save)
let &clipboard = cb_save
"Escape any special characters in the selection
let escaped_selection = EscapeString(selection)
return escaped_selection
endfunction