/ .dotfiles / .vimrc
.vimrc
  1  " ========================================
  2  "
  3  "           _____                         
  4  "    ___   ____(_)______ _________________
  5  "   ___ | / /_  /__  __ `__ \_  ___/  ___/
  6  " _____ |/ /_  / _  / / / / /  /   / /__  
  7  " _(_)____/ /_/  /_/ /_/ /_//_/    \___/  
  8  "
  9  " Maintainer: sideseal
 10  " Last Modified: 2023-01-13 11:47:33
 11  " ========================================
 12  
 13  autocmd VimEnter * so /usr/share/vim/vimrc
 14  
 15  " 1. General setup
 16  set nocompatible
 17  syntax enable
 18  if has ('termguicolors')
 19  	set termguicolors
 20  	set t_Co=256
 21  endif
 22  " darkblue, murphy, slate,
 23  " colorscheme borlandp
 24  hi clear
 25  " set background=dark
 26  colorscheme defnoche
 27  
 28  set number
 29  set nuw=5
 30  set relativenumber
 31  set title
 32  set cc=80
 33  set showtabline=2
 34  set laststatus=2
 35  " statusline settings >_<
 36  " --------------------------------------------
 37  set statusline=
 38  set statusline +=\ %n\ 		"buffer number
 39  set statusline +=%{&ff}		"file format
 40  set statusline +=%y		"file type
 41  set statusline +=\ %<%F		"full path
 42  set statusline +=%m		"modified flag
 43  set statusline +=%=%5l		"current line
 44  set statusline +=/%L		"total lines
 45  set statusline +=%4v\ 		"virtual column number
 46  set statusline +=0x%04B\ 	"character under cursorset showcmd
 47  " hi Statusline ctermbg=lightgreen ctermfg=black
 48  " --------------------------------------------
 49  set wildmenu
 50  set wildmode=longest,list
 51  set ruler
 52  set showcmd
 53  set nobackup
 54  set noswapfile
 55  set noerrorbells visualbell t_vb=
 56  set vb
 57  set mouse+=a
 58  set noimd
 59  set splitright
 60  set splitbelow
 61  set backspace=indent,eol,start
 62  set hidden
 63  set history=1000
 64  
 65  set ve+=onemore
 66  noremap $ $l
 67  
 68  set wrap
 69  set linebreak
 70  " set breakindentopt=shift:2,min:40,sbr
 71  set showbreak=↳
 72  set breakindent
 73  
 74  set clipboard=unnamed
 75  nnoremap y "*y
 76  nnoremap p "*p
 77  nnoremap Y y$
 78  nnoremap P p$
 79  set timeout timeoutlen=200
 80  
 81  augroup markdown
 82  	autocmd!
 83  	autocmd BufRead,BufNew *.md setf markdown
 84  augroup END
 85  set nofoldenable
 86  
 87  set hlsearch
 88  set incsearch
 89  " hi Search ctermbg=120 ctermfg=236 guibg=#87FF87 guifg=#303030
 90  set showmatch
 91  " hi MatchParen cterm=bold ctermbg=120 ctermfg=236 term=bold guibg=#87FF87 guifg=#303030
 92  set ignorecase
 93  set smartcase
 94  set nows
 95  nnoremap <ESC><ESC> :noh<return>
 96  
 97  filetype indent plugin on
 98  set autoindent
 99  set smartindent
100  set cindent
101  set smarttab
102  set tabstop=4
103  set shiftwidth=4
104  set noexpandtab
105  set fileencodings=utf-8,euc-kr
106  set fencs=ucs-bom,utf-8,euc-kr
107  set guifont=D2Coding:h12:cHANGEUL:qDEFAULT
108  set guifont=D2Coding:h12:cANSI:qDEFAULT
109  set guifontwide=D2Coding:h14
110  set list
111  " set listchars=tab:•·,trail:─,space:␣,eol:$
112  set listchars=tab:•·,trail:─
113  " hi NonText ctermfg=darkgrey guifg=grey70
114  " hi SpecialKey ctermfg=darkgrey guifg=grey70
115  hi NonText ctermfg=Black ctermbg=Black guifg=Black guibg=Black
116  hi SpecialKey ctermfg=Gray guifg=Gray
117  
118  
119  nnoremap k gk
120  nnoremap j gj
121  nnoremap <UP>	gk
122  nnoremap <DOWN>	gj
123  
124  " 
125  " set cursorline
126  " set cursorlineopt=number
127  " hi CursorLineNr cterm=bold
128  " 
129  " autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=1\x7"
130  " let &t_SI.="\e[5 q" "SI = INSERT mode
131  " let &t_SR.="\e[4 q" "SR = REPLACE mode
132  " let &t_EI.="\e[5 q" "EI = NORMAL mode (ELSE)
133  " set ttimeout
134  " set ttimeoutlen=1
135  " set ttyfast
136  
137  
138  " 2. Personal settings
139  
140  " command TT :vsplit output.txt | :split input.txt | :vertical resize 40<CR>
141  " nnoremap cc :execute '!make; ./app.out < input.txt > output.txt'<CR>
142  " nnoremap pp :execute '!python main.py < input.txt > output.txt'<CR>
143  
144  nnoremap HH :Stdheader<CR>
145  
146  set autoread
147  au CursorHold * checktime
148  
149  let mapleader = "g"
150  noremap <leader>1 1gt
151  noremap <leader>2 2gt
152  noremap <leader>3 3gt
153  noremap <leader>4 4gt
154  noremap <leader>5 5gt
155  noremap <leader>6 6gt
156  noremap <leader>7 7gt
157  noremap <leader>8 8gt
158  noremap <leader>9 9gt
159  noremap <leader>h :tabmove -1<CR>
160  nnoremap <leader>l :tabmove +1<CR>
161  noremap <leader>0 :tablast<CR>
162  
163  " let mapleader = "w"
164  " nmap <leader>h :vertical resize -5<CR>
165  " nmap <leader>l :vertical resize +5<CR>
166  " nmap <leader>k :resize +5<CR>
167  " nmap <leader>j :resize -5<CR>
168  
169  " netwr setting moves like NERDTree!
170  " --------------------------------------------
171  let g:netrw_sort_sequence = '[\/]$,*'
172  let g:netrw_banner = 0
173  let g:netrw_liststyle = 3
174  let g:netrw_browse_split = 3
175  let g:netrw_alto = 1
176  let g:netrw_altv = 1
177  let g:netrw_winsize = 20
178  let g:netrw_fastbrowse = 0
179  let g:netrw_special_syntax = 1
180  nnoremap <silent> <TAB><TAB> : Vexplore %:p:h<CR>
181  autocmd FileType netrw nnoremap <buffer> <silent> <TAB><TAB> :bd<CR>
182  
183  autocmd filetype netrw call Netrw_mappings()
184  function! Netrw_mappings()
185  	noremap <buffer>% :call CreateInPreview()<CR>
186  endfunction
187  function! CreateInPreview()
188  	let l:filename = input("please enter filename: ")
189  	execute 'silent !touch ' . b:netrw_curdir.'/'.l:filename 
190  	redraw!
191  endf
192  autocmd FileType netrw setl bufhidden=wipe
193  function! CloseNetrw() abort
194    for bufn in range(1, bufnr('$'))
195      if bufexists(bufn) && getbufvar(bufn, '&filetype') ==# 'netrw'
196        silent! execute 'bwipeout ' . bufn
197        if getline(2) =~# '^" Netrw '
198          silent! bwipeout
199        endif
200        return
201      endif
202    endfor
203  endfunction
204  augroup closeOnOpen
205    autocmd!
206    autocmd BufWinEnter * if getbufvar(winbufnr(winnr()), "&filetype") != "netrw"|call CloseNetrw()|endif
207  aug END
208  " --------------------------------------------
209  
210  if has('persistent_undo')
211      let s:vimDir = '$HOME/.vim'
212      let &runtimepath.=','.s:vimDir
213      let s:undoDir = expand(s:vimDir . '/undodir')
214  
215      call system('mkdir ' . s:vimDir)
216      call system('mkdir ' . s:undoDir)
217  
218      let &undodir = s:undoDir
219      set undofile
220  endif
221  set undolevels=1000
222  
223  " ---------------------------------------------
224  
225  let g:markdown_fenced_languages = ['html', 'python', 'c', 'js=javascript', 'sh=bash', 'zsh', 'css', 'xml']
226  hi link markdownItalic Normal
227  hi link markdownError Normal
228  set maxmempattern=5000
229  
230  autocmd BufWritePre ~/.vimrc :1,10s/^\" Last Modified: \zs.*$/\=strftime('%Y-%m-%d %H:%M:%S')/
231  
232  " go to library functions
233  " gf & ctrl-O
234  "set path+=/usr/local/include/**2
235  "set path+=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/**2
236  "set path+=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/**2
237  "set path+=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/**2
238  "set path+=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/**2
239  "set path+=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/**2
240  
241  " Update path with the preprocessor's #include search paths. The C search
242  " paths are a subset of the C++ search paths, so they don't have to be
243  " additionally included.
244  "
245  " if has('unix') && executable('gcc')
246  "   let s:expr = 'gcc -Wp,-v -x c++ - -fsyntax-only 2>&1 </dev/null'
247  "   let s:lines = systemlist(s:expr)
248  "   if v:shell_error ==# 0
249  "     for s:line in s:lines
250  "       if match(s:line, '^ ') ==# -1 | continue | endif
251  "       let s:include = substitute(s:line, '^ ', '', '')
252  "       " Remove ' (framework directory)' suffix (applicable on macOS).
253  "       if match(s:include, ' (framework directory)$') && !isdirectory(s:include)
254  "         let s:include = substitute(s:include, ' (framework directory)$', '', '')
255  "       endif
256  "       if !isdirectory(s:include) | continue | endif
257  "       " Escape the path, including additional handling for spaces and commas.
258  "       let s:include = fnameescape(s:include)
259  "       let s:include = substitute(s:include, ',', '\\\\,', 'g')
260  "       let s:include = substitute(s:include, '\ ', '\\\\ ', 'g')
261  "       execute 'set path+=' . s:include
262  "     endfor
263  "   endif
264  " endif
265  
266  function! CreateCenteredComment(comment)
267  	" Check if the comment fits within an 80-character comment.
268  	if len(a:comment) >= 74
269  		echoerr "Error: Comment is too long"
270  		return
271  	endif
272  
273  	" Save the current line number of the cursor.
274  	let current_line = line('.')
275  
276  	" Calculate the number of spaces on each side.
277  	let spaces_on_each_side = (74 - len(a:comment)) / 2
278  
279  	" If length of comment is even, distribute them equally.
280  	" If it's odd, add one more space to the right side.
281  	let left_spaces = spaces_on_each_side
282  	let right_spaces = spaces_on_each_side + (len(a:comment) % 2)
283  
284  	" The input comment to be inserted into the comment block.
285  	let inner_comment = '/* ' . repeat(' ', left_spaces) . a:comment .
286  						\ repeat(' ', right_spaces) . ' */'
287  
288  	" The beginning part of the comment block.
289  	let start_comment = '/* ' . repeat('*', 74) . ' */'
290  
291  	" The ending part of the comment block.
292  	let end_comment = '/* ' . repeat('*', 74) . ' */'
293  
294  	" Make the completed comment block at the current cursor position.
295  	call append(current_line, [start_comment, inner_comment, end_comment])
296  
297  	" Move the cursor down below the comment block and add an empty line.
298  	call append(current_line + 3, [''])
299  
300  	" Move the cursor down.
301  	call cursor(current_line + 4, 1)
302  endfunction
303  
304  " Set up a mapping to call the function.
305  nnoremap CC :call CreateCenteredComment(input('Enter comment: '))<CR>
306  
307  " 0. Tips to remember
308  " 10^w< 	-> decrease buffer size (vertically)
309  " 10^w>		-> increase buffer size (vertically)
310  " 10^w+		-> increase buffer size (horizontally)
311  " 10^w-		-> decrease buffer size (horizontally)
312  " ^w=		-> equal buffer size