Skip to content
Song Zheng edited this page Sep 21, 2022 · 7 revisions
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }

" Using a non-master branch. This is used for autocomplete
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim' " Gives adds editor commands like :Files
" Command list: https://github.com/junegunn/fzf.vim#commands

" Unmanaged plugin (manually installed and updated)
" Plug '~/my-prototype-plugin'

" For JS Development
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'peitalin/vim-jsx-typescript'
Plug 'styled-components/vim-styled-components', { 'branch': 'main' }
Plug 'jparise/vim-graphql'
Plug 'mattn/emmet-vim'

" COC
" Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" AFTERWARDS!!!!
" RUN IN VIM----
" :CocInstall coc-tsserver coc-json coc-html coc-css
" :CocInstall coc-eslint coc-prettier

" Color themes
Plug 'joshdick/onedark.vim'

Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" Git - http://vimcasts.org/episodes/fugitive-vim---a-complement-to-command-line-git/
Plug 'tpope/vim-fugitive'

" https://github.com/airblade/vim-gitgutter
Plug 'airblade/vim-gitgutter'

" Initialize plugin system
call plug#end()

" ------------------------------------------------------
" ------------------------------------------------------
" ------------------------------------------------------
" ---------------- Initialization ------------

" change the mapleader from \ to ,
let mapleader=","

" Source Vim configuration file and install plugins
" https://pragmaticpineapple.com/improving-vim-workflow-with-fzf/
nnoremap <silent><leader>1 :source ~/.vimrc \| :PlugInstall<CR>

" ---------------- End Of Initialization ------------
" ------------------------------------------------------
" ------------------------------------------------------
" ------------------------------------------------------


" ------------------------------------------------------
" ------------------------------------------------------
" ------------------------------------------------------
" ---------------- START PLUGIN RELATED SECTION ------------

" --- start --- Onedark color scheme
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
  if (has("nvim"))
    "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
    let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  endif
  "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
  "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
  " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
  if (has("termguicolors"))
    set termguicolors
  endif
endif

syntax on
colorscheme onedark
" --- END --- Onedark color scheme

" --- start --- NerdTree Settings
map <C-n> :NERDTreeToggle<CR>
" --- END --- NerdTree

" --- start --- COC Settings
" https://github.com/neoclide/coc.nvim/wiki/Completion-with-sources

" use <tab> for trigger completion and navigate to the next complete item
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

" DEBUGGING -
" <tab> could be remapped by another plugin, use :verbose imap <tab> to check if it's mapped as expected.
" --- end --- COC Settings

" --- start --- fzf Settings
nnoremap <C-p> :Files<Cr>
nnoremap <silent><leader>l :Buffers<CR>
nnoremap <Leader>s :Rg<cr>
nnoremap <Leader><C-s> :GFiles?<CR>

let g:fzf_layout = { 'down':  '40%'} " Othwise this will float in the center

" rg command cuts off file name, this disables preview
" Other options: https://github.com/junegunn/fzf.vim/issues/1051#issuecomment-647017856
command! -bang -nargs=* Rg
  \ call fzf#vim#grep(
  \   "rg --column --no-heading --color always --line-number --smart-case -- ".shellescape(<q-args>), 1,
  \   fzf#vim#with_preview('right:hidden', 'ctrl-/'), <bang>0)
" rg --pretty preserves output even when piping to another program (like vim).
" But throws error
" --- end ---

" --- start --- Airline
"  https://github.com/vim-airline/vim-airline-themes#vim-airline-themes--
let g:airline_theme='simple'
" View more themes: https://github.com/vim-airline/vim-airline-themes/issues/1
" --- end ---
" ---------------- END PLUGIN RELATED SECTION ------------
" ------------------------------------------------------
" ------------------------------------------------------
" ------------------------------------------------------
"

" Smart case for search: https://stackoverflow.com/questions/2287440/how-to-do-case-insensitive-search-in-vim
set ignorecase " Vim and Vrapper requires this to be set before smartcase has any effect: https://github.com/vrapper/vrapper/issues/620
set smartcase

" Show linenumber
set number

" --- start --- Tabs vs Spaces
set expandtab       "Use softtabstop spaces instead of tab characters for indentation
set shiftwidth=2    "Indent by 2 spaces when using >>, <<, == etc.
set softtabstop=2   "Indent by 2 spaces when pressing <TAB>

set autoindent      "Keep indentation from previous line
set smartindent     "Automatically inserts indentation in some cases
set cindent         "Like smartindent, but stricter and more customisable
" --- end --- Tabs vs spaces

" Allow you to scroll using mouse scroll wheel
set mouse=a

" Source - https://vim.fandom.com/wiki/Switch_between_Vim_window_splits_easily
set wmw=0           " do not display current line of each minimized file
nmap <c-h> <c-w>h
nmap <c-l> <c-w>l
nmap <c-j> <c-w>j
nmap <c-k> <c-w>k

set noswapfile      " No swap files

" enable incremental search in vim
set incsearch
set hlsearch " Highlight all search results


" Source - https://github.com/ryanpcmcquen/fix-vim-pasting/blob/master/plugin/fix-vim-pasting.vim
" Because Vim doesn't like
" pasting that works.
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"

inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()

function! XTermPasteBegin()
    set pastetoggle=<Esc>[201~
    set paste
    return ""
endfunction
" end of pasting code block

System Setup

Tutorials

Clone this wiki locally