Skip to content

Instantly share code, notes, and snippets.

@mikowl
Created June 3, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikowl/1d6b723ebe22b2dfe172b1e1ca02d671 to your computer and use it in GitHub Desktop.
Save mikowl/1d6b723ebe22b2dfe172b1e1ca02d671 to your computer and use it in GitHub Desktop.
.vimrc (no NerdTree)
set encoding=utf8
set nocompatible
" Plugins
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-markdown'
Plug 'masukomi/vim-markdown-folding'
Plug 'easymotion/vim-easymotion'
Plug 'airblade/vim-gitgutter'
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'rbong/vim-crystalline'
Plug 'mattn/emmet-vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'arcticicestudio/nord-vim'
Plug 'ryanoasis/vim-devicons'
Plug 'godlygeek/tabular'
Plug 'luochen1990/rainbow'
Plug 'posva/vim-vue'
call plug#end()
" # General
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable filetype plugins
filetype plugin on
filetype indent on
"Set auto read when a file is changed from the outside
set autoread
"Copy to system clicpboard
set clipboard=unnamed
" Set leader key
let mapleader = ","
" :W sudo saves the file
command W w !sudo tee % > /dev/null
" Automatically source vimrc on save.
autocmd! bufwritepost $MYVIMRC source $MYVIMRC
" Save folds
augroup remember_folds
autocmd!
au BufWinLeave ?* mkview 1
au BufWinEnter ?* silent loadview 1
augroup END
" Markdown
" set foldmethod=manual
set foldcolumn=2
" fenced code block
let g:markdown_fenced_languages = ['html', 'css', 'php', 'javascript', 'python', 'bash=sh', 'vim']
augroup markdown
au!
au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown
augroup END
" vim-markdown-folding
if has("autocmd")
filetype plugin indent on
endif
" default to nested folding
autocmd FileType markdown set foldexpr=StackedMarkdownFolds()
" spell check
set spellfile=~/.vim/spell/en.utf-8.add
" lazy drawing
" set lazyredraw
set ttyfast
" change cursors depending on mode
let &t_SI = "\e[6 q"
let &t_EI = "\e[2 q"
" highlight line when in insert mode
autocmd InsertEnter,InsertLeave * set cul!
" # Color schemes
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax and plugins
syntax on
" Set colorscheme
" Color schemes I like: nord, one, night-owl, palenight
set background=dark
colorscheme nord
let g:nord_italic = 1
" # Interface
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor when moving vertically using j/k
set so=7
" Display all matching files when we tab complete
set wildmenu
"Always show current position
set ruler
" Height of the command bar
set cmdheight=1
" A buffer becomes hidden when it is abandoned
set hid
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Search settings
set smartcase " smart cases when search
set hlsearch " highlight search results
set incsearch " incremental searching
set ignorecase " ignore case when searching
" For regular expressions turn magic on
set magic
set showmatch " shows matching brackets
set mat=2
" Diable sounds
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Add a bit of margin to left
set foldcolumn=2
" # Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
" # Text, tab, and indent stuff
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Indent
set expandtab
set shiftwidth=2
set autoindent
set smartindent
" Disable auto-wrap
set nowrap
set textwidth=0
set wrapmargin=0
" Set word wrap in markdown files
au BufRead,BufNewFile *.md set wrap linebreak nolist
au BufRead,BufNewFile *.md setlocal textwidth=80
set ai " Auto indent
set si " Smart indent
" Line numbers
set number
highlight LineNr ctermfg=24
" # Visual mode stuff
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" # Moving around, tabs, windows, and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" let's see if I can move off NerdTree
let g:netrw_banner=0 " disable banner
let g:netrw_browse_split=4 " open in prior window
let g:netrw_liststyle=3 " treeview
let g:netrw_winsize=24
let g:netrw_sort_options='i'
let g:netrw_localrmdir='rm -r'
let g:netrw_list_hide = '^\./$'
let g:netrw_hide = 1
" Open netrw automatically on startup if no file is specified
autocmd VimEnter * if !argc() | Explore | endif
" Open when opening a directory
autocmd VimEnter * if isdirectory(expand('<afile>')) | Explore | endif
" Hide dot files by default
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
autocmd FileType netrw setlocal bufhidden=delete
" toggle netrw on the left side of the editor
nnoremap <leader>n :Lexplore<CR>
" some netrw key bindings
augroup netrw_mapping
autocmd!
autocmd filetype netrw call NetrwMapping()
augroup END
" to change top tree level type C or gn
function! NetrwMapping()
noremap <buffer> C :Ntree<CR>
endfunction
" toggle folds in markdown files (vim-fold-toggle plugin)
nnoremap <leader>ft :FoldToggle<CR>
" Split vertically to bottom
set splitbelow
" buffers
nnoremap <leader>b :buffers<CR>:buffer<space>
" # Status line
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" # Key bindings
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Make `jj` and `jk` throw you into normal mode
inoremap jj <esc>
inoremap jk <esc>
" Remap HJKL to something more useful
nnoremap H ^
nnoremap L $
nnoremap J <C-d>
nnoremap K <C-u>
" I don't like d to copy
nnoremap <leader>d "_d
xnoremap <leader>d "_d
xnoremap <leader>p "_dP
" Type mm to cut a line
nnoremap mm yydd
" Find & replace helpers
" /foo<CR>, press CMD+d, fill and hit return
nnoremap <C-g> :%s///g<Left><Left>
" and here for those who have 'gdefault' enabled
nnoremap gs :%s//<Left>
" Move visual block
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" Moves the matches for your search to the center of the screen when you press n or N
nnoremap n nzz
nnoremap N Nzz
" Type ,w to save, ,q to exit
nmap <leader>w :w!<cr>
nmap <leader>q :q!<cr>
" Type ,wq to save and exit
nmap <leader>wq :wq!<cr>
set conceallevel=2
" # Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Briefly highlight the part of the buffer that was yanked.
function! s:hl_yank() abort
let [sl, el, sc, ec] = [line("'["), line("']"), col("'["), col("']")]
if sl == el
let pos_list = [[sl, sc, ec - sc + 1]]
else
let pos_list = [[sl, sc, col([sl, "$"]) - sc]] + range(sl + 1, el - 1) + [[el, 1, ec]]
endif
for chunk in range(0, len(pos_list), 8)
call matchaddpos('IncSearch', pos_list[chunk:chunk + 7])
endfor
redraw!
call timer_start(500, {t_id -> clearmatches()})
endfunction
augroup HlYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call s:hl_yank() | endif
augroup END
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Fix esc lag
set timeoutlen=1000 ttimeoutlen=0
" # Functions
"""""""""""""""""""""""""""""""""""""""""""""""""""
" # Plugin settings
"""""""""""""""""""""""""""""""""""""""""""""""""""
" Bracket highlighting
let g:rainbow_active = 1
" Search down into subfolders, provides tab-completion
set path+=**
" Emmet
imap <expr> <tab> emmet#expandAbbrIntelligent("\<tab>")
" easymotion
nnoremap ,z H:call EasyMotion#WB(0, 0)<CR>
" Git gutter
set updatetime=100
" let g:EasyMotion_use_upper = 1 " Use uppercase target labels and type as a lower case
let g:EasyMotion_smartcase = 1 " type `l` and match `l`&`L`
let g:EasyMotion_use_smartsign_us = 1 " Smartsign (type `3` and match `3`&`#`)
let g:EasyMotion_do_mapping = 0 " Disable default mappings
map <Leader> <Plug>(easymotion-prefix)
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
nmap s <Plug>(easymotion-overwin-f)
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" Fuzzy Find :FZF
nmap <leader>f :FZF<cr>
nnoremap <C-p> :CtrlP<Cr>
" Crystalline
function! StatusLine(current, width)
let l:s = ''
if a:current
let l:s .= crystalline#mode() . crystalline#right_mode_sep('')
else
let l:s .= '%#CrystallineInactive#'
endif
let l:s .= ' %f%h%w%m%r '
if a:current
let l:s .= crystalline#right_sep('', 'Fill') . ' %{fugitive#head()}'
endif
let l:s .= '%='
if a:current
let l:s .= crystalline#left_sep('', 'Fill') . ' %{&paste ?"PASTE ":""}%{&spell?"SPELL ":""}'
let l:s .= crystalline#left_mode_sep('')
endif
if a:width > 80
let l:s .= ' %{&ft}[%{&enc}][%{&ffs}] %l/%L %c%V %P '
else
let l:s .= ' '
endif
return l:s
endfunction
function! TabLine()
let l:vimlabel = has('nvim') ? ' NVIM ' : ' VIM '
return crystalline#bufferline(2, len(l:vimlabel), 1) . '%=%#CrystallineTab# ' . l:vimlabel
endfunction
let g:crystalline_enable_sep = 1
let g:crystalline_statusline_fn = 'StatusLine'
let g:crystalline_tabline_fn = 'TabLine'
let g:crystalline_theme = 'dracula'
set showtabline=2
set guioptions-=e
set laststatus=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment