Last active
May 29, 2021 07:00
-
-
Save hardyscc/df7349431d13993eff21c0d34182d439 to your computer and use it in GitHub Desktop.
curl -fsL https://gist.githubusercontent.com/hardyscc/df7349431d13993eff21c0d34182d439/raw/setup-vimrc.sh | sh
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
set nocompatible " be iMproved, required | |
filetype off " required | |
let &t_SI.="\e[5 q" "SI = INSERT mode | |
let &t_SR.="\e[4 q" "SR = REPLACE mode | |
let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE) | |
" Auto install VimPlug | |
if empty(glob('~/.vim/autoload/plug.vim')) | |
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs | |
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | |
endif | |
" Keep Plug commands between plug#begin() and plug#end(). | |
call plug#begin() | |
Plug 'morhetz/gruvbox' " Best color scheme | |
Plug 'vim-utils/vim-man' " Man page | |
Plug 'mbbill/undotree' " Undo history | |
Plug 'airblade/vim-gitgutter' " Show git diff of lines edited | |
Plug 'tpope/vim-fugitive' " :Gblame | |
Plug 'tpope/vim-endwise' " Autocomplete end after a do | |
Plug 'mileszs/ack.vim' " Use ack in Vim | |
Plug 'pangloss/vim-javascript' " JavaScript support | |
Plug 'leafgarland/typescript-vim' " TypeScript syntax | |
Plug 'maxmellon/vim-jsx-pretty' " JS and JSX syntax | |
Plug 'jparise/vim-graphql' " GraphQL syntax | |
Plug 'vim-airline/vim-airline' " Vim powerline | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' " Set up fzf and fzf.vim | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
" All of your Plugins must be added before the following line | |
call plug#end() " required | |
filetype plugin indent on " required | |
" Activate color scheme | |
silent! colorscheme gruvbox | |
" jk to exit insert mode | |
imap jk <Esc> | |
" Leader key is SPACE, I find it the best | |
let mapleader = " " | |
" Look and Feel settings | |
syntax enable | |
set background=dark | |
set wildmenu " when opening a file with e.g. :e ~/.vim<TAB> there is a graphical menu of all the matches | |
set ttyfast | |
set lazyredraw | |
set updatetime=300 | |
" Numbers | |
set number | |
set relativenumber | |
set numberwidth=4 | |
set ruler | |
" paste mode | |
nnoremap <F5> :set invpaste paste?<CR> | |
set pastetoggle=<F5> | |
set showmode | |
" Treat long lines as break lines | |
map j gj | |
map k gk | |
" Indentation | |
set autoindent | |
set cindent | |
set smartindent | |
" Folding | |
" Enable folding | |
set foldmethod=syntax | |
set foldlevel=99 | |
" Enable folding with the z key | |
nmap z za | |
" Disable all bells and whistles | |
set noerrorbells visualbell t_vb= | |
" Ack tricks | |
let g:ackprg = 'ag --vimgrep' | |
nmap <leader>a :Ack! ""<Left> | |
nmap <leader>A :Ack! "\b<cword>\b"<CR> | |
" Tab Options | |
set shiftwidth=2 | |
set tabstop=2 | |
set softtabstop=2 " Number of spaces a tab counts when editing | |
set expandtab | |
" Delete empty space from the end of lines on every save | |
autocmd BufWritePre * :%s/\s\+$//e | |
" Set default encoding to utf-8 | |
set encoding=utf-8 | |
set termencoding=utf-8 | |
" Disable backups and swap files | |
set nobackup | |
set nowritebackup | |
set noswapfile | |
set ignorecase " Ignore case when searching | |
set smartcase " When searching try to be smart about cases | |
set nohlsearch " Don't highlight search term | |
set incsearch " Jumping search | |
" Always show the status line | |
set laststatus=2 | |
" Allow copy and paste from system clipboard | |
set clipboard=unnamed | |
" Spellcheck for features and markdown | |
au BufRead,BufNewFile *.md setlocal spell | |
au BufRead,BufNewFile *.md.erb setlocal spell | |
au BufRead,BufNewFile *.feature setlocal spell | |
" Delete characters outside of insert area | |
set backspace=indent,eol,start | |
" +++ Shortcuts +++ | |
" Open Buffer | |
nnoremap <silent><leader>l :Buffers<CR> | |
" Open test file for a current file | |
nnoremap <silent><leader>s :A<CR> | |
" Open test file for a current file in a vertical window | |
nnoremap <silent><leader>v :AV<CR> | |
" Vertically split screen | |
nnoremap <silent><leader>\ :vs<CR> | |
" Split screen | |
nnoremap <silent><leader>/ :split<CR> | |
" Terminal | |
nnoremap <silent><leader>t :term<CR> | |
" Faster saving and exiting | |
nnoremap <silent><leader>w :w!<CR> | |
nnoremap <silent><leader>q :q!<CR> | |
nnoremap <silent><leader>x :x<CR> | |
" Open Vim configuration file for editing | |
nnoremap <silent><leader>2 :e ~/.vimrc<CR> | |
" Source Vim configuration file and install plugins | |
nnoremap <silent><leader>1 :source ~/.vimrc \| :PlugInstall<CR> | |
" If fzf installed using git | |
set rtp+=~/.fzf | |
" Map fzf search to CTRL P | |
nnoremap <C-p> :GFiles<Cr> | |
" Map fzf + ag search to CTRL G | |
nnoremap <C-g> :Ag<Cr> | |
" vim-test shortcut for running tests | |
"nnoremap <silent><leader>; :TestNearest<CR> | |
"nnoremap <silent><leader>' :TestFile<CR> | |
"let test#ruby#rspec#executable = 'spring rspec' | |
" Extra <CR> is for disabling /"Press ENTER or type command to continue/" | |
nnoremap <silent><leader>e :Exp<CR><CR> | |
" Easier movement between split windows CTRL + {h, j, k, l} | |
nnoremap <c-h> <c-w>h | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-l> <c-w>l | |
" Switch between buffers | |
:nnoremap <C-d> :bdelete<CR> | |
" Fugitive | |
nmap <leader>gh :diffget //3<CR> | |
nmap <leader>gu :diffget //2<CR> | |
nmap <leader>gs :G<CR> | |
" Undotree | |
"set undodir=~/.vim/undodir | |
"set undofile | |
"let undodir=&undodir | |
"if !isdirectory(undodir) | |
" silent !mkdir -p undodir | |
"endif | |
"nnoremap <leader>u :UndotreeShow<CR><c-w>h | |
" CoC extensions | |
let g:coc_global_extensions = ['coc-marketplace', 'coc-tsserver', 'coc-json'] | |
" Add CoC Prettier if prettier is installed | |
if isdirectory('./node_modules') && isdirectory('./node_modules/prettier') | |
let g:coc_global_extensions += ['coc-prettier'] | |
endif | |
" Add CoC ESLint if ESLint is installed | |
if isdirectory('./node_modules') && isdirectory('./node_modules/eslint') | |
let g:coc_global_extensions += ['coc-eslint'] | |
endif | |
" TextEdit might fail if hidden is not set. | |
set hidden | |
" Give more space for displaying messages. | |
"set cmdheight=2 | |
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable | |
" delays and poor user experience. | |
set updatetime=300 | |
" Don't pass messages to |ins-completion-menu|. | |
set shortmess+=c | |
" Always show the signcolumn, otherwise it would shift the text each time | |
" diagnostics appear/become resolved. | |
if has("patch-8.1.1564") | |
" Recently vim can merge signcolumn and number column into one | |
set signcolumn=number | |
else | |
set signcolumn=yes | |
endif | |
" Use tab for trigger completion with characters ahead and navigate. | |
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by | |
" other plugin before putting this into your config. | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
" Use <c-space> to trigger completion. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current | |
" position. Coc only does snippet and additional edit on confirm. | |
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`. | |
"if exists('*complete_info') | |
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
"else | |
" inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
"endif | |
" Use `[g` and `]g` to navigate diagnostics | |
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. | |
nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
" GoTo code navigation. | |
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) | |
" Use K to show documentation in preview window. | |
"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 | |
" Highlight the symbol and its references when holding the cursor. | |
autocmd CursorHold * silent call CocActionAsync('highlight') | |
" Symbol renaming. | |
nmap <leader>rn <Plug>(coc-rename) | |
"" Formatting selected code. | |
xmap <leader>f <Plug>(coc-format-selected) | |
nmap <leader>f <Plug>(coc-format-selected) | |
augroup mygroup | |
autocmd! | |
" Setup formatexpr specified filetype(s). | |
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') | |
" Update signature help on jump placeholder. | |
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') | |
augroup end | |
" Applying codeAction to the selected region. | |
" Example: `<leader>aap` for current paragraph | |
xmap <leader>a <Plug>(coc-codeaction-selected) | |
nmap <leader>a <Plug>(coc-codeaction-selected) | |
" Remap keys for applying codeAction to the current buffer. | |
nmap <leader>ac <Plug>(coc-codeaction) | |
" Apply AutoFix to problem on the current line. | |
nmap <leader>qf <Plug>(coc-fix-current) | |
" Map function and class text objects | |
" NOTE: Requires 'textDocument.documentSymbol' support from the language server. | |
xmap if <Plug>(coc-funcobj-i) | |
omap if <Plug>(coc-funcobj-i) | |
xmap af <Plug>(coc-funcobj-a) | |
omap af <Plug>(coc-funcobj-a) | |
xmap ic <Plug>(coc-classobj-i) | |
omap ic <Plug>(coc-classobj-i) | |
xmap ac <Plug>(coc-classobj-a) | |
omap ac <Plug>(coc-classobj-a) | |
" Use CTRL-S for selections ranges. | |
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver | |
nmap <silent> <C-s> <Plug>(coc-range-select) | |
xmap <silent> <C-s> <Plug>(coc-range-select) | |
" Add `:Format` command to format current buffer. | |
command! -nargs=0 Format :call CocAction('format') | |
" Add `:Fold` command to fold current buffer. | |
command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
" Add `:OR` command for organize imports of the current buffer. | |
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') | |
" Add (Neo)Vim's native statusline support. | |
" NOTE: Please see `:h coc-status` for integrations with external plugins that | |
" provide custom statusline: lightline.vim, vim-airline. | |
"set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
" Mappings for CoCList | |
" Show all diagnostics. | |
"nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr> | |
"" Manage extensions. | |
"nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr> | |
"" Show commands. | |
"nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr> | |
"" Find symbol of current document. | |
"nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr> | |
"" Search workspace symbols. | |
"nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr> | |
"" Do default action for next item. | |
"nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR> | |
"" Do default action for previous item. | |
"nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR> | |
"" Resume latest coc list. | |
"nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR> |
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
{ | |
"coc.preferences.formatOnSaveFiletypes": [ | |
"css", | |
"markdown", | |
"json", | |
"javascript", | |
"javascriptreact", | |
"typescript", | |
"typescriptreact" | |
] | |
} |
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
#!/bin/sh | |
curl -fsLo ~/.vimrc https://gist.githubusercontent.com/hardyscc/df7349431d13993eff21c0d34182d439/raw/.vimrc | |
curl -fsLo ~/.vim/coc-settings.json --create-dirs https://gist.githubusercontent.com/hardyscc/df7349431d13993eff21c0d34182d439/raw/coc-settings.json | |
echo "Your .vimrc has been updated, please run vim to complete the setup." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment