-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc.lite
More file actions
327 lines (280 loc) · 10.9 KB
/
Copy path.vimrc.lite
File metadata and controls
327 lines (280 loc) · 10.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
" ============================================================================
" Vim Lite Configuration — Zero Plugins Required
" Author: George Gozal
" All features use vim built-ins only. No :PlugInstall needed.
" Usage: vim -u ~/.vimrc.lite OR copy to ~/.vimrc on a fresh machine
" ============================================================================
" Required when loading with vim -u (skips defaults.vim)
set nocompatible
set backspace=indent,eol,start
" ============================================================================
" TERMINAL & COLOR COMPATIBILITY
" ============================================================================
let s:is_mac = has('mac') || has('macunix')
function! s:HasTrueColor() abort
if !has('termguicolors')
return 0
endif
if s:is_mac && $TERM_PROGRAM ==# 'Apple_Terminal'
return 0
endif
return $COLORTERM ==# 'truecolor' || $COLORTERM ==# '24bit'
\ || $TERM_PROGRAM ==# 'iTerm.app'
\ || $TERM_PROGRAM ==# 'vscode'
\ || $TERM =~# 'direct'
\ || $TERM =~# 'kitty'
\ || $TERM =~# 'wezterm'
\ || $TERM =~# 'alacritty'
endfunction
let s:use_termguicolors = s:HasTrueColor()
if s:use_termguicolors
set termguicolors
else
set notermguicolors
if &t_Co < 256 && ($TERM =~# '256color' || $TERM =~# 'xterm')
set t_Co=256
endif
endif
function! s:ApplyUiHighlights() abort
if s:use_termguicolors
highlight CursorLine guibg=#303030
highlight CursorLineNr guifg=#ffff00
highlight LineNr guifg=#585858
highlight StatusLine guibg=#262626 guifg=#ffffff
highlight StatusLineNC guibg=#262626 guifg=#808080
elseif &t_Co >= 256
highlight CursorLine cterm=NONE ctermbg=236
highlight CursorLineNr ctermfg=226 cterm=bold
highlight LineNr ctermfg=243
highlight Normal ctermfg=252 ctermbg=234
highlight StatusLine cterm=bold ctermfg=15 ctermbg=236
highlight StatusLineNC ctermfg=246 ctermbg=236
else
highlight CursorLine cterm=underline
highlight CursorLineNr ctermfg=Yellow cterm=bold
highlight LineNr ctermfg=Cyan
highlight StatusLine cterm=bold ctermfg=White ctermbg=Black
highlight StatusLineNC ctermfg=Grey ctermbg=Black
endif
endfunction
if s:is_mac
set clipboard=unnamed
else
if has('clipboard')
set clipboard=unnamedplus
else
autocmd TextYankPost * call system('xclip -selection clipboard', @")
nnoremap p :let @"=system('xclip -selection clipboard -o')<CR>p
nnoremap P :let @"=system('xclip -selection clipboard -o')<CR>P
endif
endif
" ============================================================================
" GENERAL SETTINGS
" ============================================================================
filetype plugin indent on
syntax on
set number
set relativenumber
set tabstop=4
set shiftwidth=4
set expandtab
set cursorline
set autoindent
set nowrap
set ignorecase
set smartcase
set incsearch
set hlsearch
set backspace=indent,eol,start
set mouse=a
set encoding=utf-8
set background=dark
" ============================================================================
" BETTER DEFAULTS
" ============================================================================
set hidden
set splitright
set splitbelow
set undofile
set undodir=~/.vim/undodir
set wildmenu
set wildmode=list:longest,full
set showcmd
set showmatch
set matchtime=2
set history=1000
set updatetime=300
set lazyredraw
set completeopt=menuone,noinsert,noselect
set shortmess+=c
set noswapfile
set nobackup
" ============================================================================
" COLORSCHEME (built-in)
" ============================================================================
colorscheme desert
call s:ApplyUiHighlights()
syntax enable
" ============================================================================
" BUILT-IN STATUS LINE (replaces vim-airline)
" ============================================================================
set laststatus=2
set statusline=
set statusline+=\ %f " file path
set statusline+=\ %m%r " modified/readonly flags
set statusline+=%= " right align
set statusline+=\ %y " filetype
set statusline+=\ [%{&fileencoding}] " encoding
set statusline+=\ %l:%c " line:column
set statusline+=\ [%p%%] " percentage
" ============================================================================
" BUILT-IN FILE EXPLORER (replaces NERDTree)
" ============================================================================
" netrw is built into vim — use :Explore or :Vexplore
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 " 25% width
" Toggle netrw sidebar with Ctrl+n
nnoremap <C-n> :Lexplore<CR>
" :Tree command (same as full .vimrc)
command! Tree Lexplore
" Open netrw as a proper sidebar when vim starts with a directory argument
" This prevents 'vim .' from putting netrw in the main window, which would
" cause Ctrl+n to open a duplicate sidebar
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
\ execute 'cd' fnameescape(argv()[0]) | enew | Lexplore | endif
" ============================================================================
" BUILT-IN FUZZY FIND (replaces ctrlp)
" ============================================================================
" Search recursively in subdirectories
set path+=**
" :find <filename> now works with tab completion across the project
" :b <partial> switches buffers with tab completion
" ============================================================================
" BUILT-IN COMMENTING (replaces vim-commentary)
" ============================================================================
" Toggle comment with <leader>c in normal and visual mode
" Uses filetype-aware comment strings
augroup commenting
autocmd!
autocmd FileType python,sh,bash,zsh,yaml let b:comment_prefix = '# ' | let b:comment_suffix = ''
autocmd FileType javascript,java,c,cpp let b:comment_prefix = '// ' | let b:comment_suffix = ''
autocmd FileType vim let b:comment_prefix = '" ' | let b:comment_suffix = ''
autocmd FileType html,xml let b:comment_prefix = '<!-- ' | let b:comment_suffix = ' -->'
augroup END
function! ToggleComment() range
let l:prefix = get(b:, 'comment_prefix', '# ')
let l:suffix = get(b:, 'comment_suffix', '')
let l:lines = getline(a:firstline, a:lastline)
let l:uncomment = 0
for l:line in l:lines
if l:line =~ '^\s*$' | continue | endif
if l:line =~ '^\s*' . escape(l:prefix, '/*')
let l:uncomment = 1
endif
break
endfor
for l:lnum in range(a:firstline, a:lastline)
let l:line = getline(l:lnum)
if l:line =~ '^\s*$' | continue | endif
if l:uncomment
if !empty(l:suffix)
call setline(l:lnum, substitute(l:line, '^\(\s*\)' . escape(l:prefix, '/*') . '\(.*\)' . escape(l:suffix, '/*') . '\s*$', '\1\2', ''))
else
call setline(l:lnum, substitute(l:line, '^\(\s*\)' . escape(l:prefix, '/*'), '\1', ''))
endif
else
if !empty(l:suffix)
call setline(l:lnum, substitute(l:line, '^\(\s*\)\(.*\)\s*$', '\1' . l:prefix . '\2' . l:suffix, ''))
else
call setline(l:lnum, substitute(l:line, '^\(\s*\)', '\1' . escape(l:prefix, '&'), ''))
endif
endif
endfor
endfunction
nnoremap <leader>c :call ToggleComment()<CR>
vnoremap <leader>c :call ToggleComment()<CR>
" ============================================================================
" KEY MAPPINGS
" ============================================================================
nnoremap <C-s> :w<CR>
nnoremap <C-q> :q<CR>
nnoremap <leader>h :nohlsearch<CR>
nnoremap j gj
nnoremap k gk
inoremap jk <Esc>
nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
vnoremap <C-j> :m '>+1<CR>gv=gv
vnoremap <C-k> :m '<-2<CR>gv=gv
if !s:is_mac || $TERM_PROGRAM ==# 'iTerm.app'
nnoremap <M-j> :m .+1<CR>==
nnoremap <M-k> :m .-2<CR>==
vnoremap <M-j> :m '>+1<CR>gv=gv
vnoremap <M-k> :m '<-2<CR>gv=gv
endif
" ============================================================================
" BUFFER & WINDOW NAVIGATION
" ============================================================================
nnoremap <leader>n :bnext<CR>
nnoremap <leader>p :bprev<CR>
nnoremap <leader>d :bdelete<CR>
nnoremap <leader>b :ls<CR>:b<Space>
nnoremap <leader>1 :b1<CR>
nnoremap <leader>2 :b2<CR>
nnoremap <leader>3 :b3<CR>
nnoremap <leader>4 :b4<CR>
nnoremap <leader>5 :b5<CR>
nnoremap <leader>x :bp<bar>sp<bar>bn<bar>bd<CR>
nnoremap <leader>v :vsplit<CR>
nnoremap <leader>s :split<CR>
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
" Keep visual selection after indent
vnoremap < <gv
vnoremap > >gv
" ============================================================================
" BUILT-IN BUFFER TABLINE (replaces vim-buftabline)
" ============================================================================
" Show tabline when 2+ buffers open
set showtabline=2
function! BufTabLine()
let s = ''
for i in range(1, bufnr('$'))
if buflisted(i)
let name = fnamemodify(bufname(i), ':t')
if empty(name) | let name = '[No Name]' | endif
if i == bufnr('%')
let s .= ' %#TabLineSel# ' . name . ' '
else
let s .= ' %#TabLine# ' . name . ' '
endif
endif
endfor
return s . '%#TabLineFill#'
endfunction
set tabline=%!BufTabLine()
" ============================================================================
" FILE TYPE SPECIFIC SETTINGS
" ============================================================================
autocmd FileType python setlocal shiftwidth=4 tabstop=4
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType sh setlocal shiftwidth=4 tabstop=4
autocmd FileType xml setlocal shiftwidth=2 tabstop=2
autocmd FileType json setlocal shiftwidth=2 tabstop=2
autocmd FileType yaml setlocal shiftwidth=2 tabstop=2
" ============================================================================
" AUTO-CLEANUP
" ============================================================================
" Remove trailing whitespace on save for Python and shell scripts
autocmd BufWritePre *.py,*.sh,*.bash %s/\s\+$//e
" ============================================================================
" INITIALIZATION
" ============================================================================
if !isdirectory($HOME."/.vim/undodir")
call mkdir($HOME."/.vim/undodir", "p", 0700)
endif