scriptencoding utf-8 " Explicitly define script encoding to be compatible with Windows and non-UTF locales
set nocompatible " Enable vim features
set autoindent " Copy indent from whe current line when opening a new line
set nobackup " Wherever I need a backup, I use version control
set backspace=2 " Allow backspace over indentation, end-of-line and start-of-line
set noerrorbells " Keep vim quiet
set showmatch " Show the matching bracket for the last ')'?
set shortmess=atI " Reduce the verbosity of the most common messages and remove :intro
set visualbell " Keep vim quiet
set background=dark " I'm running it on black-backgrounded xterm
set tildeop " make a tilde ("~") an operator, to use it like "~W"
set tabstop=8 " Keep tabstop right for compatibility, but
set softtabstop=2 " use softtabstop to have 2 spaces per <Tab> hit
set shiftwidth=2 " and match it indent shift
set shiftround " Round indent to the nearest shiftwidth value
set expandtab " Use expandtab to avoid mixing tabs and spaces which breaks Python code
set smarttab
set hlsearch " Highlight search - show the current search pattern
set wrapmargin=5 " Wrapmargin allows to wrap text automagically
set modeline modelines=3 " Use modeline
set hidden " Do not complain about switching from unsaved buffer
set cpoptions-=z " Make w in cw behave like in dw
" Make Y yank everything from the cursor to the end of the line, similar to C and D
noremap Y y$
if has('autocmd')
filetype plugin indent on
endif
if has("syntax")
syntax on
endif
" Settings specific to file types
autocmd FileType crontab,fstab,make setlocal noexpandtab shiftwidth=8
autocmd FileType html setlocal textwidth=132 colorcolumn=132
autocmd FileType c,python setlocal textwidth=132 colorcolumn=132 cursorline cindent cinkeys-=0#
autocmd FileType asciidoc,markdown setlocal textwidth=132 colorcolumn=132 spell
autocmd FileType yaml setlocal cursorline
autocmd FileType vim setlocal keywordprg=:help textwidth=132 colorcolumn=132
autocmd FileType xml setlocal equalprg=xmllint\ --format\ -
autocmd FileType json setlocal equalprg=jq\ .
" Jump to the last position when reopening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" GUI option
set guifont=Cascadia_Mono:h14:cANSI:qDRAFT
set guioptions-=T
set guioptions-=m
colorscheme hybrid
" show whitespaces at the end of line
" switch it on and off with a <leader>l
if has('multi_byte') || has('listchars')
set listchars=tab:»\ ,trail:·
nnoremap <silent> <leader>l :setlocal list!<CR>
endif
function! Numbers()
" cycle between 3 settings
" 0. set nonumner, set norelativenumber
" 1. set number, set norelativenumber
" 2. set number, set relativenumber
if &l:number == 1 && &l:relativenumber == 0
setlocal number
setlocal relativenumber
elseif &l:number == 1 && &l:relativenumber == 1
setlocal nonumber
setlocal norelativenumber
else
setlocal number
setlocal norelativenumber
endif
endfunction
nnoremap <silent> <leader>n :call Numbers()<CR>
" Use Q to replay q buffer, which I use most frequently
nnoremap <silent> Q @q
vnoremap <silent> Q :norm @q<cr>
" statusline
set laststatus=2 " Always show the status line
set noshowmode " Not needed with status line highlights
highlight User1 cterm=NONE ctermfg=195 ctermbg=67 gui=NONE guifg=#d7ffff guibg=#5f87af
set statusline=\ %.20f " Path to the file
set statusline+=%= " Switch to the right side
set statusline+=%{&paste==1?'[PASTE]\ ':''} " Paste mode indicator
set statusline+=%c " Current column
set statusline+=%1*:%0* " Separator
set statusline+=%l " Current line
set statusline+=%1*/%0* " Separator
set statusline+=%L " Total lines
set statusline+=\ " Padding
function! ChangeStatusColor(mode)
if a:mode == 'i'
highlight StatusLine cterm=NONE ctermfg=254 ctermbg=036 gui=NONE guifg=#e4e4e4 guibg=#00af87
highlight User1 cterm=NONE ctermfg=057 ctermbg=036 gui=NONE guifg=#5f00ff guibg=#00af87
elseif a:mode == 'r'
highlight StatusLine cterm=NONE ctermfg=254 ctermbg=202 gui=NONE guifg=#e4e4e4 guibg=#ff5f00
highlight User1 cterm=NONE ctermfg=075 ctermbg=202 gui=NONE guifg=#5fafff guibg=#ff5f00
else
highlight StatusLine cterm=NONE ctermfg=254 ctermbg=67 gui=NONE guifg=#e4e4e4 guibg=#5f87af
highlight User1 cterm=NONE ctermfg=195 ctermbg=67 gui=NONE guifg=#d7ffff guibg=#5f87af
endif
endfunction
autocmd InsertEnter * call ChangeStatusColor(v:insertmode)
autocmd InsertLeave * call ChangeStatusColor('n')
" Generic mappings
nnoremap <silent> <leader>c :setlocal cursorline!<CR>
nnoremap <silent> <leader>p :setlocal paste!<CR>
nnoremap <silent> <leader>/ :nohls<enter>
" set lower timeout so that shift-O doesn't take as long
" see https://github.com/vim/vim/issues/24
set timeout timeoutlen=5000 ttimeoutlen=100
" Use buffers like tabs
nnoremap <silent> <C-N> :bnext<cr>
nnoremap <silent> <C-P> :bprevious<cr>
nnoremap <silent> <leader>1 :1buffer<cr>
nnoremap <silent> <leader>2 :2buffer<cr>
nnoremap <silent> <leader>3 :3buffer<cr>
nnoremap <silent> <leader>4 :4buffer<cr>
nnoremap <silent> <leader>5 :5buffer<cr>
nnoremap <silent> <leader>6 :6buffer<cr>
nnoremap <silent> <leader>7 :7buffer<cr>
nnoremap <silent> <leader>8 :8buffer<cr>
nnoremap <silent> <leader>9 :9buffer<cr>
noremap <C-k> <C-w>k
noremap <C-j> <C-w>j
" buftabline
let g:buftabline_show = 1
hi BufTabLineCurrent term=bold,reverse ctermfg=15 ctermbg=63 guifg=#ffffff guibg=#5f5fff
hi BufTabLineActive ctermfg=117 ctermbg=63 guifg=#b0e7ff guibg=#5f5fff
hi BufTabLineHidden ctermfg=7 ctermbg=63 guifg=#c0c0c0 guibg=#5f5fff
hi BufTabLineFill ctermfg=254 ctermbg=63 guifg=#f0f0f0 guibg=#5f5fff
" bufexplorer
let g:bufExplorerDisableDefaultKeyMapping=1
let g:bufExplorerDefaultHelp=0
nnoremap <silent> <leader>b :ToggleBufExplorer<cr>
" Built-in plugin to improve % behaviour
silent! packadd! matchit
" when editing vim configs use K to call for :help
" create tags for source code
command! Tags !ctags -R .
" netrw
let g:netrw_banner = 0
nnoremap <silent> <leader>e :Explore<cr>
" disable arrows and force hjkl use for movement
map <Up> <nop>
map <Down> <nop>
map <Left> <nop>
map <Right> <nop>
" Make ^u and ^w to be a separate change in undo history
inoremap <C-U> <C-G>u<C-U>
inoremap <C-W> <C-G>u<C-W>
" vimwiki: use Markdown
let g:vimwiki_list = [{'path': '~/.notes/', 'ext': '.md', 'syntax': 'markdown'}]
" showmarks
highlight ShowMarksHLl ctermfg=154 ctermbg=232 guifg=#87d7ff
highlight ShowMarksHLu ctermfg=154 ctermbg=232 guifg=#87afff
highlight ShowMarksHLo ctermfg=154 ctermbg=232 guifg=#87afff
let g:showmarks_textlower="▸"
let g:showmarks_textupper="▸"
let g:showmarks_textother="▸"
let g:showmarks_include="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"Add a code snippet to your website: www.paste.org