Skip to content

Instantly share code, notes, and snippets.

@danstn
Created December 1, 2022 01:23
Show Gist options
  • Save danstn/eedb9bfb7ad9332cecddd58056a24cfb to your computer and use it in GitHub Desktop.
Save danstn/eedb9bfb7ad9332cecddd58056a24cfb to your computer and use it in GitHub Desktop.
A millionth version of my vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CORE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autoindent " enable automatic indentation
set expandtab
set hlsearch " highlight search results
set ignorecase " case insensitive search
set incsearch " match the search and return to the initial position
set list " Show `listchars` characters
set nofoldenable
set number " show line numbers
set showcmd " show command in bottom bar
set showmatch " highlight matching [{()}]
set smartcase " use case sensitive search if a capital letter is used
set warn " show current mode
set wildmenu " visual autocomplete for command menu
set hidden
set secure
set nowrap
set noshowmode
" Editing
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set colorcolumn=80
set tw=79
set autoindent
set smartindent
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Clear highlighed search
nmap <silent> ,/ :nohlsearch<CR>
nmap <Leader>h :bnext<CR>
nmap <Leader>l :bprevious<CR>
" Wrap toggle
:nnoremap <F3> :set wrap!<CR>
" Reload current file
:nnoremap <F5> :source %<CR>
" Save as sudo
cmap w!! w !sudo tee % >/dev/null
" Indent/unindent with tab/shift-tab
map <Tab> >>
imap <S-Tab> <Esc><<i
nmap <S-tab> <<
filetype on
filetype plugin indent on
" Jump to the previous location when opening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
" Strip whitespace on write
fun! StripTrailingWhitespace()
if &ft =~ 'vim\|vimrc'
return
endif
%s/\s\+$//e
endfun
autocmd BufWritePre * call StripTrailingWhitespace()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
runtime autoload/plug.vim
if !exists("*plug#begin")
echo "[ERR] Plug is not installed."
else
call plug#begin()
Plug 'arcticicestudio/nord-vim'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
"Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
if !executable("fzf")
echo "[ERR] fzf is not installed"
else
Plug 'junegunn/fzf.vim'
endif
if !executable("node")
echo "[ERR] node is not installed"
else
Plug 'neoclide/coc.nvim', {'branch': 'release'}
endif
Plug 'vim-airline/vim-airline'
Plug 'tpope/vim-surround'
Plug 'w0rp/ale'
"Plug 'ryanoasis/vim-devicons'
"Plug 'vim-airline/vim-airline'
"Plug 'vim-airline/vim-airline-themes'
"Plug 'maxbrunsfeld/vim-yankstack'
"Plug 'sheerun/vim-polyglot'
"Plug 'honza/vim-snippets'
"Plug 'galooshi/vim-import-js'
"Plug 'godlygeek/tabular'
"Plug 'neovimhaskell/haskell-vim'
"Plug 'parsonsmatt/intero-neovim'
"Plug 'neomake/neomake'
"Plug 'ndmitchell/ghcid', { 'rtp': 'plugins/nvim' }
call plug#end()
endif
if !has_key(plugs, "nord-vim")
echo "[ERR] nord-vim not found"
else
colorscheme nord
let g:nord_italic_comments=1
endif
if !has_key(plugs, "nerdtree")
echo "[ERR] nerdtree not found"
else
nmap <leader>f :NERDTreeToggle<CR>
nmap <leader>F :NERDTreeFind<CR>
let NERDTreeMinimalUI=1
endif
if !has_key(plugs, "fzf.vim")
echo "[ERR] fzf.vim not found"
else
nnoremap <silent> <C-t> :FZF -m<cr>
nnoremap <silent> <C-p> :Files<cr>
nnoremap <silent> <C-f> :Rg<cr>
endif
if !has_key(plugs, "coc.nvim")
echo "[ERR] coc.nvim not found"
else
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ CheckBackspace() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Make <CR> auto-select the first completion item and notify coc.nvim to
" format on enter, <cr> could be remapped by other vim plugin
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Shift+k to show documentation
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Leader + rn to rename
nmap <leader>rn <Plug>(coc-rename)
" Leader + ac for a code action
nmap <leader>ac <Plug>(coc-codeaction)
endif
if !has_key(plugs, "vim-airline")
echo "[ERR] vim-airline not found"
else
let g:airline#extensions#tabline#enabled = 1
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment