.vimrc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  3. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  4. """ """
  5. """ """
  6. """ In the name of Allah, the most Gracious, the most Merciful. """
  7. """ """
  8. """ ▓▓▓▓▓▓▓▓▓▓ """
  9. """ ░▓ Author ▓ Abdullah <https://abdullah.today> """
  10. """ ░▓▓▓▓▓▓▓▓▓▓ """
  11. """ ░░░░░░░░░░ """
  12. """ """
  13. """ ░█▀█░█░█░▀█▀░█▄█ """
  14. """ ░█░█░▀▄▀░░█░░█░█ """
  15. """ ░▀░▀░░▀░░▀▀▀░▀░▀ """
  16. """ """
  17. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  18. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  19. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  20. " Install vim-plug
  21. if empty(glob('~/.vim/autoload/plug.vim'))
  22. silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
  23. \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  24. endif
  25. "
  26. "" Run PlugInstall if there are missing plugins
  27. autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
  28. \| PlugInstall --sync | source $MYVIMRC
  29. \| endif
  30. "
  31. "" sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
  32. "
  33. "" Call vim-plug
  34. "
  35. "" Directory to save plugins
  36. "
  37. call plug#begin('~/.vim/plugged')
  38. "
  39. "" Plugins
  40. "
  41. Plug 'ryanoasis/vim-devicons' | Plug 'neoclide/coc.nvim', { 'branch': 'release' } | Plug 'honza/vim-snippets' | Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes' | Plug 'neoclide/coc-snippets' | Plug 'dylanaraps/wal' | Plug 'jiangmiao/auto-pairs' | Plug 'dkarter/bullets.vim'
  42. "
  43. "" Initialize vim-plug
  44. "
  45. call plug#end()
  46. "
  47. " Use vim settings rather than vi
  48. if &compatible
  49. set nocompatible
  50. endif
  51. " vim bullets for .md, .txt, and gitcommit
  52. let g:bullets_enabled_file_types = ['markdown', 'text', 'gitcommit', 'mail']
  53. " Show relative numbers
  54. set rnu nu
  55. " Set colorscheme
  56. color molokai
  57. " Set status line
  58. set laststatus=2
  59. set statusline=
  60. " Show file path
  61. set statusline+=%#Question#
  62. set statusline+=%f
  63. " Show current mode
  64. let g:currentmode={
  65. \ 'n' : 'NORMAL ',
  66. \ 'v' : 'VISUAL ',
  67. \ 'V' : 'V·Line ',
  68. \ '' : 'V·Block ',
  69. \ 'i' : 'INSERT ',
  70. \ 'R' : 'R ',
  71. \ 'Rv' : 'V·Replace ',
  72. \ 'c' : 'Command ',
  73. \}
  74. set statusline+=%#LineNr#
  75. set statusline+=\ %{toupper(g:currentmode[mode()])}
  76. set statusline+=%{&paste?'[paste]':''}
  77. set statusline+=\ %m
  78. set statusline+=%#MoreMsg#
  79. set statusline+=%r
  80. set statusline+=%#StatusLine#
  81. set statusline+=%=
  82. set statusline+=%#CursorColumn#
  83. set statusline+=%#Constant#
  84. set statusline+=\ %y
  85. set statusline+=%#PreProc#
  86. set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
  87. set statusline+=%#Tag#
  88. set statusline+=\ [%{&fileformat}\]
  89. set statusline+=%#Debug#
  90. set statusline+=\ %p%%
  91. set statusline+=%#Number#
  92. set statusline+=\ %l:%c
  93. function! SaveIfUnsaved()
  94. if &modified
  95. :silent! w
  96. endif
  97. endfunction
  98. " w!! to write file as root
  99. cmap w!! %!sudo tee > /dev/null %
  100. " No comments with o
  101. set formatoptions-=o
  102. " au FocusLost,BufLeave * :call SaveIfUnsaved()
  103. au FocusGained,BufEnter * :silent! !
  104. set ruler
  105. if &diff
  106. highlight! link DiffText MatchParen
  107. else
  108. " setup for non-diff mode
  109. endif
  110. " Sessions management
  111. " No help windows
  112. set sessionoptions-=help
  113. set sessionoptions-=curdir
  114. silent! set numberwidth=4
  115. if &t_Co > 2 || has("gui_running")
  116. set hlsearch
  117. endif
  118. autocmd! bufwritepost $HOME/.Xresources !xrdb -load $HOME/.Xresources
  119. autocmd! bufwritepost $HOME/.zshrc !source $HOME/.zshrc
  120. autocmd! bufwritepost $HOME/.config/sxhkd/sxhkdrc !pkill -USR1 -x sxhkd
  121. autocmd! bufwritepost $HOME/cfg/sxhkd/.config/sxhkd/sxhkdrc !pkill -USR1 -x sxhkd
  122. autocmd! bufwritepost $HOME/cfg/zsh/.zsh/custom-alias !source $HOME/.zsh/custom-alias
  123. autocmd! bufwritepost $HOME/cfg/polybar/.config/polybar/*.{conf,ini} !bspc wm -r >/dev/null 2>&1
  124. autocmd! bufwritepost $HOME/cfg/bspwm/.config/bspwm/bspwmrc !bspc wm -r >/dev/null 2>&1
  125. autocmd! bufwritepost $HOME/cfg/etc/.local/bin/mypanel !pkill mypanel && $HOME/.local/bin/mypanel & disown
  126. autocmd! bufwritepost $HOME/cfg/sway/.config/sway/config !swaymsg reload
  127. set nocp
  128. filetype on
  129. au BufNewFile,BufRead *Pkgfile set filetype=sh
  130. set textwidth=80
  131. if !&scrolloff
  132. set scrolloff=3
  133. endif
  134. if !&sidescrolloff
  135. set sidescrolloff=5
  136. endif
  137. set foldlevel=4
  138. set foldmethod=marker
  139. set foldmarker=<<<,>>>
  140. filetype plugin indent on
  141. set showmode
  142. set fo+=w
  143. set ai
  144. set sc
  145. if has('reltime')
  146. set incsearch
  147. endif
  148. "set nrformats=octal
  149. set nrformats=bin,hex,unsigned
  150. set completeopt=menuone
  151. set ignorecase
  152. set wrapscan
  153. set magic
  154. set gdefault
  155. com! -complete=file -bang -nargs=? W :w<bang> <args>
  156. set smartcase
  157. set cursorcolumn
  158. "set colorcolumn=+1
  159. set cursorline
  160. hi ColorColumn guifg=#232526 guibg=#F92672
  161. hi CursorColumn guifg=white guibg=#2b3f4a
  162. set noexpandtab
  163. set backspace=indent,eol,start
  164. if has("syntax")
  165. syntax on
  166. syntax sync minlines=200
  167. endif
  168. if has('mouse') | set mouse=a | endif
  169. let mapleader=" "
  170. set hidden
  171. set autoread
  172. set history=10000
  173. filetype plugin indent on
  174. set linebreak
  175. set display+=lastline
  176. set display+=truncate
  177. set display+=uhex
  178. silent! set listchars=eol:¬,tab:→.,extends:»,precedes:«,trail:•
  179. set list
  180. set wrap
  181. set tabstop=8
  182. set smarttab copyindent preserveindent
  183. set shiftwidth=4
  184. set softtabstop=4
  185. set expandtab
  186. retab
  187. set clipboard=unnamed,unnamedplus
  188. set ttyfast
  189. set smartindent
  190. set wildmenu
  191. silent! set wildignorecase
  192. set noerrorbells visualbell t_vb=
  193. set shortmess+=I
  194. set autoindent
  195. set nocindent
  196. set cinkeys=0{,0},0),:,!,o,O,e
  197. set formatoptions=tcrqnjw
  198. set comments-=:%
  199. set comments-=:XCOMM
  200. set lazyredraw
  201. set noshowmatch
  202. if has("unix")
  203. if has("nvim")
  204. set undofile
  205. else
  206. silent! set undodir=~/.vim/undodir//
  207. silent! set undofile
  208. endif
  209. endif
  210. set noshowmode
  211. set viminfo='10,\"100,:20,%,n~/.viminfo
  212. autocmd BufWritePre *.c,*.cpp,*.cc,*.h,*.sh,*.hpp,*.py,*.m,*.mm :%s/\s\+$//e
  213. set modeline
  214. set nobackup
  215. set showcmd
  216. set whichwrap=b,s,<,>,[,]
  217. set splitbelow splitright
  218. set tabpagemax=20
  219. if &t_Co > 16
  220. setl cursorline
  221. au WinEnter * setl cursorline
  222. au WinLeave * setl nocursorline
  223. au FocusGained * setl cursorline
  224. au FocusLost * setl nocursorline
  225. endif
  226. hi CursorLine guifg=white guibg=#2b3f4a
  227. let g:instant_markdown_browser = "/usr/bin/google-chrome-stable --new-window"
  228. let g:instant_markdown_logfile = '/tmp/instant_markdown.log'
  229. let g:instant_markdown_port = 47479
  230. let g:powerline_pycmd = 'py3'
  231. "let g:ycm_autoclose_preview_window_after_completion = 1
  232. "map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
  233. let g:airline#extensions#tabline#enabled = 1
  234. let g:airline#extensions#ale#enabled = 1
  235. let g:ale_sign_error = '●'
  236. let g:ale_sign_warning = '.'
  237. let g:airline#extensions#tabline#formatter = 'default'
  238. let g:airline_powerline_fonts = 1
  239. "
  240. if !exists('g:airline_symbols')
  241. let g:airline_symbols = {}
  242. endif
  243. "
  244. "" unicode symbols
  245. let g:airline_left_sep = '»'
  246. let g:airline_left_sep = '▶'
  247. let g:airline_right_sep = '«'
  248. let g:airline_right_sep = '◀'
  249. let g:airline_symbols.linenr = '␊'
  250. let g:airline_symbols.linenr = '␤'
  251. let g:airline_symbols.linenr = '¶'
  252. let g:airline_symbols.branch = '⎇'
  253. let g:airline_symbols.paste = 'ρ'
  254. let g:airline_symbols.paste = 'Þ'
  255. let g:airline_symbols.paste = '∥'
  256. let g:airline_symbols.whitespace = 'Ξ'
  257. "" airline symbols
  258. let g:airline_left_sep = ''
  259. let g:airline_left_alt_sep = ''
  260. let g:airline_right_sep = ''
  261. let g:airline_right_alt_sep = ''
  262. let g:ale_fix_on_save = 1
  263. let g:airline_symbols.branch = ''
  264. let g:airline_symbols.readonly = ''
  265. let g:airline_symbols.linenr = ''
  266. noremap <leader>u :w \| startinsert \| term urlview %<CR>
  267. map <leader>n :CocCommand explorer<CR>
  268. " comment out current line
  269. map <leader>c 0i# <ESC>
  270. nnoremap ; :
  271. nnoremap K <nop>
  272. nnoremap q :q
  273. nnoremap qq :q!<CR>
  274. nnoremap Q q
  275. inoremap # #
  276. autocmd BufEnter *.md exe 'noremap <F5> :!google-chrome-stable %:p<CR>'
  277. au BufNewFile,BufRead /dev/shm/gopass.* setlocal noswapfile nobackup noundofile
  278. au BufNewFile,BufRead /dev/shm/pass.* setlocal noswapfile nobackup noundofile
  279. "autocmd BufReadPost *
  280. " \ if line("'\"") > 0 && line("'\"") <= line("$") |
  281. " \ exe "normal! g`\"" |
  282. " \ endif
  283. autocmd BufReadPost *
  284. \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~#'commit'
  285. \ | exe "normal! g`\""
  286. \ | endif
  287. function! ResCur()
  288. if line("'\"") <= line("$")
  289. normal! g`"
  290. return 1
  291. endif
  292. endfunction
  293. function! DeleteFunctionUnderCursor()
  294. let line = getline('.')
  295. normal diwxml
  296. let i = 1
  297. let c = 1
  298. while i <= strlen(line)
  299. let char = getline('.')[col('.') - 1]
  300. if (char == '(')
  301. let c += 1
  302. elseif (char == ')')
  303. let c -= 1
  304. endif
  305. if (c == 0)
  306. normal x`l
  307. break
  308. endif
  309. normal l
  310. let i += 1
  311. endwhile
  312. endfunc
  313. command! -range=% DeleteFunctionUnderCursor <line1>,<line2>call DeleteFunctionUnderCursor()
  314. function! ToggleNumber()
  315. if(&relativenumber == 1)
  316. set norelativenumber
  317. set number
  318. else
  319. set relativenumber
  320. endif
  321. endfunc
  322. command! ToggleNumber call ToggleNumber()
  323. if !exists(":DiffOrig")
  324. command DiffOrig vert new | set bt=nofile | r ++edit | 0d_ | diffthis
  325. \ wincmd p | diffthis
  326. endif
  327. if $TERM !~# '^linux\|^Eterm|^screen-*|^tmux-*'
  328. set t_Co=8
  329. endif
  330. if has("nvim")
  331. silent! set guicursor=
  332. endif
  333. hi CursorLineNr cterm=NONE
  334. " duplicate lines
  335. function! HighlightRepeats() range
  336. let lineCounts = {}
  337. let lineNum = a:firstline
  338. while lineNum <= a:lastline
  339. let lineText = getline(lineNum)
  340. if lineText != ""
  341. let lineCounts[lineText] = (has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
  342. endif
  343. let lineNum = lineNum + 1
  344. endwhile
  345. exe 'syn clear Repeat'
  346. for lineText in keys(lineCounts)
  347. if lineCounts[lineText] >= 2
  348. exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
  349. endif
  350. endfor
  351. endfunction
  352. command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
  353. autocmd FileType python set breakindentopt=shift:4
  354. " comfortable navigation
  355. nnoremap k gk
  356. nnoremap j gj
  357. nnoremap <Up> gk
  358. nnoremap <Down> gj
  359. nnoremap <Tab> %
  360. vnoremap <Tab> %
  361. nnoremap <A-h> <C-w>h
  362. nnoremap <A-j> <C-w>j
  363. nnoremap <A-k> <C-w>k
  364. nnoremap <A-l> <C-w>l
  365. if has("nvim") || has("terminal")
  366. tnoremap <Esc> <C-\><C-n>
  367. endif
  368. nnoremap <Leader>l :ls<CR>:b<Space>
  369. nnoremap <Leader>b :bd<CR>
  370. nnoremap <Leader>h :nohlsearch<CR>
  371. nnoremap <Leader>t :terminal<CR>
  372. nnoremap <Leader>rw :%s/\<<C-r><C-w>\>/
  373. " sort CSS properties
  374. nnoremap <Leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR>
  375. " reselect pasted text
  376. nnoremap <Leader>v `[V`]
  377. " rewrap current paragraph
  378. nnoremap <Leader>w gq}
  379. " strip trailing whitespace
  380. nnoremap <Leader>W :%s/\s\+$//<CR>:let @/=""<CR>
  381. " fix application-numpad mode
  382. if !has("nvim")
  383. " (Vim 8.1) with Num Lock off, Num5 is parsed as individual commands
  384. map! <Esc>OE <Nop>
  385. endif
  386. set nottimeout
  387. "let g:python_host_prog = "/usr/bin/python2.7"
  388. let g:python3_host_prog = "/usr/bin/python3"
  389. function! s:check_back_space() abort
  390. let col = col('.') - 1
  391. return !col || getline('.')[col - 1] =~ '\s'
  392. endfunction
  393. inoremap <silent><expr> <Tab>
  394. \ pumvisible() ? "\<C-n>" :
  395. \ <SID>check_back_space() ? "\<Tab>" :
  396. \ coc#refresh()
  397. noremap <silent><expr> <TAB>
  398. \ pumvisible() ? coc#_select_confirm() :
  399. \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
  400. \ <SID>check_back_space() ? "\<TAB>" :
  401. \ coc#refresh()
  402. function! s:check_back_space() abort
  403. let col = col('.') - 1
  404. return !col || getline('.')[col - 1] =~# '\s'
  405. endfunction
  406. let g:coc_snippet_next = '<tab>'
  407. if has("autocmd")
  408. au BufNewFile,BufRead COMMIT_EDITMSG,git-rebase-todo
  409. \ setl nomodeline
  410. au BufNewFile,BufRead /etc/motd
  411. \ setl et
  412. au BufNewFile,BufRead authorized_keys*,known_hosts,id_*.pub
  413. \ setl ft=conf wrap nolinebreak
  414. au! BufNewFile */_posts/2*.html
  415. \ 0r %:h/_template.html
  416. if has("nvim")
  417. " Neovim 0.2.1: terminal buffers now have line numbers
  418. au! TermOpen * setl nonumber norelativenumber
  419. endif
  420. endif
  421. " some pastebins commands
  422. " for GUI apps like browsers, paste the URL with CTRL+v
  423. command! -range=% CL <line1>,<line2>w !curl -F 'clbin=<-' https://clbin.com | tr -d '\n' | xclip -i -selection clipboard
  424. " Another good pastebin same as CTRL+v paste.
  425. command! -range=% VP <line1>,<line2>w !curl -F 'text=<-' http://vpaste.net | tr -d '\n' | xclip -i -selection clipboard
  426. " pastebin ptpb is now down but is the best pastebin ever
  427. command! -range=% PB <line1>,<line2>w !curl -F 'c=@-' https://ptpb.pw/ | sed -n 's/^url: //p' | xclip
  428. command! -range=% TB <line1>,<line2>w !fb
  429. command! -range=% GT <line1>,<line2>w !gist -c -p -f %
  430. map <F3> :! ( urxvt & ) &>/dev/null &<CR><CR>
  431. " Run python code without exiting vim
  432. nmap <silent> <Leader>m :w<CR>:!clear && python % > /tmp/vim-py.out && cat /tmp/vim-py.out && rm -f /tmp/vim-py.out<CR>
  433. " Run bash code without exiting vim
  434. nmap <silent> <Leader>o :w<CR>:!clear && sh -x % > /tmp/vim-bash.out && cat /tmp/vim-bash.out && rm -f /tmp/vim-bash.out<CR>
  435. "
  436. " Json highlight comments
  437. autocmd FileType json syntax match Comment +\/\/.\+$+
  438. " For all text files, set textwidth to 78
  439. autocmd FileType text setlocal textwidth=78
  440. " UTF-8 support
  441. if has("multi_byte")
  442. if &termencoding == ""
  443. let &termencoding = "utf-8"
  444. endif
  445. set encoding=utf-8
  446. setglobal fileencoding=utf-8
  447. endif
  448. " Highlight comments italic
  449. highlight Comment cterm=italic
  450. if has('syntax') && has('eval')
  451. packadd! matchit
  452. endif
  453. vmap rot :!tr A-Za-z N-ZA-Mn-za-m<CR>
  454. vnoremap < <gv
  455. vnoremap > >gv
  456. nmap <leader>s :%s//g<Left><Left>
  457. set wildignore+=*.opus,*.flac,*.pdf,*.jpg,*.png,*.so,*.swp,*.zip,*.gzip,*.bz2,*.tar,*.xz,*.lrzip,*.lrz,*.mp3,*.ogg,*.mp4,*.gif,*.jpeg,*.webm
  458. " vim: set ft=vim :