dotfiles for servers
1"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2" Maintainer:
3" Original: Amir Salihefendic - @amix3k
4" Current: Jeffrey Serio - @hyperreal@tilde.zone
5"
6" Sections:
7" -> General
8" -> VIM user interface
9" -> Colors and Fonts
10" -> Files and backups
11" -> Text, tab and indent related
12" -> Visual mode related
13" -> Moving around, tabs and buffers
14" -> Status line
15" -> Editing mappings
16" -> vimgrep searching and cope displaying
17" -> Spell checking
18" -> Misc
19" -> Helper functions
20"
21"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
22
23"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
24" => General
25"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
26" Sets how many lines of history VIM has to remember
27set history=500
28
29" Enable filetype plugins
30filetype plugin on
31filetype indent on
32
33" Set to auto read when a file is changed from the outside
34set autoread
35au FocusGained,BufEnter * silent! checktime
36
37" With a map leader it's possible to do extra key combinations
38" like <leader>w saves the current file
39let mapleader = ","
40
41" Fast saving
42nmap <leader>w :w!<cr>
43
44" :W sudo saves the file
45" (useful for handling the permission-denied error)
46command! W execute 'w !sudo tee % > /dev/null' <bar> edit!
47
48
49"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
50" => VIM user interface
51"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
52" Set 7 lines to the cursor - when moving vertically using j/k
53set so=7
54
55" Ignore compiled files
56set wildignore=*.o,*~,*.pyc
57if has("win16") || has("win32")
58 set wildignore+=.git\*,.hg\*,.svn\*
59else
60 set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
61endif
62
63" Always show current position
64set ruler
65
66" Height of the command bar
67set cmdheight=1
68
69" A buffer becomes hidden when it is abandoned
70set hid
71
72" Configure backspace so it acts as it should act
73set backspace=eol,start,indent
74set whichwrap+=<,>,h,l
75
76" Ignore case when searching
77set ignorecase
78
79" When searching try to be smart about cases
80set smartcase
81
82" Highlight search results
83set hlsearch
84
85" Makes search act like search in modern browsers
86set incsearch
87
88" Don't redraw while executing macros (good performance config)
89set lazyredraw
90
91" For regular expressions turn magic on
92set magic
93
94" Show matching brackets when text indicator is over them
95set showmatch
96
97" How many tenths of a second to blink when matching brackets
98set mat=2
99
100" No annoying sound on errors
101set noerrorbells
102set novisualbell
103set t_vb=
104set tm=500
105
106" Properly disable sound on errors on MacVim
107if has("gui_macvim")
108 autocmd GUIEnter * set vb t_vb=
109endif
110
111" Add a bit extra margin to the left
112set foldcolumn=1
113
114
115"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
116" => Colors and Fonts
117"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
118" Enable syntax highlighting
119syntax enable
120
121" Set regular expression engine automatically
122set regexpengine=0
123
124" Enable 256 colors palette in Gnome Terminal
125if $COLORTERM == 'gnome-terminal'
126 set t_Co=256
127endif
128
129try
130 colorscheme catppuccin_mocha
131catch
132endtry
133
134set background=dark
135
136" Set extra options when running in GUI mode
137if has("gui_running")
138 set guioptions-=T
139 set guioptions-=e
140 set t_Co=256
141 set guitablabel=%M\ %t
142endif
143
144" Set utf8 as standard encoding and en_US as the standard language
145set encoding=utf8
146
147" Use Unix as the standard file type
148set ffs=unix,dos,mac
149
150
151"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
152" => Files, backups and undo
153"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
154" Turn backup off, since most stuff is in SVN, git etc. anyway...
155set nobackup
156set nowb
157set noswapfile
158
159
160"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
161" => Text, tab and indent related
162"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
163" Use spaces instead of tabs
164set expandtab
165
166" Be smart when using tabs ;)
167set smarttab
168
169" 1 tab == 4 spaces
170set shiftwidth=4
171set tabstop=4
172
173" Linebreak on 500 characters
174set lbr
175set tw=500
176
177set ai "Auto indent
178set si "Smart indent
179set wrap "Wrap lines
180
181
182""""""""""""""""""""""""""""""
183" => Visual mode related
184""""""""""""""""""""""""""""""
185" Visual mode pressing * or # searches for the current selection
186" Super useful! From an idea by Michael Naumann
187vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
188vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
189
190
191"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
192" => Moving around, tabs, windows and buffers
193"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
194" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
195map <space> /
196map <C-space> ?
197
198" Disable highlight when <leader><cr> is pressed
199map <silent> <leader><cr> :noh<cr>
200
201" Smart way to move between windows
202map <C-j> <C-W>j
203map <C-k> <C-W>k
204map <C-h> <C-W>h
205map <C-l> <C-W>l
206
207" Close the current buffer
208map <leader>bd :Bclose<cr>:tabclose<cr>gT
209
210" Close all the buffers
211map <leader>ba :bufdo bd<cr>
212
213map <leader>l :bnext<cr>
214map <leader>h :bprevious<cr>
215
216" Useful mappings for managing tabs
217map <leader>tn :tabnew<cr>
218map <leader>to :tabonly<cr>
219map <leader>tc :tabclose<cr>
220map <leader>tm :tabmove
221map <leader>t<leader> :tabnext<cr>
222
223" Let 'tl' toggle between this and the last accessed tab
224let g:lasttab = 1
225nmap <leader>tl :exe "tabn ".g:lasttab<CR>
226au TabLeave * let g:lasttab = tabpagenr()
227
228
229" Opens a new tab with the current buffer's path
230" Super useful when editing files in the same directory
231map <leader>te :tabedit <C-r>=escape(expand("%:p:h"), " ")<cr>/
232
233" Switch CWD to the directory of the open buffer
234map <leader>cd :cd %:p:h<cr>:pwd<cr>
235
236" Specify the behavior when switching between buffers
237try
238 set switchbuf=useopen,usetab,newtab
239 set stal=2
240catch
241endtry
242
243" Return to last edit position when opening files (You want this!)
244au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
245
246
247""""""""""""""""""""""""""""""
248" => Status line
249""""""""""""""""""""""""""""""
250" Always show the status line
251set laststatus=2
252
253" Format the status line
254set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
255
256
257"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
258" => Editing mappings
259"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
260" Remap VIM 0 to first non-blank character
261map 0 ^
262
263" Move a line of text using ALT+[jk] or Command+[jk] on mac
264nmap <M-j> mz:m+<cr>`z
265nmap <M-k> mz:m-2<cr>`z
266vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
267vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
268
269if has("mac") || has("macunix")
270 nmap <D-j> <M-j>
271 nmap <D-k> <M-k>
272 vmap <D-j> <M-j>
273 vmap <D-k> <M-k>
274endif
275
276" Delete trailing white space on save, useful for some filetypes ;)
277fun! CleanExtraSpaces()
278 let save_cursor = getpos(".")
279 let old_query = getreg('/')
280 silent! %s/\s\+$//e
281 call setpos('.', save_cursor)
282 call setreg('/', old_query)
283endfun
284
285if has("autocmd")
286 autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
287endif
288
289
290"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
291" => Spell checking
292"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
293" Pressing ,ss will toggle and untoggle spell checking
294map <leader>ss :setlocal spell!<cr>
295
296" Shortcuts using <leader>
297map <leader>sn ]s
298map <leader>sp [s
299map <leader>sa zg
300map <leader>s? z=
301
302
303"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
304" => Misc
305"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
306" Remove the Windows ^M - when the encodings gets messed up
307noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
308
309" Quickly open a buffer for scribble
310map <leader>q :e ~/buffer<cr>
311
312" Quickly open a markdown buffer for scribble
313map <leader>x :e ~/buffer.md<cr>
314
315" Toggle paste mode on and off
316map <leader>pp :setlocal paste!<cr>
317
318
319"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
320" => Helper functions
321"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
322" Returns true if paste mode is enabled
323function! HasPaste()
324 if &paste
325 return 'PASTE MODE '
326 endif
327 return ''
328endfunction
329
330" Don't close window, when deleting a buffer
331command! Bclose call <SID>BufcloseCloseIt()
332function! <SID>BufcloseCloseIt()
333 let l:currentBufNum = bufnr("%")
334 let l:alternateBufNum = bufnr("#")
335
336 if buflisted(l:alternateBufNum)
337 buffer #
338 else
339 bnext
340 endif
341
342 if bufnr("%") == l:currentBufNum
343 new
344 endif
345
346 if buflisted(l:currentBufNum)
347 execute("bdelete! ".l:currentBufNum)
348 endif
349endfunction
350
351function! CmdLine(str)
352 call feedkeys(":" . a:str)
353endfunction
354
355function! VisualSelection(direction, extra_filter) range
356 let l:saved_reg = @"
357 execute "normal! vgvy"
358
359 let l:pattern = escape(@", "\\/.*'$^~[]")
360 let l:pattern = substitute(l:pattern, "\n$", "", "")
361
362 if a:direction == 'gv'
363 call CmdLine("Ack '" . l:pattern . "' " )
364 elseif a:direction == 'replace'
365 call CmdLine("%s" . '/'. l:pattern . '/')
366 endif
367
368 let @/ = l:pattern
369 let @" = l:saved_reg
370endfunction
371
372""""""""""""""""""""""""""""""
373" => Python section
374""""""""""""""""""""""""""""""
375let python_highlight_all = 1
376au FileType python syn keyword pythonDecorator True None False self
377
378au BufNewFile,BufRead *.jinja set syntax=htmljinja
379au BufNewFile,BufRead *.mako set ft=mako
380
381au FileType python map <buffer> F :set foldmethod=indent<cr>
382
383au FileType python inoremap <buffer> $r return
384au FileType python inoremap <buffer> $i import
385au FileType python inoremap <buffer> $p print
386au FileType python inoremap <buffer> $f # --- <esc>a
387au FileType python map <buffer> <leader>1 /class
388au FileType python map <buffer> <leader>2 /def
389au FileType python map <buffer> <leader>C ?class
390au FileType python map <buffer> <leader>D ?def
391
392
393""""""""""""""""""""""""""""""
394" => Shell section
395""""""""""""""""""""""""""""""
396set termguicolors
397
398""""""""""""""""""""""""""""""
399" => Markdown
400""""""""""""""""""""""""""""""
401let vim_markdown_folding_disabled = 1
402
403
404""""""""""""""""""""""""""""""
405" => YAML
406""""""""""""""""""""""""""""""
407autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
408
409""""""""""""""""""""""""""""""
410" => JSON
411""""""""""""""""""""""""""""""
412autocmd FileType json setlocal ts=4 sts=4 sw=4 expandtab