.vimrc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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' | Plug 'fannheyward/coc-pyright'
  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/cfg/zsh/.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. autocmd! bufwritepost $HOME/cfg/herbstluftwm/.config/herbstluftwm/autostart !herbstclient reload
  128. set nocp
  129. filetype on
  130. au BufNewFile,BufRead *Pkgfile set filetype=sh
  131. set textwidth=120
  132. if !&scrolloff
  133. set scrolloff=3
  134. endif
  135. if !&sidescrolloff
  136. set sidescrolloff=5
  137. endif
  138. set foldlevel=4
  139. set foldmethod=marker
  140. set foldmarker=<<<,>>>
  141. filetype plugin indent on
  142. set showmode
  143. set fo+=w
  144. set ai
  145. set sc
  146. if has('reltime')
  147. set incsearch
  148. endif
  149. "set nrformats=octal
  150. set nrformats=bin,hex,unsigned
  151. set completeopt=menuone
  152. set ignorecase
  153. set wrapscan
  154. set magic
  155. set gdefault
  156. com! -complete=file -bang -nargs=? W :w<bang> <args>
  157. set smartcase
  158. set cursorcolumn
  159. "set colorcolumn=+1
  160. set cursorline
  161. hi ColorColumn guifg=#232526 guibg=#F92672
  162. hi CursorColumn guifg=white guibg=#2b3f4a
  163. set noexpandtab
  164. set backspace=indent,eol,start
  165. if has("syntax")
  166. syntax on
  167. syntax sync minlines=200
  168. endif
  169. if has('mouse') | set mouse=a | endif
  170. let mapleader=" "
  171. set hidden
  172. set autoread
  173. set history=10000
  174. filetype plugin indent on
  175. set linebreak
  176. set display+=lastline
  177. set display+=truncate
  178. set display+=uhex
  179. silent! set listchars=eol:¬,tab:→.,extends:»,precedes:«,trail:•
  180. set list
  181. set wrap
  182. set tabstop=8
  183. set smarttab copyindent preserveindent
  184. set shiftwidth=4
  185. set softtabstop=4
  186. set expandtab
  187. retab
  188. set clipboard=unnamed,unnamedplus
  189. set ttyfast
  190. set smartindent
  191. set wildmenu
  192. silent! set wildignorecase
  193. set noerrorbells visualbell t_vb=
  194. set shortmess+=I
  195. set autoindent
  196. set nocindent
  197. set cinkeys=0{,0},0),:,!,o,O,e
  198. set formatoptions=tcrqnjw
  199. set comments-=:%
  200. set comments-=:XCOMM
  201. set lazyredraw
  202. set noshowmatch
  203. if has("unix")
  204. if has("nvim")
  205. set undofile
  206. else
  207. silent! set undodir=~/.vim/undodir//
  208. silent! set undofile
  209. endif
  210. endif
  211. set noshowmode
  212. set viminfo='10,\"100,:20,%,n~/.viminfo
  213. autocmd BufWritePre *.c,*.cpp,*.cc,*.h,*.sh,*.hpp,*.py,*.m,*.mm :%s/\s\+$//e
  214. set modeline
  215. set nobackup
  216. set cmdheight=2
  217. set updatetime=300
  218. set showcmd
  219. set whichwrap=b,s,<,>,[,]
  220. set splitbelow splitright
  221. set tabpagemax=20
  222. if &t_Co > 16
  223. setl cursorline
  224. au WinEnter * setl cursorline
  225. au WinLeave * setl nocursorline
  226. au FocusGained * setl cursorline
  227. au FocusLost * setl nocursorline
  228. endif
  229. hi CursorLine guifg=white guibg=#2b3f4a
  230. let g:instant_markdown_browser = "/usr/bin/google-chrome-stable --new-window"
  231. let g:instant_markdown_logfile = '/tmp/instant_markdown.log'
  232. let g:instant_markdown_port = 47479
  233. let g:powerline_pycmd = 'py3'
  234. "let g:ycm_autoclose_preview_window_after_completion = 1
  235. "map <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
  236. let g:airline#extensions#tabline#enabled = 1
  237. let g:airline#extensions#ale#enabled = 1
  238. let g:ale_sign_error = '●'
  239. let g:ale_sign_warning = '.'
  240. let g:airline#extensions#tabline#formatter = 'default'
  241. let g:airline_powerline_fonts = 1
  242. "
  243. if !exists('g:airline_symbols')
  244. let g:airline_symbols = {}
  245. endif
  246. "
  247. "" unicode symbols
  248. let g:airline_left_sep = '»'
  249. let g:airline_left_sep = '▶'
  250. let g:airline_right_sep = '«'
  251. let g:airline_right_sep = '◀'
  252. let g:airline_symbols.linenr = '␊'
  253. let g:airline_symbols.linenr = '␤'
  254. let g:airline_symbols.linenr = '¶'
  255. let g:airline_symbols.branch = '⎇'
  256. let g:airline_symbols.paste = 'ρ'
  257. let g:airline_symbols.paste = 'Þ'
  258. let g:airline_symbols.paste = '∥'
  259. let g:airline_symbols.whitespace = 'Ξ'
  260. "" airline symbols
  261. let g:airline_left_sep = ''
  262. let g:airline_left_alt_sep = ''
  263. let g:airline_right_sep = ''
  264. let g:airline_right_alt_sep = ''
  265. let g:ale_fix_on_save = 1
  266. let g:airline_symbols.branch = ''
  267. let g:airline_symbols.readonly = ''
  268. let g:airline_symbols.linenr = ''
  269. noremap <leader>u :w \| startinsert \| term urlview %<CR>
  270. map <leader>n :CocCommand explorer<CR>
  271. " comment out current line
  272. map <leader>c 0i# <ESC>
  273. nnoremap ; :
  274. nnoremap K <nop>
  275. nnoremap q :q
  276. nnoremap qq :q!<CR>
  277. nnoremap Q q
  278. inoremap # #
  279. "nnoremap <silent> K :call ShowDocumentation()<CR>
  280. "function! ShowDocumentation()
  281. " if CocAction('hasProvider', 'hover')
  282. " call CocActionAsync('doHover')
  283. " else
  284. " call feedkeys('K', 'in')
  285. " endif
  286. "endfunction
  287. autocmd BufEnter *.md exe 'noremap <F5> :!google-chrome-stable %:p<CR>'
  288. au BufNewFile,BufRead /dev/shm/gopass.* setlocal noswapfile nobackup noundofile
  289. au BufNewFile,BufRead /dev/shm/pass.* setlocal noswapfile nobackup noundofile
  290. "autocmd BufReadPost *
  291. " \ if line("'\"") > 0 && line("'\"") <= line("$") |
  292. " \ exe "normal! g`\"" |
  293. " \ endif
  294. autocmd BufReadPost *
  295. \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~#'commit'
  296. \ | exe "normal! g`\""
  297. \ | endif
  298. function! ResCur()
  299. if line("'\"") <= line("$")
  300. normal! g`"
  301. return 1
  302. endif
  303. endfunction
  304. function! DeleteFunctionUnderCursor()
  305. let line = getline('.')
  306. normal diwxml
  307. let i = 1
  308. let c = 1
  309. while i <= strlen(line)
  310. let char = getline('.')[col('.') - 1]
  311. if (char == '(')
  312. let c += 1
  313. elseif (char == ')')
  314. let c -= 1
  315. endif
  316. if (c == 0)
  317. normal x`l
  318. break
  319. endif
  320. normal l
  321. let i += 1
  322. endwhile
  323. endfunc
  324. command! -range=% DeleteFunctionUnderCursor <line1>,<line2>call DeleteFunctionUnderCursor()
  325. function! ToggleNumber()
  326. if(&relativenumber == 1)
  327. set norelativenumber
  328. set number
  329. else
  330. set relativenumber
  331. endif
  332. endfunc
  333. command! ToggleNumber call ToggleNumber()
  334. if !exists(":DiffOrig")
  335. command DiffOrig vert new | set bt=nofile | r ++edit | 0d_ | diffthis
  336. \ wincmd p | diffthis
  337. endif
  338. if $TERM !~# '^linux\|^Eterm|^screen-*|^tmux-*'
  339. set t_Co=8
  340. endif
  341. if has("nvim")
  342. silent! set guicursor=
  343. endif
  344. hi CursorLineNr cterm=NONE
  345. " duplicate lines
  346. function! HighlightRepeats() range
  347. let lineCounts = {}
  348. let lineNum = a:firstline
  349. while lineNum <= a:lastline
  350. let lineText = getline(lineNum)
  351. if lineText != ""
  352. let lineCounts[lineText] = (has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
  353. endif
  354. let lineNum = lineNum + 1
  355. endwhile
  356. exe 'syn clear Repeat'
  357. for lineText in keys(lineCounts)
  358. if lineCounts[lineText] >= 2
  359. exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
  360. endif
  361. endfor
  362. endfunction
  363. command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
  364. autocmd FileType python set breakindentopt=shift:4
  365. " comfortable navigation
  366. nnoremap k gk
  367. nnoremap j gj
  368. nnoremap <Up> gk
  369. nnoremap <Down> gj
  370. nnoremap <Tab> %
  371. vnoremap <Tab> %
  372. nnoremap <A-h> <C-w>h
  373. nnoremap <A-j> <C-w>j
  374. nnoremap <A-k> <C-w>k
  375. nnoremap <A-l> <C-w>l
  376. if has("nvim") || has("terminal")
  377. tnoremap <Esc> <C-\><C-n>
  378. endif
  379. nnoremap <Leader>l :ls<CR>:b<Space>
  380. nnoremap <Leader>b :bd<CR>
  381. nnoremap <Leader>h :nohlsearch<CR>
  382. nnoremap <Leader>t :terminal<CR>
  383. nnoremap <Leader>rw :%s/\<<C-r><C-w>\>/
  384. " sort CSS properties
  385. nnoremap <Leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR>
  386. " reselect pasted text
  387. nnoremap <Leader>v `[V`]
  388. " rewrap current paragraph
  389. nnoremap <Leader>w gq}
  390. " strip trailing whitespace
  391. nnoremap <Leader>W :%s/\s\+$//<CR>:let @/=""<CR>
  392. " fix application-numpad mode
  393. if !has("nvim")
  394. " (Vim 8.1) with Num Lock off, Num5 is parsed as individual commands
  395. map! <Esc>OE <Nop>
  396. endif
  397. set nottimeout
  398. "let g:python_host_prog = "/usr/bin/python2.7"
  399. let g:python3_host_prog = "/usr/bin/python3"
  400. "inoremap <silent><expr> <Tab>
  401. " \ pumvisible() ? "\<C-n>" :
  402. " \ <SID>check_back_space() ? "\<Tab>" :
  403. " \ coc#refresh()
  404. "noremap <silent><expr> <TAB>
  405. " \ pumvisible() ? coc#_select_confirm() :
  406. " \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
  407. " \ <SID>check_back_space() ? "\<TAB>" :
  408. " \ coc#refresh()
  409. function! s:check_back_space() abort
  410. let col = col('.') - 1
  411. return !col || getline('.')[col - 1] =~# '\s'
  412. endfunction
  413. "let g:coc_snippet_next = '<tab>'
  414. if has("autocmd")
  415. au BufNewFile,BufRead COMMIT_EDITMSG,git-rebase-todo
  416. \ setl nomodeline
  417. au BufNewFile,BufRead /etc/motd
  418. \ setl et
  419. au BufNewFile,BufRead authorized_keys*,known_hosts,id_*.pub
  420. \ setl ft=conf wrap nolinebreak
  421. au! BufNewFile */_posts/2*.html
  422. \ 0r %:h/_template.html
  423. if has("nvim")
  424. " Neovim 0.2.1: terminal buffers now have line numbers
  425. au! TermOpen * setl nonumber norelativenumber
  426. endif
  427. endif
  428. " some pastebins commands
  429. " for GUI apps like browsers, paste the URL with CTRL+v
  430. command! -range=% CL <line1>,<line2>w !curl -F 'clbin=<-' https://clbin.com | tr -d '\n' | xclip -i -selection clipboard
  431. " Another good pastebin same as CTRL+v paste.
  432. command! -range=% VP <line1>,<line2>w !curl -F 'text=<-' http://vpaste.net | tr -d '\n' | xclip -i -selection clipboard
  433. " pastebin ptpb is now down but is the best pastebin ever
  434. command! -range=% PB <line1>,<line2>w !curl -F 'c=@-' https://ptpb.pw/ | sed -n 's/^url: //p' | xclip
  435. command! -range=% TB <line1>,<line2>w !fb
  436. command! -range=% GT <line1>,<line2>w !gist -c -p -f %
  437. map <F3> :! ( urxvt & ) &>/dev/null &<CR><CR>
  438. " Run python code without exiting vim
  439. nmap <silent> <Leader>m :w<CR>:!clear && python % > /tmp/vim-py.out && cat /tmp/vim-py.out && rm -f /tmp/vim-py.out<CR>
  440. " Run bash code without exiting vim
  441. 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>
  442. "
  443. " Json highlight comments
  444. autocmd FileType json syntax match Comment +\/\/.\+$+
  445. " For all text files, set textwidth to 78
  446. autocmd FileType text setlocal textwidth=78
  447. " UTF-8 support
  448. if has("multi_byte")
  449. if &termencoding == ""
  450. let &termencoding = "utf-8"
  451. endif
  452. set encoding=utf-8
  453. setglobal fileencoding=utf-8
  454. endif
  455. " Highlight comments italic
  456. highlight Comment cterm=italic
  457. if has('syntax') && has('eval')
  458. packadd! matchit
  459. endif
  460. vmap rot :!tr A-Za-z N-ZA-Mn-za-m<CR>
  461. vnoremap < <gv
  462. vnoremap > >gv
  463. nmap <leader>s :%s//g<Left><Left>
  464. set wildignore+=*.opus,*.flac,*.pdf,*.jpg,*.png,*.so,*.swp,*.zip,*.gzip,*.bz2,*.tar,*.xz,*.lrzip,*.lrz,*.mp3,*.ogg,*.mp4,*.gif,*.jpeg,*.webm
  465. " Highlight the symbol and its references when holding the cursor.
  466. "autocmd CursorHold * silent call CocActionAsync('highlight')
  467. " Symbol renaming.
  468. "nmap <leader>rn <Plug>(coc-rename)
  469. " Formatting selected code.
  470. "xmap <leader>f <Plug>(coc-format-selected)
  471. "nmap <leader>f <Plug>(coc-format-selected)
  472. " vim: set ft=vim :