-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
212 lines (166 loc) · 6.44 KB
/
vimrc
File metadata and controls
212 lines (166 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" preamble "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
" Necessary for Vundle, should be turned on after plugins setup
filetype off
" Use space as leader key
nnoremap <space> <nop>
let mapleader = "\<space>"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Color Scheme "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable
set t_Co=256
" Source: https://github.com/joshdick/dotfiles/blob/main/vim.symlink/config/settings/colorscheme.vim#L11
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
if (has("termguicolors"))
if !empty($TMUX)
"Set Vim-specific sequences for RGB colors; only seems to be needed for Vim 8 running inside tmux with $TERM=tmux
"Found at < https://github.com/vim/vim/issues/993#issuecomment-255651605 >
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors
endif
"onedark setup {{{
"source: https://github.com/joshdick/dotfiles/blob/main/vim.symlink/config/settings/colorscheme.vim#L23
"onedark.vim override: Don't set a background color when running in a terminal;
"just use the terminal's background color
if (has("autocmd") && !has("gui_running"))
augroup colors
autocmd!
let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16": "7"}
autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) "No `bg` setting
augroup END
endif
"colorscheme onedark
"}}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vimrc augroup "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TODO: This custom group should use more precisely
augroup vimrc
" Automatically delete trailing DOS-returns and whitespace on file open and write.
autocmd BufRead,BufWritePre,FileWritePre * silent! %s/[\r \t]\+$//
augroup END
" autocmd! vimrc bufwritepost .vimrc source %
"" Commenting blocks of code
autocmd FileType c,cpp,m,java,scala,swift let b:comment_leader = '// '
autocmd FileType sh,ruby,python let b:comment_leader = '# '
autocmd FileType conf,fstab let b:comment_leader = '# '
autocmd FileType tex let b:comment_leader = '% '
autocmd FileType vim let b:comment_leader = '" '
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General settings "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set number
if has('unnamedplus')
" By default, Vim will not use the system clipboard when yanking/pasting to
" the default register. This option makes Vim use the system default
" clipboard.
" Note that on X11, there are _two_ system clipboards: the "standard" one, and
" the selection/mouse-middle-click one. Vim sees the standard one as register
" '+' (and this option makes Vim use it by default) and the selection one as
" '*'.
" See :h 'clipboard' for details.
set clipboard=unnamedplus,unnamed
else
" Vim now also uses the selection system clipboard for default yank/paste.
set clipboard+=unnamed
endif
set backspace=indent,eol,start
set exrc
set secure
set autoread
" Tabulation
set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround
set expandtab
" Indentation
set nowrap
set autoindent
set smartindent
set colorcolumn=120
highlight ColorColumn ctermbg=222
set showmatch
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
set showcmd
set ruler
set rulerformat=%-13.(%l,%c%V%)\ %P
set textwidth=120
set wildmenu
set wildmode=longest:list,full
set listchars=tab:▸\ ,eol:¬
" The order of using encodings and files formats
set ffs=unix,dos,mac
set fencs=utf-8,cp1251,koi8-r,ucs-2,cp-866
" Set up mouse in all vim modes
if has('mouse')
set mouse=a
endif
" macOS only
if has("mac") || has("macunix")
set ambiwidth=double
endif
set cursorline
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Keybindings "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enter (make new line and get into `insert` mode)
nnoremap <Enter> o<Esc>
" Ctrl+s (fast saving)
nnoremap <silent> <C-s> <esc>:w<CR>
inoremap <silent> <C-s> <esc>:w<CR>
" leader+s/+v (Horizontal/Vertical window split)
nnoremap <leader>s :split<CR>
nnoremap <leader>v :vsplit<CR>
" Create / Navigate through Tabs
nnoremap <C-t> :tabnew<CR>
inoremap <C-t> <Esc>:tabnew<CR>
nnoremap <C-]> :tabnext<CR>
inoremap <C-]> <Esc>:tabnext<CR>i
" `Ctrl-[` in ViM the same as `Esc`.
" see comments: https://vi.stackexchange.com/questions/31004/vim-shortcut-for-tabprevious-change-opened-file-on-start
"nnoremap <C-[> :tabprevious<CR>
"inoremap <C-[> <Esc>:tabprevious<CR>i
" Jump to bottom/top/left/rigth split
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
nnoremap <silent> <C-u> :<C-u>Update<CR>
" inoremap <c-s> <c-o>:Update<CR>
" Tab/Shift-Tab mapping for each Vim mode
nnoremap <Tab> >>
nnoremap <S-Tab> <<
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
inoremap <S-Tab> <C-D>
" basic Vim grep
nnoremap gr :grep <cword> *<CR>
nnoremap Gr :grep <cword> %:p:h/*<CR>
nnoremap gR :grep '\b<cword>\b' *<CR>
nnoremap GR :grep '\b<cword>\b' %:p:h/*<CR>
" manual formatting of paragraphs
vmap Q gq
nmap Q gqap
" select ALL
map <silent> <C-A> ggVG
" cancel searching highlight
nnoremap ; :nohlsearch<CR>
noremap <silent> <leader>/ :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
noremap <silent> <leader>\ :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
" <leader>V reloads it and makes all changes active (file has to be saved first)
noremap <silent> <leader>R :source $MYVIMRC<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" Map +/- keys with leader to change vertical window size
" `=` symbol is easier to type rather that `+`
map <leader>= :vertical res +1<CR>
map <leader>- :vertical res -1<CR>