-
Notifications
You must be signed in to change notification settings - Fork 10
/
functions.vim
executable file
·107 lines (98 loc) · 2.57 KB
/
functions.vim
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
" FUNCTIONS
fun! ToggleSpell()
if &spell
if &spelllang == "pt"
set spelllang=pt,en
echo "toggle spell" &spelllang
elseif &spelllang == "pt,en"
set spelllang=en
echo "toggle spell" &spelllang
else
set spell!
echo "toggle spell off"
endif
else
set spelllang=pt
set spell!
echo "toggle spell" &spelllang
endif
endfun
" Toggle spell check
nmap <silent>ts :call ToggleSpell()<CR>
fun! FoldText()
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount) - 4
return line . ' …' . repeat(" ",fillcharcount) . foldedlinecount . ' '
endfun
fun! ToggleFold()
if &foldmethod == "indent"
set foldmethod=syntax
else
set foldmethod=indent
endif
endfun
nmap <silent>tf :call ToggleFold()<CR>
fun! 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)
endfun
fun! Clipboard()
reg
echo "Item: "
let char = nr2char(getchar())
if char != "\<Esc>"
execute "normal! \"".char."p"
endif
redraw
endfun
command! -nargs=0 Clipboard call Clipboard()
nmap <silent>C :call Clipboard()<cr>
function! ToggleNetrw()
if g:netrw_is_open
let i = bufnr("$")
while (i >= 1)
if (getbufvar(i, "&filetype") == "netrw")
silent exe "bwipeout " . i
endif
let i-=1
endwhile
let g:netrw_is_open=0
else
let g:netrw_is_open=1
silent Lexplore
endif
endfunction
let g:netrw_is_open=0
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
noremap <silent> <C-o> :call ToggleNetrw()<CR>
" Enable the auto-creation of missing folders in a save path
if !exists('*s:MakeNewDir')
function s:MakeNewDir(fullpath, buf)
if empty(getbufvar(a:buf,'&buftype')) && a:fullpath!~#'\v^\w+\:\/'
let dirpath=fnamemodify(a:fullpath,':h')
if !isdirectory(dirpath)|call mkdir(dirpath,'p')|endif
endif
endfun
augroup WriteDir
autocmd!
autocmd BufWritePre * :call s:MakeNewDir(expand('<afile>'),+expand('<abuf>'))
augroup END
endif