-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
138 lines (103 loc) · 3.79 KB
/
.vimrc
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
"
" Author: PJensen
" Date: 03/08/2013
" Description: gVim settings file.
"
" Color Scheme Init
colorscheme darkblue
" Tab, Whitespace and Spacing
set ts=4
set sw=4
set expandtab
" Spell checking
set spell
" Line numbers enabled
set nu
" Set ignore case
set ic
" Enable pattern highlighting
set hls
" Enable show-match
set sm
" Syntax highlighting
syntax on
"Ruler enabled
set ruler
" Windows
source $VIMRUNTIME/mswin.vim
" Global Abbreviations
:iab <expr> dts strftime("%c")
iabbrev <silent> CWD <C-R>=getcwd()<CR>
" Load vim-gist
set runtimepath+=$HOME/.vim/vim-gist
" Github setup
" and ... this token is invalid.
let g:github_user = substitute(system('git config --get user.name'), "\n", '', '')
let g:github_token = "3b51b179b0c1d190c8835ab2ef00273a"
let g:tab_toggle = 1
" F5 kicks this file out as a Gist.
nmap <F5> :Gist -p<CR>
" Perform basic calculation
imap <silent> calc <C-R>=string(eval(input("Calculate: ")))<CR>
" Classic ASP comment...
imap <silent> --- <C-R>=CommentBlock(input("Enter comment: "),"'--")<CR>
" Equals alignment
nmap <silent> === :call AlignAssignments()<CR>
" Function:
" Description:
function! ToggleTabs()
syntax match Tab /\t/
hi Tab gui=underline guifg=blue ctermbg=blue
endfunction
" Function: CommentBlock
" Description: Given some input, write a comment block.
" See: http://www.ibm.com/developerworks/linux/library/l-vim-script-2/index.html
function CommentBlock(comment, ...)
"If 1 or more optional args, first optional arg is introducer...
let introducer = a:0 >= 1 ? a:1 : "//"
"If 2 or more optional args, second optional arg is boxing character...
let box_char = a:0 >= 2 ? a:2 : "*"
"If 3 or more optional args, third optional arg is comment width...
let width = a:0 >= 3 ? a:3 : strlen(a:comment) + 2
" Build the comment box and put the comment inside it...
return introducer . " " . repeat(box_char,width) . "\<CR>"
\ . introducer . " " . a:comment . "\<CR>"
\ . introducer . " " . repeat(box_char,width) . "\<CR>"
endfunction
" Function: CommentBlock
" Description: Given some input, write a comment block.
" See: http://www.ibm.com/developerworks/linux/library/l-vim-script-2/index.html
function AlignAssignments ()
"Patterns needed to locate assignment operators...
let ASSIGN_OP = '[-+*/%|&]\?=\@<!=[=~]\@!'
let ASSIGN_LINE = '^\(.\{-}\)\s*\(' . ASSIGN_OP . '\)'
"Locate block of code to be considered (same indentation, no blanks)
let indent_pat = '^' . matchstr(getline('.'), '^\s*') . '\S'
let firstline = search('^\%('. indent_pat . '\)\@!','bnW') + 1
let lastline = search('^\%('. indent_pat . '\)\@!', 'nW') - 1
if lastline < 0
let lastline = line('$')
endif
"Find the column at which the operators should be aligned...
let max_align_col = 0
let max_op_width = 0
for linetext in getline(firstline, lastline)
"Does this line have an assignment in it?
let left_width = match(linetext, '\s*' . ASSIGN_OP)
"If so, track the maximal assignment column and operator width...
if left_width >= 0
let max_align_col = max([max_align_col, left_width])
let op_width = strlen(matchstr(linetext, ASSIGN_OP))
let max_op_width = max([max_op_width, op_width+1])
endif
endfor
"Code needed to reformat lines so as to align operators...
let FORMATTER = '\=printf("%-*s%*s", max_align_col, submatch(1),
\ max_op_width, submatch(2))'
" Reformat lines with operators aligned in the appropriate column...
for linenum in range(firstline, lastline)
let oldline = getline(linenum)
let newline = substitute(oldline, ASSIGN_LINE, FORMATTER, "")
call setline(linenum, newline)
endfor
endfunction