Last active
November 17, 2021 12:13
-
-
Save lithammer/0dc0b22c6b28829728f1 to your computer and use it in GitHub Desktop.
Small vimrc for servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scriptencoding utf-8 | |
if &compatible | |
set nocompatible | |
endif | |
" Tree style listing in netrw. | |
let g:netrw_liststyle = 3 | |
" Hide patterns specified in .gitignore. Press "a" to cycle through the hiding modes. | |
" :h netrw-hiding | |
" if exists('*netrw_gitignore#Hide') | |
" let g:netrw_list_hide = netrw_gitignore#Hide() | |
" endif | |
" Press CTRL-^ to return to the last edited file, instead of the netrw browsing buffer. | |
let g:netrw_altfile = 1 | |
" menuone Use the popup menu also when there is only one match. | |
" Useful when there is additional information about the | |
" match, e.g., what file it comes from. | |
set completeopt=menuone | |
" Don't break a line after a one-letter word. It's broken before it | |
" instead (if possible). | |
set formatoptions+=1 | |
if has('patch-7.3.541') | |
" Where it makes sense, remove a comment leader when joining lines. | |
set formatoptions+=j | |
endif | |
" Highlight all search matches. | |
set hlsearch | |
" Do incremental searching when it's possible to timeout. | |
if has('reltime') | |
set incsearch | |
endif | |
" Always do case-insensitive search, unless the pattern contains upper case characters. | |
set ignorecase smartcase | |
" Show invisible characters, e.g. tabs and trailing whitespace. | |
set list listchars=tab:\|\ ,trail:·,extends:>,precedes:<,nbsp:_ | |
" Show line numbers. | |
set number | |
" Use 4-space indentation by default. | |
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab | |
if exists('+breakindent') | |
" Every wrapped line will continue visually indented (same amount of | |
" space as the beginning of that line), thus preserving horizontal blocks | |
" of text. | |
set breakindent | |
" Display the 'showbreak' value before applying the additional indent. | |
set breakindentopt=sbr | |
let &showbreak = "\u21AA " | |
endif | |
" When more than one match, list all matches. | |
set wildmode=list:longest,list:full | |
" Case-insensitive wild menu. | |
if exists('+wildignorecase') | |
set wildignorecase | |
end | |
function! s:stdpath(what) abort | |
return has('nvim') ? stdpath(a:what) : expand('~/.vim') | |
endfunction | |
let &directory = s:stdpath('data') . '/swap//' | |
if !isdirectory(&directory) | |
call mkdir(&directory) | |
endif | |
let &backupdir = s:stdpath('data') . '/backup' | |
if !isdirectory(&backupdir) | |
call mkdir(&backupdir) | |
endif | |
if has('persistent_undo') | |
set undofile | |
let &undodir = s:stdpath('data') . '/undo' | |
if !isdirectory(&undodir) | |
call mkdir(&undodir) | |
endif | |
endif | |
" Include column number (%c) in the grep format list. | |
set grepformat^=%f:%l:%c:%m | |
if executable('rg') | |
set grepprg=rg\ --vimgrep | |
elseif executable('ag') | |
set grepprg=ag\ --vimgrep | |
else | |
set grepprg=grep\ -Irn\ $*\ /dev/null | |
endif | |
" Use <C-L> to clear the highlighting of :set hlsearch. | |
if maparg('<C-L>', 'n') ==# '' | |
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L> | |
endif | |
" Do a grep search and open the result in a quickfix window. | |
" :Grep foobar | |
command! -bar -nargs=+ -complete=file_in_path Grep silent! grep! <args> | redraw! | |
" Automatically open the quickfix window when populated. | |
augroup quickfix | |
autocmd! | |
autocmd QuickFixCmdPost [^l]* cwindow | |
autocmd QuickFixCmdPost l* lwindow | |
autocmd VimEnter * cwindow | |
augroup END | |
" :h last-position-jump | |
augroup lastpositionjump | |
autocmd! | |
autocmd BufReadPost * | |
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' | |
\ | exe "normal! g`\"" | |
\ | endif | |
augroup END | |
" :h diff-original-file | |
if !exists(':DiffOrig') | |
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis | |
\ | wincmd p | diffthis | |
endif | |
" vi: ts=2 sts=2 sw=2 et: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment