Skip to content

Instantly share code, notes, and snippets.

@lirundong
Last active June 5, 2023 03:54
Show Gist options
  • Save lirundong/e64b9bb1e3183348a2812c28c2eadb6a to your computer and use it in GitHub Desktop.
Save lirundong/e64b9bb1e3183348a2812c28c2eadb6a to your computer and use it in GitHub Desktop.
My super neat, minimum Vim config.
"" OS-specfic variables and plugins.
if has('win64') || has('win32') || has('win16')
let s:os = 'Windows'
let s:data_dir = has('nvim') ? stdpath('data') . '/site' : $HOME . '/vimfiles'
set shell=powershell
set shellcmdflag=-NoProfile\ -Command
else
let s:os = substitute(system('uname'), '\n', '', '')
let s:data_dir = has('nvim') ? stdpath('data') . '/site' : $HOME . '/.vim'
endif
" Check if vim-plug is installed.
let s:vim_plug_url = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
let s:vim_plug_dir = s:data_dir . '/plugged'
let s:vim_plug_path = s:data_dir . '/autoload/plug.vim'
if empty(glob(s:vim_plug_path)) " Vim-plug script does not exist.
call mkdir(s:data_dir . '/autoload', 'p', )
if s:os == 'Windows'
execute '!Invoke-WebRequest -Uri ' . s:vim_plug_url . ' -OutFile ' . s:vim_plug_path
else
execute '!curl -L ' . s:vim_plug_url . ' -o ' . s:vim_plug_path
endif
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" List plugins.
call plug#begin(s:vim_plug_dir)
Plug 'arcticicestudio/nord-vim'
Plug 'sheerun/vim-polyglot'
Plug 'vim-airline/vim-airline'
Plug 'google/vim-searchindex'
call plug#end()
"" General settings.
set mouse=a
set nu
set nowrap
" Expand tabs.
set tabstop=2
set shiftwidth=2
set expandtab
" Unidoce encoding.
set encoding=utf-8
set fileencoding=utf-8
"" Visual settings.
syntax on
set cursorline
if has('termguicolors')
" Fix true-colors in tmux.
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
" Each system has different pre-installed fonts.
if has('gui_running') || has('nvim') " nvim-qt can't check has('gui_running').
if s:os == 'Darwin'
set guifont=SF\ Mono:h14
set guifontwide=Sarasa\ Mono\ SC:h14
elseif s:os == 'Windows'
set guifont=Cascadia_Code_PL:h12
set guifontwide=Sarasa_Mono_SC:h12
else
set guifont=Monospace\ 12
set guifontwide=Sarasa\ Mono\ SC\ 12
endif
set guioptions-=m " Hide menu bar.
set guioptions-=T " Hide toolbar.
set guioptions-=r " Hide scrollbar.
set linespace=3
set lines=45
set columns=132
endif
" Column width visualize.
set colorcolumn=80
highlight ColorColumn ctermbg=lightgray guibg=lightgray
" Color scheme.
let g:nord_bold = 1
let g:nord_italic = 1
let g:nord_underline = 1
" Fix itialic and bold text mark.
let &t_ZH = "\e[3m"
let &t_ZR = "\e[23m"
colorscheme nord
"" Misc settings.
filetype on
set nocompatible
" Highlight trailing whitespaces.
highlight TrailingWhitespace ctermbg=lightred guibg=lightred
match TrailingWhitespace /\s\+$/
" NVim-specific settings.
if has('nvim')
set clipboard+=unnamedplus
endif
"" Language-specific settings.
" Wrap Markdown and TeX documents.
augroup DocumentSpecific
autocmd!
autocmd FileType markdown,tex setlocal wrap
autocmd FileType markdown,tex setlocal linebreak
augroup END
" Python files have a 100 character line-width.
augroup PythonSpecific
autocmd!
autocmd FileType python setlocal colorcolumn=100
autocmd FileType python setlocal tabstop=4
autocmd FileType python setlocal shiftwidth=4
augroup END
" Git commit should contain at most 72 characters each line.
augroup GitCommit
autocmd!
autocmd FileType gitcommit setlocal colorcolumn=72
augroup END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment