-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
350 lines (301 loc) · 11.9 KB
/
.vimrc
File metadata and controls
350 lines (301 loc) · 11.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
" ============================================================================
" Main vimrc file
" ============================================================================
" Create necessary directories if they don't exist
if !isdirectory(expand("~/.vim/plugin_configs"))
call mkdir(expand("~/.vim/plugin_configs"), "p")
endif
if !isdirectory(expand("~/.vim/modules"))
call mkdir(expand("~/.vim/modules"), "p")
endif
" Load plugins
if filereadable(expand("~/.vim/plugins.vim"))
source ~/.vim/plugins.vim
endif
" ============================================================================
" Basic Settings {{{
" ============================================================================
set nocompatible " Use Vim settings, rather than Vi settings
set encoding=utf-8 " Set default encoding
set fileformats=unix,dos,mac " Use Unix as the standard file type
" Indentation and tabs
set autoindent " Copy indent from current line when starting a new line
set cindent " Stricter rules for C programs
set expandtab " Use spaces instead of tabs
set smarttab " Be smart when using tabs
set shiftwidth=4 " Number of spaces to use for each step of (auto)indent
set softtabstop=4 " Number of spaces that a <Tab> counts for while editing
set tabstop=4 " Number of spaces that a <Tab> in the file counts for
" UI Configuration
set cursorline " Highlight the current line
set laststatus=2 " Always show the status line
set cmdheight=1 " Command bar height
set showcmd " Show incomplete commands
set showmatch " Show matching brackets
set number " Show line numbers
set ruler " Show current position
set wildmenu " Enhanced command line completion
set wildmode=list:longest " Complete files like a shell
set scrolloff=7 " Minimum number of lines to keep above/below cursor
set noshowmode " Don't show mode (using lightline instead)
set title " Set terminal title
set hidden " Allow buffer switching without saving
set virtualedit=block " Allow cursor to move where there is no text in visual block mode
set signcolumn=yes " Always show the signcolumn for git markers and LSP diagnostics
" Folding settings
set foldmethod=indent
set nofoldenable " Start with all folds open
set foldlevel=2 " When folding is enabled, fold at depth 2+
" Enable folding with the spacebar
nnoremap <space> za
" Netrw (built-in file explorer) configuration
let g:netrw_banner = 0 " Hide banner
let g:netrw_liststyle = 3 " Tree view
let g:netrw_browse_split = 4 " Open in previous window
let g:netrw_altv = 1 " Open splits to the right
let g:netrw_winsize = 25 " Width percentage
nnoremap <leader>e :Lexplore<CR>
" }}}
" ============================================================================
" Search Settings {{{
" ============================================================================
set hlsearch " Highlight search results
set incsearch " Incremental search
set ignorecase " Case-insensitive search
set smartcase " Override ignorecase when search pattern has uppercase
" Clear search highlighting with Enter
nnoremap <CR> :nohlsearch<CR>/<BS><CR>
" }}}
" ============================================================================
" Syntax and Colors {{{
" ============================================================================
syntax on " Enable syntax highlighting
set background=dark " Use dark background
" Configure true color support for terminal
if (empty($TMUX))
if has('nvim') || has('termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
let g:onedark_terminal_italics = 0
colorscheme onedark
"colorscheme catppuccin_mocha
else
colorscheme jellybeans
endif
endif
" Enable italics
let &t_ZH="\e[3m"
let &t_ZR="\e[23m"
highlight Comment cterm=italic gui=italic
" Highlight redundant whitespaces and tabs
highlight RedundantSpaces ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t\|\t/
" }}}
" ============================================================================
" Cursor Settings {{{
" ============================================================================
" Cursor shape configuration - simple and effective
if has('nvim')
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
else
" Terminal cursor shape
let &t_SI = "\<Esc>[6 q" " Insert mode - vertical bar
let &t_SR = "\<Esc>[4 q" " Replace mode - underline
let &t_EI = "\<Esc>[2 q" " Normal mode - block
" Mac-specific cursor settings
if has("mac")
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
endif
" Restore normal cursor on exit
autocmd VimLeave * set guicursor=a:ver25-blinkwait700-blinkon400-blinkoff250
" }}}
" ============================================================================
" File Type Detection and Settings {{{
" ============================================================================
" Enable filetype detection and plugins
filetype plugin indent on
" File-specific settings
augroup file_types
autocmd!
" Verilog/SystemVerilog
autocmd BufRead,BufNewFile *.v,*.vh,*.sv,*.svi,*.svh set filetype=verilog_systemverilog
" Verilog/SystemVerilog - consistent 4-space indentation
autocmd BufRead,BufNewFile *.v,*.vh,*.sv,*.svi,*.svh setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4
" Liberty .lib files
autocmd BufRead,BufNewFile *.lib set filetype=verilog_systemverilog
" TCL
autocmd BufRead,BufNewFile *.do,*.tcl set filetype=tcl
" DFT stuff in STIL syntax
autocmd BufRead,BufNewFile *.spf,*.stil,*.ctl set filetype=verilog
" LEF/DEF
autocmd BufRead,BufNewFile *.lef,*.LEF so ~/.vim/syntax/lef.vim
autocmd BufRead,BufNewFile *.def so ~/.vim/syntax/def.vim
autocmd BufRead,BufNewFile *.lef,*.LEF set filetype=lef
autocmd BufRead,BufNewFile *.def set filetype=def
" SPICE
autocmd BufRead,BufNewFile *.cdl,*.sp,*.spice set filetype=spice
" Shell aliases files
autocmd BufNewFile,BufRead .*aliases* set ft=sh
" Makefiles (keep tabs)
autocmd FileType make setlocal noexpandtab
" Python PEP8 style
autocmd BufNewFile,BufRead *.py set tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0 expandtab autoindent fileformat=unix
" jinja2 templates
autocmd BufNewFile,BufRead *.j2 set ft=jinja
" C/C++ style
autocmd FileType c,cpp set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
augroup END
" Show relative line numbers in normal mode, absolute in insert mode
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
" Only show cursor line in active buffer
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
" Auto-resize splits when Vim gets resized
autocmd VimResized * wincmd =
" }}}
" ============================================================================
" Key Mappings {{{
" ============================================================================
" Split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Make p in Visual mode replace the selected text with the "" register
vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>
" Delete all trailing whitespace with F5
nnoremap <silent> <F5> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" Quick save with leader w
nnoremap <leader>w :w<CR>
" Quick quit with leader q
nnoremap <leader>q :q<CR>
" Quick buffer navigation
nnoremap <leader>bn :bnext<CR>
nnoremap <leader>bp :bprevious<CR>
nnoremap <leader>bd :bdelete<CR>
" Center the screen after searching
nnoremap n nzz
nnoremap N Nzz
" }}}
" ============================================================================
" Custom Functions {{{
" ============================================================================
" Function to clean up text
function! CleanText()
let curcol = col(".")
let curline = line(".")
exe ":retab"
exe ":%s/\r$//ge"
exe ":%s/\r/ /ge"
exe ":%s/ \+$//e"
call cursor(curline, curcol)
endfunction
" Diff options
if !has('mac')
set diffopt+=iwhite " ignore whitespace for vimdiff
endif
set diffexpr=DiffW()
function! DiffW()
let opt = ""
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-w " " swapped vim's -b with -w
endif
silent execute "!diff -a --binary " . opt .
\ v:fname_in . " " . v:fname_new . " > " . v:fname_out
endfunction
" Add all TODO items to the quickfix list
function! s:todo() abort
let entries = []
for cmd in ['git grep -niIw -e TODO -e FIXME 2> /dev/null',
\ 'grep -rniIw -e TODO -e FIXME . 2> /dev/null']
let lines = split(system(cmd), '\n')
if v:shell_error != 0 | continue | endif
for line in lines
let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
endfor
break
endfor
if !empty(entries)
call setqflist(entries)
copen
endif
endfunction
command! Todo call s:todo()
" Insert a date/time entry
command! -nargs=* Entry call s:RunEntry()
function! s:RunEntry()
let s:tm = "\n---" . strftime("%d/%m/%y %H:%M:%S") . "----------------------\n"
execute "normal! i" . s:tm
call feedkeys("i")
endfunction
" }}}
" ============================================================================
" GUI Settings {{{
" ============================================================================
" GUI options - remove scrollbars and toolbar
if has('gui_running')
set guioptions=aegimt
" Set GUI font based on OS
if has("gui_gtk2") || has("gui_gtk3")
set guifont=Fira\ Code\ weight=450\ 11
elseif has("gui_macvim")
set guifont=SourceCodePro-Regular:h12
elseif has("gui_win32")
set guifont=Consolas:h11:cANSI
endif
endif
" Set paper size from system configuration if available
try
if filereadable('/etc/paper.config')
let s:papersize = matchstr(system('/bin/cat /etc/paper.config'), '\p*')
if strlen(s:papersize)
let &printoptions = "paper:" . s:papersize
endif
unlet! s:papersize
endif
catch /E145/
endtry
" }}}
" ============================================================================
" Plugin Configurations {{{
" ============================================================================
" Load all plugin-specific configurations
for f in split(glob('~/.vim/plugin_configs/*.vim'), '\n')
exe 'source' f
endfor
" }}}
" ============================================================================
" Module Loading {{{
" ============================================================================
" Command to load specific modules on-demand
" Type :LoadModule then tab for module list completion
command! -nargs=1 -complete=custom,ListModules LoadModule execute 'source ~/.vim/modules/' . <q-args> . '.vim'
function! ListModules(A, L, P)
let modules = glob('~/.vim/modules/*.vim', 0, 1)
let module_names = []
for module in modules
let name = fnamemodify(module, ':t:r')
call add(module_names, name)
endfor
return join(module_names, "\n")
endfunction
" Uncomment the line below to always load the ASIC module
" source ~/.vim/modules/asic.vim
" Or, run :LoadModule asic when you need ASIC functionality, without having it loaded all the time.
" }}}
" vim: set foldmethod=marker foldlevel=0 ts=2 sts=2 sw=2 noet :