-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
273 lines (212 loc) · 7.93 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
"""""""""""""""""""""""""""""""
" GENERAL DISPLAY/OPERATION "
"""""""""""""""""""""""""""""""
" Turn off vi compatibility for better features.
set nocp
" Don't write backup files.
set nobackup
set nowritebackup
set noswapfile
" Backspace over autoindent, line breaks, and over the start of insert.
set backspace=indent,eol,start
"""""""""""""""""""""""""""""
" FILETYPE CUSTOMIZATIONS "
"""""""""""""""""""""""""""""
" Turn file type detection on, as well as for indentation and plugins.
filetype plugin indent on
" Set filetypes for my dot files.
autocmd BufRead,BufNew,BufNewFile .bash* set filetype=sh
autocmd BufRead,BufNew,BufNewFile .screenrc set filetype=sh
autocmd BufRead,BufNew,BufNewFile .inputrc set filetype=sh
" typescript fixes
au BufNewFile,BufRead *.tsx,*.jsx set filetype=typescript.typescriptreact
autocmd BufRead,BufNew * if (&ft == 'typescript' || &ft == 'typescript.typescriptreact') | set re=0 | endif
""""""""""""""""
" LINE OPTIONS "
""""""""""""""""
" Turn off text wrapping.
set textwidth=0
" Show line numbers.
set nu
" Keep a buffer of lines above and below the cursor.
set scrolloff=5
""""""""""""""""""""""""""""""""
" SEARCHING AND HIGHLIGHTING "
""""""""""""""""""""""""""""""""
" Turn on syntax highlighting.
syntax on
" Syntax highlighting for really long lines & files
" set synmaxcol=0
" syntax sync minlines=10000
" Incremental search.
set incsearch
" Highlight all search matches.
set hlsearch
" Case sensitive searching.
set noignorecase
" Press space to clear search highlighting and any message already displayed, get rid of preview window.
nnoremap <silent> <SPACE> :silent noh<Bar>echo<CR><C-W><C-Z>
" Highlight matching bracket.
set showmatch
" Set comment colors.
hi Comment ctermfg=Blue
hi Directory ctermfg=Blue
hi SpecialKey ctermfg=Blue
" Search mappings: These will make it so that going to a search result will center its line.
nnoremap N Nzz
nnoremap n nzz
nnoremap * *zz
nnoremap # #zz
" search and move to ~top of screen
"nnoremap N Nzt
"nnoremap n nzt
"nnoremap * *zt
"nnoremap # #zt
"""""""""""""""""""""""""""""""""""""""
" TABS, WHITESPACE, AND INDENTATION "
"""""""""""""""""""""""""""""""""""""""
" To toggle viewing whitespace:
" set list!
"
" To prevent converting tabs to spaces:
" set noexpandtab
" Convert spaces to tabs
" You can do %retab! after the above to fix spaces but it will also 'fix'
" spaces in the middle of a line.
" Use this regex instead: %s#\v(^(\t*|( )*))@<= #\t#gc
" %s = substitute on all lines
" # = use # instead of / for readability
" \v = use very magic mode - less escapes needed
" (^ = start group and start at beginning of line
" (\t* = start group and match any number of tabs (at the start of line)
" |( )* = OR match groups of two spaces
" )) = close previous groups
" @<= = positive lookbehind (must exist but won't be included in the 'match')
" ' #\t#' = replace two spaces with tab
" gc = global (multiple matches per line) & confirm
" Turn on indenting.
set autoindent
set smartindent
set cindent
" Set my tabstops.
autocmd BufRead,BufNew,BufNewFile * set tabstop=2
autocmd BufRead,BufNew,BufNewFile * set softtabstop=2
autocmd BufRead,BufNew,BufNewFile * set shiftwidth=2
" Convert tabs to spaces. (:retab to do this manually)
set expandtab
" Map tab to shift left and right, deselect if not selected, reselect if selected.
nnoremap <TAB> V><ESC>
nnoremap <S-TAB> V<LT><ESC>
vnoremap <TAB> >gv
vnoremap <S-TAB> <LT>gv
nnoremap > V><ESC>
nnoremap <LT> V<LT><ESC>
vnoremap > >gv
vnoremap <LT> <LT>gv
" Allow space to indent one space as tab does above
" Add the space just before first word
vnoremap <SPACE> :s/^\(\s*\)/\1 /<CR>:noh<BAR>echo<CR>gv
" Turn off folding for all file types.
set nofoldenable
set foldcolumn=0
autocmd BufLeave * if (&fen == 0) | set foldcolumn=0 | endif
" Set how whitespace and other chars are displayed when you use `set list!`
"set listchars=eol:¬,tab:>_,trail:~,extends:>,precedes:<,space:·
" Highlight trailing whitespace in red
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
""""""""""""""""""""""
" WINDOW SPLITTING "
""""""""""""""""""""""
" On enter, collapse other windows, get rid of preview window.
map <C-m> <C-W><C-Z><C-w>_
" Set the minimum window height to 0 for collapsing other windows.
set winminheight=0
" Have ^w kick out of insert mode first so it doesn't randomly delete stuff.
inoremap <C-w> <ESC><C-w>
""""""""""""""""""""
" TAB COMPLETION "
""""""""""""""""""""
" Fix coloring.
hi PmenuSel ctermfg=7 ctermbg=4
hi PmenuSbar ctermfg=Gray ctermbg=Blue
hi PmenuThumb cterm=reverse
" Set the preview window to 3 lines high.
set previewheight=3
" Insert only the longest match, open the menu even if there is only one match, show preview window.
set completeopt=longest,menuone,preview
" Make enter behave the same regardless of the complete menu state.
"http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
""""""""""""""""""
" STATUS LINES "
""""""""""""""""""
" Always show status line.
set laststatus=2
" Show the long vim commands you are executing as you type them in.
set showcmd
" Status add full path and file type to options, move options to right.
" Make all text black on grey, modified file = red from 2 User highlights.
function! SetupStatusLine()
hi User1 ctermbg=red ctermfg=white
hi User2 ctermbg=grey ctermfg=black
hi User3 ctermbg=black ctermfg=darkyellow
" Here's a breakdown.
" Some general info:
" %#* Means set the highlighting to the User# highlight colors.
" %xxx(yyy%) This is a grouping for setting alignment/width (xxx) of (yyy) inside the grouping.
" %-#.@ This is for formatting, - is left align, # is min width, @ is max width but optional.
"
" [%2*] Set highlighting to User2 (black on grey).
" [%<] Truncate here if the line is too long.
" [%F\ ] Full path to file in the buffer.
" [%=] Separation point between left and right aligned items.
" [%-5.(%)\ ] Empty group at least 5 wide followed by a space.
" [%-8.(%2*%y%)\ ] Display filetype (%y) in User2 highlighting (black on grey).
" [%-10.(%1*%m%*%2*%r%w%h%)\ ] Display modified (in red), readonly, preview, and help flags.
" [%-8.(%2*%l,%v%)\ ] Display line number, virtual column number.
" [%2*] Set highlighting back to User2.
" [%P] Display percentage of way through file.
set statusline=%2*%<%F\ %=%-5.(%)\ %-8.(%2*%y%)\ %-10.(%1*%m%*%2*%r%w%h%)\ %-8.(%2*%l,%v%)\ %2*%P
endfunction
call SetupStatusLine()
""""""""""""""""
" Better Tilde "
""""""""""""""""
function! BetterTilde()
let l:let = getline('.')[col('.') - 1] "get the letter under the cursor
echo l:let
if l:let =~ '"'
silent exe "normal s'\<ESC>"
elseif l:let =~ "'"
silent exe "normal s\"\<ESC>"
elseif l:let =~ "-"
silent exe "normal s\_\<ESC>"
elseif l:let =~ "_"
silent exe "normal s\-\<ESC>"
else
nunmap ~
silent exec "normal ~\<left>"
nnoremap ~ :call BetterTilde()<CR>
endif
endfunction
nnoremap ~ :call BetterTilde()<CR>
""""""""""""""""""""""
" PERSONAL HELPFILE "
""""""""""""""""""""""
" Use typing: `:help myhelp` OR `:help myhelp-diff`
" retag my personal help file
helpt ~/.vim/pack/personal/start/myhelp/doc/
""""""""""""""""""""
" LOCAL OVERRIDES "
""""""""""""""""""""
" search upward to find the file
let localvimscript=findfile('.vimscript_file', '.;')
if filereadable(expand(localvimscript))
exec "source " . expand(localvimscript)
" The following command might be too verbose, you can just run this to check
" tabs/spaces formatting and where the settings came from:
" verbose set ts? et?
"
" au BufReadPost,BufNewFile *.* verbose set ts? et?
endif