1"=============================================================================
2"
3" NAME
4"
5" .vimrc
6"
7" DESCRIPTION
8"
9" Settings for Vim editor loaded upon startup.
10"
11" NOTES
12"
13" UNIX, Mac OS X: Copy to ~/.vimrc
14" Windows: Copy to C:/Program Files/vim/_vimrc
15"
16" AUTHOR
17"
18" Bram Moolenaar <Bram@vim.org>
19" Sean Erik O'Connor 10 Oct 2024
20"
21"=============================================================================
22
23set fileformat=unix
24set encoding=UTF-8
25
26" Use Vim settings, rather then Vi settings (much better!).
27" This must be first, because it changes other options as a side effect.
28set nocompatible
29
30" Vim can detect the file type.
31filetype on
32
33" Enable plugins
34filetype plugin on
35
36" Mouse and window behavior tuned for Microslime Windows.
37behave mswin
38
39" Restore Control-F to page forward instead of find dialog box.
40"unmap<C-F>
41
42" Allow backspacing over everything in insert mode.
43set backspace=indent,eol,start
44
45" Turn on backup option.
46set backup
47
48" Create the backup directory if it doesn't exist.
49if !isdirectory($HOME.'/.vim/.backup')
50 silent call mkdir( $HOME.'/.vim/.backup', 'p' )
51endif
52
53" Store backups in the home directory ~/.vim/.backup.
54set backupdir=~/.vim/.backup
55
56" Make a backup before overwriting the current buffer.
57set writebackup
58
59" Overwrite the original backup file.
60set backupcopy=yes
61
62" Put swap files in the home directory ~/.vim/.swp
63if !isdirectory($HOME."/.vim/.swp")
64 silent call mkdir( $HOME.'/.vim/.swp', 'p' )
65endif
66
67set directory=~/.vim/.swp
68
69set history=2000 " Keep 2000 lines of command line history.
70set ruler " Show the cursor position all the time.
71set showcmd " Display incomplete commands.
72
73set incsearch " Do incremental searching.
74set hlsearch " Searches are highlighted.
75
76set wildmenu " File name completing using tabs cycles through all possibilities.
77set wildmode=list:longest " Make similar to bash completion.
78set wildignore=*.docx,*.jpg,*.png,*.gif,*.pyc,*.xlsx:w " Ignore these files when doing file name completion.
79
80set lazyredraw " Don't redraw screen while running macros.
81
82set lines=80 " Number of lines visible on the screen.
83set columns=160 " Number of columns visible on the screen.
84winpos 700 100 " Initial window position (MacBookPro).
85set winwidth=240 " Initial window width.
86set winminwidth=150 " Minimum width.
87
88set cursorline " Highlight the current line.
89set number " Show line numbers.
90set nosmartindent " Don't use smart indenting.
91
92set tabstop=4 " Tabs are 4 spaces wide.
93set softtabstop=4 " When editing, tabs are 4 spaces wide.
94set shiftwidth=4 " Indent 4 spaces.
95set expandtab " Expand tabs into spaces.
96set smarttab " tab in front of a line inserts shiftwidth spaces, and backspace will delete that many spaces.
97
98set showmatch " Show matching parentheses.
99set matchtime=5 " Match time is 1/2 sec.
100
101" Error blink and bell.
102set errorbells
103set visualbell
104
105" Set file paths to my most commonly used directories (MacBookPro).
106set path="~/Applications/vim/**"
107set path+="~/Desktop/Sean/WebSite/**"
108
109" Default directory is my current active subdirectory
110" in my web page directory.
111" This is where :e . takes us.
112cd ~/Desktop/Sean/WebSite/Mathematics/AbstractAlgebra/PrimitivePolynomials/Project/SourceCode
113
114" Set paths for tags files generated by Ctags. See :help tags
115" "./tags" means search for the file "tags" in the same directory as the current f i l e you are editing.
116" "tags" means search for the file "tags" in the current working directory (the directory shown by the command :pwd)
117" NOTE: this is affected if you set autochdir (see below).
118" Then search from the directory containing tags to your home directory.
119set tags=./tags,tags;~
120
121" Automatically change the current working directory to the one containing the file which was opened. See :help autochdir
122"Note: When this option is on some plugins may not work.
123set autochdir
124
125" Color them the same as the C group-name "Type".
126highlight link xType Type
127
128" Persistent undo: undo changes even after saving the file and exiting Vim.
129if has('persistent_undo')
130 set undofile
131 set undodir=$HOME/.vim/.backup
132endif
133
134" ===============================================================================
135" | Color scheme and font for the full gVim GUI.
136" | Use the default for launching vim from a command window.
137" ===============================================================================
138if has("gui_running")
139
140 colorscheme torte
141
142 " To verify the if condition, on the Vim command line, do
143 " :echom has("x11")
144 " and look for 1 or 0.
145 "
146 " To find out the font type:
147 " In the Vim command line, do
148 " :set guifont=*
149 " to make a menu come up.
150 "
151 " Select the font from the menu.
152 "
153 " Do the command
154 " :set guifont?
155 " to find out the name.
156 "
157 " In the if tests below, add
158 " set guifont=<name of the font>
159 " Escape all spaces with backslashes.
160 "
161 if has("gui_win32")
162 set guifont=Courier_New:h13:b
163 " Test for Mac first.
164 elseif has("mac")
165 set guifont=Menlo\ Regular:h12
166 " On Ubuntu Linux:
167 elseif has("x11")
168 set guifont=DejaVu\ Sans\ Mono\ 10
169 " Otherwise
170 else
171 set guifont=*
172 endif
173endif
174
175" Switch syntax highlighting on, when the terminal has colors.
176" Also switch on highlighting the last used search pattern.
177if &t_Co > 2 || has("gui_running")
178 syntax on " Turn on syntax highlighting.
179 set hlsearch " Searches are highlighted.
180endif
181
182" ===============================================================================
183" | Abbreviations
184" ===============================================================================
185
186" Abbreviations. My name:
187:iabbrev soc Sean Erik O'Connor
188
189" Right arrow.
190:iabbrev rar ➤
191
192:iabbrev bf \mathbf{
193:iabbrev fb }
194
195" ===============================================================================
196" | Shortcuts - HTML and CSS
197" ===============================================================================
198
199" Remapping looks like
200" <map_mode> <what you type> <what is executed>
201" These are the map modes:
202" nnoremap - Map keys in normal mode.
203" inoremap - Map keys in insert mode.
204" vnoremap - Map keys in visual mode.
205
206" Let comma be the character which starts any mapping command.
207let mapleader=","
208
209" Insert Blender hotkeys.
210nnoremap ,bhot a <em class="hotkey"></em><ESC>4hi
211
212" Insert html emphasis.
213nnoremap ,em a <em></em><ESC>4hi
214
215" Insert an HTML element with the indentation at the same level as the neighbors.
216" First CR finishes the call to function HTMLParagraph()
217" Second CR takes us out of command mode :
218" To see the echom debug statements, type :messages. To clear all
219" messages type :messages clear
220function! InsertHTMLElement( prefix, suffix )
221 echom "HTMLParagraph"
222 " Scan the previous few lines until you see a line which has an indent > 0.
223 " An indent value of -1 means the line does not exist (past the top or bottom of the file. Zero means a blank line.
224 let current_line_num = line(".")
225 let num_lines_to_search = 10
226 let previous_nonzero_indent = 0
227 for line_num in range( current_line_num-1, current_line_num - num_lines_to_search, -1)
228 echom 'line_num = ' line_num
229 let line_indent = indent( line_num )
230 echom 'line_indent = ' line_indent
231 if line_indent > 0
232 let previous_nonzero_indent = line_indent
233 break
234 endif
235 endfor
236 echom 'previous_nonzero_indent = ' previous_nonzero_indent
237 "Create indentation with blanks.
238 let blanks = repeat( " ", previous_nonzero_indent )
239 echom 'blanks = ' '|' .. blanks .. '|'
240 " Create the HTML element in the form of a list.
241 """""let HTMLElementLines = [ blanks .. '<div class="scrollBox"> <div class="scrollBoxContent">', blanks, blanks .. '</div></div>', '']
242 let HTMLElementLines = [ blanks .. a:prefix, blanks, blanks .. a:suffix, '']
243 echo 'HTMLElementLines = ' HTMLElementLines
244 " Append the scroll box lines after the current line.
245 call append( '.', HTMLElementLines )
246endfunction
247
248" The commands after the CR CR place the cursor into insert position.
249
250" Insert a scroll box.
251nnoremap <leader>sb :call InsertHTMLElement( '<div class="scrollBox"> <div class="scrollBoxContent">', '</div></div>' )<CR><CR>jjA
252
253" Insert an html paragraph.
254nnoremap <leader>par :call InsertHTMLElement( '<p>', '</p>' )<CR><CR>jjA
255
256" Insert hyperlink.
257nnoremap <leader>hr :call InsertHTMLElement('<a href="', '</a>')<CR><CR>kA<ESC>jj$JJa"><ESC>hhxi
258
259" Insert an image.
260nnoremap <leader>im :call InsertHTMLElement('<img class="centeredsmaller" alt="X" src="Images/X.jpg">','')<CR><CR>jfXfXxi
261
262" Insert a mathematical thingies.
263nnoremap <leader>def :call InsertHTMLElement('<em>Definition</em>','')<CR><CR>jA
264nnoremap <leader>lem :call InsertHTMLElement('<em>Lemma</em>','')<CR><CR>jA
265nnoremap <leader>prop :call InsertHTMLElement('<em>Proposition</em>','')<CR><CR>jA
266nnoremap <leader>th :call InsertHTMLElement('<em>Theorem</em>','')<CR><CR>jA
267nnoremap <leader>pf :call InsertHTMLElement('<em>Proof</em>','')<CR><CR>jA
268nnoremap <leader>cor :call InsertHTMLElement('<em>Corrollary</em>','')<CR><CR>jA
269nnoremap <leader>qed :call InsertHTMLElement('$\blacksquare$','')<CR><CR>jA
270
271" Insert a nonbreaking space.
272nnoremap ,s i <ESC>
273
274" ===============================================================================
275" | Shortcuts - miscellaneous
276" ===============================================================================
277
278" Make jk the same as ESCAPE in insert mode.
279inoremap jk <esc>
280
281" Reload this VIM resource file.
282nnoremap ,sou :source $MYVIMRC<CR>
283
284" Save the file.
285nnoremap ,sa :w<CR>
286
287" ===============================================================================
288" | Shortcuts - formatting
289" ===============================================================================
290
291" Trim blanks at end of all lines. Turn off search highlighting.
292nnoremap ,tbe :%s/\s*$//<CR><ESC>:nohlsearch<CR><ESC>
293
294" Make p in Visual mode replace the selected text with the "" register.
295vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>
296
297" Turn off highlighting after searches.
298nnoremap ,<SPACE> :nohlsearch<CR>
299
300" Toggle comment lines. You can highlight the range
301" with the mouse and then type ,to
302nnoremap ,to :call ToggleComment()<CR>
303
304function! ToggleComment()
305 " Get the line under the cursor
306 " Check if it begins with |
307 if getline(".") =~ '^|'
308 let s:savedSearchPat=@/
309 s/^|//
310 let @/=s:savedSearchPat
311 else
312 let s:savedSearchPat=@/
313 s/^/|/
314 let @/=s:savedSearchPat
315 endif
316endfunction
317
318" Convert C comments on a line to C++ comments.
319nnoremap ,cc :call ConvertCCommentToCpp()<CR>
320
321function! ConvertCCommentToCpp()
322 " Get the line under the cursor
323 " Check if contains a /*
324 if getline(".") =~ '\/\*'
325 let s:savedSearchPat=@/
326 s/\/\*/\/\//
327 let @/=s:savedSearchPat
328 endif
329 if getline(".") =~ '\*\/'
330 let s:savedSearchPat=@/
331 s/\*\///
332 let @/=s:savedSearchPat
333 endif
334endfunction
335
336" Justify a paragraph.
337nnoremap ,j gqap
338
339function! HardcopyPDF()
340 " https://askubuntu.com/questions/705973/how-can-i-print-from-vim-to-pdf
341 " Vim hardcopy generates a PostScript file.
342 " Convert to PDF, delete the PS file, tell where the PDF is located.
343 hardcopy > %.ps | !ps2pdf %.ps && rm %.ps && echom 'Created: %.pdf'
344endfunction
345
346" Hardcopy to *.pdf file.
347nnoremap ,pdf :call HardcopyPDF()<CR>
348
349" Special one time mapping. Change master_xyz to local_xyz
350nnoremap ,ll /master<CR>dt_ilocal<ESC>
351
352" ===============================================================================
353" | Folding
354" ===============================================================================
355" zR - open all folds
356" zM - close all folds
357" zj, zk - move between folds
358" za - toggle folds; mapped to shortcut ,,
359" :help usr_28
360set foldmethod=indent " Folding based on indentation.
361set foldcolumn=2 " Show the status of the folds in the left column.
362nnoremap <leader>, za
363
364" Save the folds in this file upon write, and load again upon read.
365" Saved in ~/.vim/view
366augroup remember_folds
367 autocmd! | " Clear all existing autocommands
368 autocmd BufWinLeave * silent! mkview
369 autocmd BufWinEnter * silent! loadview
370augroup END