-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.vim
More file actions
89 lines (81 loc) · 2.82 KB
/
helper.vim
File metadata and controls
89 lines (81 loc) · 2.82 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
function! s:getchar() abort
redraw | echo 'Press any key: '
let c = getchar()
while c ==# "\<CursorHold>"
redraw | echo 'Press any key: '
let c = getchar()
endwhile
redraw | echomsg printf('Raw: "%s" | Char: "%s"', c, nr2char(c))
endfunction
command! GetChar call s:getchar()
command! Reload :source $XDG_DATA_HOME/nvim/init.vim
command! FixSyntax :syntax sync fromstart " sometimes vim can't highlight syntax correctly
" return OS type
function! MySys()
if has("win16")||has("win32")||has("dos")||has("dos16")||has("dos32")||has("win64")||has("win95")
return "windows"
elseif has("unix")
return has('mac') ? "mac" : "linux"
endif
endfunction
" check required folders needed by this vimrc , if not exists,create
function! EnsureDirExists (dir)
if !isdirectory(a:dir)
if exists("*mkdir")
call mkdir(a:dir,'p')
echo "Created directory: " . a:dir
else
echo "Please create directory: " . a:dir
!cmd
endif
endif
endfunction
" Strip whitespace
function! StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
%s/\s\+$//e
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
"===============================================================================
" Author: JarrodCTaylor
" Source: https://github.com/JarrodCTaylor/dotfiles/blob/master/vim/functions/delete-regex-buffers.vim
" DESCRIPTION: Delete buffers from buffer list matching regex
" EXAMPLE USAGE: Assuming we have [text1.md, text2.md, text3.md] buffers open.
" We can delete buffers text2.md and text3.md like so
" `:BD 2\|3`
" There are delete because the regex `2\|3` matches the desired
" buffer names
"===============================================================================
function! DeleteMatchingBuffers(pattern, hasBang)
let l:bufferList = filter(range(1, bufnr('$')), 'buflisted(v:val)')
let l:matchingBuffers = filter(bufferList, 'bufname(v:val) =~ a:pattern')
if len(l:matchingBuffers) < 1
echo 'No buffers found matching pattern ' . a:pattern
return
endif
if (a:hasBang)
execute 'bd! ' . join(l:matchingBuffers, ' ')
else
execute 'bd ' . join(l:matchingBuffers, ' ')
endif
endfunction
command! -nargs=1 -bang BD call DeleteMatchingBuffers('<args>', <bang>0)
" 新开tab显示命令执行的结果
" Examples:
" TabMessage highlight
" TabMessage !git stash show -p stash@{0}
function! TabMessage(cmd)
redir => message
silent execute a:cmd
redir END
tabnew
silent put=message
set nomodified
endfunction
command! -nargs=+ -complete=command TabMessage call TabMessage(<q-args>)