-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
423 lines (320 loc) · 11.4 KB
/
Copy path.vimrc
File metadata and controls
423 lines (320 loc) · 11.4 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
" ============================================================================
" Vim Configuration for Python, JavaScript & Web Development
" Author: George Gozal
" macOS Compatible Version
" ============================================================================
" ============================================================================
" MACOS COMPATIBILITY FIXES
" ============================================================================
" Detect operating system
let s:is_mac = has('mac') || has('macunix')
let s:is_linux = has('unix') && !has('macunix')
" macOS-specific terminal setup
if s:is_mac
" Fix for macOS Terminal color issues
if $TERM_PROGRAM ==# 'Apple_Terminal'
set notermguicolors
else
" iTerm2 and other modern terminals support true colors
set termguicolors
endif
" macOS clipboard integration
set clipboard=unnamed
" Fix backspace on macOS
set backspace=indent,eol,start
else
" Linux settings
set termguicolors
if has('clipboard')
set clipboard=unnamedplus
else
" Workaround: sync yank/paste with system clipboard via xclip
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
" ============================================================================
" Enable filetype detection, plugins, and indentation
filetype plugin indent on
" Enable syntax highlighting
syntax on
" Show line numbers
set number
" Show relative line numbers
set relativenumber
" Set tab width to 4 spaces
set tabstop=4
" Set indentation width to 4 spaces
set shiftwidth=4
" Use spaces instead of tabs
set expandtab
" Highlight the current line
set cursorline
" Automatic indentation for new lines
set autoindent
" Disable line wrapping
set nowrap
" Case-insensitive search
set ignorecase
" Case-sensitive search if uppercase letters are used
set smartcase
" Show search results in real-time
set incsearch
" Highlight search results
set hlsearch
" Fix backspace behavior
set backspace=indent,eol,start
" Enable mouse support (useful for text selection)
set mouse=a
" Use UTF-8 encoding
set encoding=utf-8
" Set dark background
set background=dark
" ============================================================================
" BETTER DEFAULTS
" ============================================================================
" Allow switching buffers without saving
set hidden
" Sensible split directions
set splitright
set splitbelow
" Persistent undo across sessions
set undofile
set undodir=~/.vim/undodir
" Enhanced command completion
set wildmenu
set wildmode=list:longest,full
" Show partial commands
set showcmd
" Highlight matching brackets
set showmatch
set matchtime=2
" More command history
set history=1000
" Faster updates for better UX
set updatetime=300
" Don't redraw during macros (performance)
set lazyredraw
" Better completion options
set completeopt=menuone,noinsert,noselect
set shortmess+=c
" Disable swap and backup files (optional)
set noswapfile
set nobackup
" ============================================================================
" KEY MAPPINGS
" ============================================================================
" Save file with Ctrl+S
nnoremap <C-s> :w<CR>
" Quit Vim with Ctrl+Q
nnoremap <C-q> :q<CR>
" Clear search highlights with <leader>h (default leader is \)
nnoremap <leader>h :nohlsearch<CR>
" Move by visual lines (useful when lines are wrapped)
nnoremap j gj
nnoremap k gk
" Use 'jk' as an alternative to Esc in Insert mode
inoremap jk <Esc>
" ============================================================================
" BUFFER & WINDOW NAVIGATION
" ============================================================================
" Buffer navigation
nnoremap <leader>n :bnext<CR>
nnoremap <leader>p :bprev<CR>
nnoremap <leader>d :bdelete<CR>
" Show buffer list and prompt for buffer switch
nnoremap <leader>b :ls<CR>: b<Space>
" Quick buffer switching by number (useful when many files open)
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>
" Delete buffer without closing window
nnoremap <leader>x :bp<bar>sp<bar>bn<bar>bd<CR>
" Quick splits
nnoremap <leader>v :vsplit<CR>
nnoremap <leader>s :split<CR>
" Quick save and quit
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
" Keep visual selection after indent
vnoremap < <gv
vnoremap > >gv
" macOS-compatible line moving (works without Alt key issues)
" Use Ctrl+j and Ctrl+k instead of Alt/Meta
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
" Alternative: If you're using iTerm2, you can keep Alt mappings
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
" ============================================================================
" PLUGIN MANAGER (VIM-PLUG)
" ============================================================================
call plug#begin('~/.vim/plugged')
" File tree navigation
Plug 'preservim/nerdtree'
" Status line
Plug 'vim-airline/vim-airline'
" Syntax checking and linting
Plug 'dense-analysis/ale'
" Easy commenting/uncommenting
Plug 'tpope/vim-commentary'
" Monokai color scheme
Plug 'crusoexia/vim-monokai'
" HTML/CSS fast writing
Plug 'mattn/emmet-vim'
" Fuzzy file finder
Plug 'ctrlpvim/ctrlp.vim'
" Auto-close brackets
Plug 'jiangmiao/auto-pairs'
" Git integration
Plug 'airblade/vim-gitgutter'
" Better syntax highlighting
Plug 'sheerun/vim-polyglot'
" Buffer list in tabline
Plug 'ap/vim-buftabline'
call plug#end()
" Fuzzy file finder
nnoremap <C-p> :CtrlP<CR>
" ============================================================================
" COLORSCHEME
" ============================================================================
" Enable Monokai color scheme with fallback
try
colorscheme monokai
catch
" Fallback if monokai isn't installed yet
colorscheme desert
endtry
" ============================================================================
" NERDTREE CONFIGURATION
" ============================================================================
" Toggle NERDTree with Ctrl+n
nnoremap <C-n> :NERDTreeToggle<CR>
" Custom alias :Tree for NERDTree (toggles, won't open duplicates)
command! Tree NERDTreeToggle
" Show hidden files (dotfiles) by default
let g:NERDTreeShowHidden = 1
" Auto-close NERDTree if it's the only window left
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Open NERDTree as a proper sidebar when vim starts with a directory argument
" This prevents 'vim .' from putting NERDTree 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 |
\ execute 'NERDTree' fnameescape(getcwd()) | wincmd p | endif
" macOS-specific NERDTree settings
if s:is_mac
" Use ASCII characters for NERDTree if terminal doesn't support Unicode well
if $TERM_PROGRAM ==# 'Apple_Terminal'
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'
endif
endif
" ============================================================================
" FILE TYPE SPECIFIC SETTINGS
" ============================================================================
" Python-specific settings
autocmd FileType python setlocal shiftwidth=4 tabstop=4
" JavaScript/Node.js-specific settings
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
" HTML-specific settings
autocmd FileType html setlocal shiftwidth=2 tabstop=2
" Shell script settings
autocmd FileType sh setlocal shiftwidth=4 tabstop=4
" XML settings
autocmd FileType xml setlocal shiftwidth=2 tabstop=2
" JSON settings
autocmd FileType json setlocal shiftwidth=2 tabstop=2
" YAML settings
autocmd FileType yaml setlocal shiftwidth=2 tabstop=2
" ============================================================================
" ALE CONFIGURATION
" ============================================================================
" Configure linters
let g:ale_linters = {
\ 'python': ['flake8', 'pylint'],
\ 'javascript': ['eslint'],
\ 'html': ['htmlhint'],
\ 'sh': ['shellcheck'],
\}
" Configure fixers
let g:ale_fixers = {
\ 'python': ['isort', 'black'],
\ 'javascript': ['prettier'],
\ 'html': ['prettier'],
\}
" Auto-fix on save
let g:ale_fix_on_save = 1
" Python-specific ALE settings
let g:ale_python_flake8_use_global = 0
let g:ale_python_flake8_executable = 'python3 -m flake8'
let g:ale_python_flake8_options = '--max-line-length=88'
let g:ale_python_black_options = '--line-length=88'
let g:ale_python_auto_virtualenv = 1
" Show ALE errors in airline
let g:airline#extensions#ale#enabled = 1
" ============================================================================
" PYTHON VIRTUAL ENVIRONMENT AUTO-DETECTION
" ============================================================================
function! ActivateVenv()
let l:venv_dir = finddir('.venv', '.;')
if empty(l:venv_dir)
let l:venv_dir = finddir('venv', '.;')
endif
if ! empty(l:venv_dir)
let l:venv_dir = fnamemodify(l:venv_dir, ':p')
" macOS uses different path structure for Python in venv
if s:is_mac
let l:python_path = l:venv_dir . 'bin/python3'
else
let l:python_path = l:venv_dir . 'bin/python'
endif
if executable(l:python_path)
let g:python3_host_prog = l:python_path
let $VIRTUAL_ENV = l:venv_dir
let $PATH = l:venv_dir . 'bin:' . $PATH
" Configure ALE to use venv linters
let g:ale_python_flake8_executable = l:venv_dir . 'bin/flake8'
let g:ale_python_pylint_executable = l:venv_dir . 'bin/pylint'
endif
endif
endfunction
autocmd BufRead,BufNewFile *.py call ActivateVenv()
" ============================================================================
" MACOS PYTHON3 SETUP
" ============================================================================
if s:is_mac
" Try to find Python 3 installation on macOS
if executable('python3')
let g:python3_host_prog = exepath('python3')
elseif executable('/usr/local/bin/python3')
let g:python3_host_prog = '/usr/local/bin/python3'
elseif executable('/opt/homebrew/bin/python3')
" Apple Silicon Mac (M1/M2/M3)
let g:python3_host_prog = '/opt/homebrew/bin/python3'
endif
endif
" ============================================================================
" AUTO-CLEANUP
" ============================================================================
" Remove trailing whitespace on save for Python and shell scripts
autocmd BufWritePre *.py,*.sh,*.bash %s/\s\+$//e
" ============================================================================
" INITIALIZATION
" ============================================================================
" Create undo directory if it doesn't exist
if !isdirectory($HOME."/.vim/undodir")
call mkdir($HOME."/.vim/undodir", "p", 0700)
endif