-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimrc
More file actions
202 lines (166 loc) · 6.9 KB
/
Copy pathvimrc
File metadata and controls
202 lines (166 loc) · 6.9 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
"------------------------------------------------------------------------------
"# Options #-------------------------------------------------------------------
set nocompatible " disable vi-compatible mode
set encoding=utf-8
scriptencoding utf-8
filetype plugin indent on
" window & split behavior
set splitright " open vertical splits to the right
set splitbelow " open horizontal splits below
set scrolloff=5 " keep 5 lines visible above/below cursor
" display & visual
set number " show line numbers
set relativenumber " show relative line numbers
if has('termguicolors')
set termguicolors " enable 24-bit RGB colors
endif
set linebreak " wrap long lines at word boundaries
set textwidth=80 " wrap text at column 80
set laststatus=0 " hide the statusline
set noruler " /etc/vim/vimrc forces 'ruler' on, which would survive laststatus=0
set visualbell " use visual bell instead of beeping
set showmatch " briefly jump to matching bracket
syntax enable " enable syntax highlighting
" search behavior
set hlsearch " highlight all search matches
set incsearch " show search matches as you type
set ignorecase " case-insensitive search by default
set smartcase " case-sensitive search when query has uppercase
" indentation & tabs
set autoindent " copy indent from current line on newline
set smartindent " smart auto-indenting for new lines
set breakindent " preserve indent on wrapped lines
set tabstop=4 " how wide a tab *displays*
set shiftwidth=4 " how much >>, << indent by
set softtabstop=0 " no "soft tab" fakery, let tabstop govern
set noexpandtab " pressing <Tab> inserts a real tab char
set smarttab " Tab at line start uses shiftwidth/tabstop
" completion
set complete=.,w,b,u,t " sources for <C-n>/<C-p> completion
set completeopt=menuone,noselect
set pumheight=10 " popup menu height
" editor defaults
set undolevels=1000 " maximum undo levels
set grepprg=rg\ --vimgrep " use ripgrep for :grep
set shortmess+=I " suppress the intro message on startup
set guioptions-=e " disable GUI tab pages line
set backspace=indent,eol,start " allow backspace over everything
" visual noise
set list
set listchars=tab:▏\ ,trail:░,nbsp:░
" file explorer (netrw)
let g:netrw_banner = 0
let g:netrw_sort_options = "i"
let g:netrw_bufsettings = "noma nomod nu nobl nowrap ro rnu"
" load after the editor is up
augroup vimrc_late
autocmd!
autocmd VimEnter * set clipboard=unnamedplus | set rtp+=/opt/homebrew/opt/fzf
augroup END
"------------------------------------------------------------------------------
"# Default Override #----------------------------------------------------------
" NOTE: <leader> is the default backslash, same as in the lua config.
" NOTE: <M-...> maps need a terminal that sends real Alt (or Esc+key); they
" work out of the box in gvim/MacVim and most modern terminals.
" save, creating missing parent dirs (nvim's ':wq ++p'), then quit
nnoremap <silent> ZZ :call mkdir(expand('%:p:h'), 'p') <Bar> wq<CR>
nnoremap <silent> S "_d$a
nnoremap <silent> X "_x
nnoremap <silent> s "_d
xnoremap <silent> s "_d
nnoremap <silent> <Esc> <Esc>:noh<CR>
" Use 'c' to enter Visual Block mode
nnoremap <silent> c <C-v>
xnoremap <silent> c <C-v>
"------------------------------------------------------------------------------
"# cxxx #----------------------------------------------------------------------
" ctags
nnoremap <silent> <leader>td <C-]>
nnoremap <silent> <leader>tb <C-t>
nnoremap <silent> <leader>ts :tselect <C-r><C-w><CR>
nnoremap <silent> <leader>tl :tlist <C-r><C-w><CR>
nnoremap <silent> <leader>tt :tag <C-r><C-w><CR>
nnoremap <silent> <leader>tj :tnext<CR>
nnoremap <silent> <leader>tk :tprev<CR>
nnoremap <silent> <leader>t0 :tfirst<CR>
nnoremap <silent> <leader>t$ :tlast<CR>
nnoremap <silent> <leader>tx :tags<CR>
" quickfixes
nnoremap <silent> <leader>qo :copen<CR>
nnoremap <silent> <leader>qq :cclose<CR>
nnoremap <silent> <leader>ql :clist<CR>
nnoremap <silent> <leader>qj :cnext<CR>
nnoremap <silent> <leader>qk :cprev<CR>
nnoremap <silent> <leader>q0 :cfirst<CR>
nnoremap <silent> <leader>q$ :clast<CR>
"------------------------------------------------------------------------------
"# Windows #-------------------------------------------------------------------
" toggle color column
function! ToggleColumn() abort
if &l:colorcolumn ==# ''
setlocal colorcolumn=81,101
else
setlocal colorcolumn=
endif
endfunction
nnoremap <silent> <leader>l :call ToggleColumn()<CR>
" toggle horizontal/vertical panes
let s:pane_type = 'vertical'
function! RotatePanes() abort
if s:pane_type ==# 'horizontal'
let s:pane_type = 'vertical'
wincmd K
else
let s:pane_type = 'horizontal'
wincmd H
endif
endfunction
nnoremap <silent> <leader>w :call RotatePanes()<CR>
" explore and panes
nnoremap <silent> ZE :Ex<CR>
nnoremap <silent> ZH :vsplit <Bar> Explore<CR>
nnoremap <silent> ZV :split <Bar> Explore<CR>
" Move splits with <C-w>h/j/k/l instead of navigating
nnoremap <silent> <C-w>h <C-w>H
nnoremap <silent> <C-w>j <C-w>J
nnoremap <silent> <C-w>k <C-w>K
nnoremap <silent> <C-w>l <C-w>L
"------------------------------------------------------------------------------
"# Conveniences #--------------------------------------------------------------
command! -nargs=0 W w
command! -nargs=0 Wq wq
cnoremap w!! w !sudo tee > /dev/null %
" to whole file
nnoremap <silent> sA gg"_dG<CR>
nnoremap <silent> dA :%delete<CR>
nnoremap <silent> yA :%yank<CR>
nnoremap <silent> <leader>R gg"_dGp<CR>
nnoremap <silent> =A myLgg=G``zb`y<CR>:%s/ *$//g<CR>
" faster actions
nnoremap <silent> <space>/ /--#<CR> kztj<CR>
nnoremap <space>s :%s/
nnoremap <silent> <M-z> zfi{
nnoremap <silent> <M-Z> zo
nnoremap <silent> <M-j> <Esc>jzz<CR>
"------------------------------------------------------------------------------
"# Inserts #-------------------------------------------------------------------
" autoclose brackets: get in
inoremap <silent> <M-9> ()<Left>
inoremap <silent> <M-{> {}<Left>
inoremap <silent> <M-[> []<Left>
inoremap <silent> <M-"> ""<Left>
inoremap <silent> <M-'> ''<Left>
" autoclose brackets: stay out
inoremap <silent> <M-0> ()
inoremap <silent> <M-)> ( void )<CR>{<CR>}<Esc>O
inoremap <silent> <M-]> []
inoremap <silent> <M-}> {}
" common actions
inoremap <silent> <M-;> <Esc>A;
inoremap <silent> <M-=> <Space>==<Space>
inoremap <silent> <M-+> <Space>!=<Space>
" hjkl nav in insert mode
inoremap <silent> <M-h> <Left>
inoremap <silent> <M-j> <Down>
inoremap <silent> <M-k> <Up>
inoremap <silent> <M-l> <Right>