chore: Update plugins to latest tag
[Vimrc.git] / vimrc
blobb9a9892a421521a237b3f9b70ba072a719237635
1 " encoding
2 set encoding=utf-8
3 scriptencoding utf-8
4 set termencoding=utf-8
5 set fileencoding=utf-8
6 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
7 set fileformats=unix,dos,mac
8 "set langmenu=zh_CN.UTF-8
9 "set helplang=cn
11 " Create needed folder
12 silent !mkdir -p $HOME/.vim/.swap
14 " Be iMproved, required
15 if &compatible
16     set nocompatible
17 endif
19 " MacOS & Unix italic
20 if has("macunix") || has("unix")
21     let &t_ZH="\e[3m"
22     let &t_ZR="\e[23m"
23 endif
25 " viminfo: remember certain things when we exit
26 set viminfo=%50,\"100,'20,/20,:50,h,f1,n$HOME/.vim/.swap/viminfo
27 "           |    |    |   |   |   | |  + viminfo file path
28 "           |    |    |   |   |   | + file marks 0-9,A-Z. 0 = not storeed
29 "           |    |    |   |   |   + disable hlsearch loading viminfo
30 "           |    |    |   |   + command line history saved
31 "           |    |    |   + search history saved
32 "           |    |    + file marks saved
33 "           |    + lines saved each register (old name for <, vi6,2)
34 "           + save/restore buffer list
37 " Global Settings
38 syntax on
39 set cursorline
40 "set cursorcolumn
41 set number
42 set title
43 "set t_ti= t_te=
44 set ruler                           " Always show current position
45 set virtualedit=onemore             " block, insert, all, onemore
46 set list!                           " Display unprintable characters
47 set listchars=tab:▸\ ,trail:•,extends:»,precedes:«
49 " Formatting, indentation and tabbing
50 set autoindent smartindent shiftround
51 set smarttab                        " Make <tab> and <backspace> smarter
52 set expandtab                       " expand tabs to spaces
53 "set noexpandtab
54 set tabstop=4 softtabstop=4 shiftwidth=4
55 set formatoptions-=t formatoptions+=croql
56 set modeline
58 " Misc
59 filetype plugin indent on
60 set hidden
61 set wildmenu                        " Enhanced completion hints in command
62 set wildmode=list:longest,full
63 set backspace=eol,start,indent      " Allow backspace
64 set complete=.,w,b,u,U,t,i,d        " Do lots of scanning on tab completion
65 set updatecount=100                 " Write swap file to disk every 100 chars
66 "set autochdir
67 set directory=$HOME/.vim/.swap      " Directory to use for the swap file
68 set diffopt=filler,iwhite
69 set history=10000
70 "set wrap
71 "set linebreak
72 set scrolloff=3
73 set visualbell t_vb=                " Disable error bells
74 set shortmess+=A                    " Always edit file
75 set nobackup                        " close backup files
76 set nowritebackup
77 set modifiable
78 "set laststatus=2
79 set mouse=a                         " Mouse wheel
80 let g:netrw_home=$HOME.'/.vim/.swap'
81 "set showcmd
82 set magic                           " For regular expressions
84 " Persistent undo
85 set undolevels=10000
86 if has("persistent_undo")
87     set undodir=$HOME/.vim/.swap
88     set undofile
89     set undoreload=10000
90 endif
92 " Search settings
93 set ignorecase                      " ignore case buring search
94 set smartcase                       " ignore 'ignorecase' when UPPer in search
95 set hlsearch                        " highlight search
96 set incsearch                       " do incremental searching
97 set showmatch                       " show matching parenthese
98 set wrapscan
100 set textwidth=0
101 autocmd FileType c,cmake,cpp,css,fortran,lisp,make,perl,scss,sh,vim
102             \ setlocal textwidth=78 colorcolumn=+1 wrap linebreak formatoptions+=t
103 autocmd FileType html setlocal shiftwidth=2 softtabstop=2 expandtab
105 " Auto reload when editing it
106 autocmd! bufwritepost .vimrc source %
108 " When opening a file, always jump to the last cursor position
109 autocmd BufReadPost *
110             \ if line("'\"") > 0 && line ("'\"") <= line("$") |
111             \ exe "normal g'\"zz" |
112             \ endif |
114 " After 4s of inactivity, check for file modifications on next keyrpress
115 autocmd CursorHold * checktime
117 " Cscope
118 if has("cscope")
119     set cscopetag
120     set csto=0
121     if filereadable("cscope.out")
122         cs add cscope.out
123     endif
124     set cscopeverbose
125 endif
127 " Keybindings
128 let mapleader=","
129 let localmapleader=","
131 " allow saving files as sudo
132 cmap w!! w !sudo tee > /dev/null %
134 " yank to clipboard
135 if has("clipboard")
136     " Copy, paste, undo, save, select all
137     vnoremap <C-c> "+y
138     nnoremap <C-V> "*p
139     nnoremap <C-z> u
140     nnoremap <C-s> :w!<cr>
141     nnoremap <C-a> ggVG
142     set clipboard=unnamed             " copy to the system clipboard
143     if has("unnamedplus")             " X11 support
144         set clipboard+=unnamedplus
145     endif
146 endif
148 " Follow scroll wheel to cursor
149 noremap <ScrollWheelUp>     3k
150 noremap <ScrollWheelDown>   3j
152 nnoremap <Leader>s  :%S/
153 vnoremap <Leader>s  :S/
155 vnoremap .  :normal .<cr>
156 vnoremap @  :normal! @
158 " up/down on displayed lines, not real lines. More useful than painful.
159 nnoremap k   gk
160 nnoremap j   gj
162 " toggle numbers
163 noremap <Leader>/  :nohlsearch<cr>
165 " tabprevious and tabnext
166 noremap <S-l>      :tabprevious<cr>
167 noremap <S-h>      :tabnext<cr>
169 " Do also cnext and cprev as a fallback
170 noremap <PageDown>  :lnext<cr>
171 noremap <PageUp>    :lprev<cr>
173 " Disable K for manpages - not used often and easy to accidentally hit
174 noremap K   k
176 " Resize window splits
177 nnoremap <C-k>  3<C-w>-
178 nnoremap <C-j>  3<C-w>+
179 nnoremap <C-h>  3<C-w><
180 nnoremap <C-l>  3<C-w>>
182 " Split window
183 nnoremap _  :split<cr>
184 nnoremap \| :vsplit<cr>
186 vnoremap s  :!sort<cr>
187 vnoremap u  :!sort -u<cr>
189 " colorscheme
191     if empty(glob('~/.vim/colors/lucario.vim'))
192         silent !curl -fLo $HOME/.vim/colors/lucario.vim --create-dirs
193                     \ https://raw.githubusercontent.com/raphamorim/lucario/master/colors/lucario.vim
194     endif
195     colorscheme lucario
196     hi CursorLineNr ctermfg=NONE ctermbg=236 cterm=bold guifg=NONE guibg=#405160 gui=NONE
197     hi SpecialKey   ctermfg=NONE ctermbg=NONE cterm=NONE guifg=#61bbc8 guibg=NONE gui=NONE
198     hi Comment      ctermfg=44 ctermbg=NONE cterm=italic guifg=#5c98cd guibg=NONE gui=italic
199     hi clear SignColumn
200 catch
201     colorscheme default
202 endtry
204 " Load plug.vim
205 silent! so $HOME/.vim/plugrc.vim
207 " vim: set et fenc=utf-8 ff=unix sts=4 sw=4 ts=4 :