Skip to content

Instantly share code, notes, and snippets.

@toidang92
Last active October 13, 2023 11:22
Show Gist options
  • Save toidang92/a9577682d037cb53d06d0775d1c09576 to your computer and use it in GitHub Desktop.
Save toidang92/a9577682d037cb53d06d0775d1c09576 to your computer and use it in GitHub Desktop.
" Install Vim
" sudo apt-get install vim
" brew install vim --with-python3
" Install Vundle
" git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
" $ vim
" $ :PluginInstall
set nocompatible " be iMproved, require
" Disable bell sound
set belloff=all
" Disable auto-comment
set paste
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
"Plugin 'L9'
" Git plugin not hosted on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Avoid a name conflict with L9
"Plugin 'user/L9', {'name': 'newL9'}
" Remapings {" My plugins
Plugin 'myusuf3/numbers.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'tpope/vim-projectionist'
Plugin 'jlanzarotta/bufexplorer'
Plugin 'adelarsq/vim-matchit'
Plugin 'preservim/nerdtree'
Plugin 'preservim/nerdcommenter'
Plugin 'kchmck/vim-coffee-script'
" Ruby on Rails
" brew install cmake
" gem install ruby-lsp
" cd /Users/toidb/.config/nvim/bundle/YouCompleteMe/
" python3 install.py
" python3 -m pip install --user --upgrade pynvim
Plug 'Valloric/YouCompleteMe'
Plugin 'vim-ruby/vim-ruby'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-rake'
Plugin 'tpope/vim-bundler'
Plugin 'slim-template/vim-slim.git'
" Javascript
Plugin 'Quramy/tsuquyomi'
Plugin 'HerringtonDarkholme/yats.vim'
Plugin 'leafgarland/typescript-vim'
Plugin 'peitalin/vim-jsx-typescript'
Plugin 'jparise/vim-graphql'
" Fzf
" MacOS: brew install fzf
" Ubuntu: sudo apt-get install fzf ripgrep
Plugin 'junegunn/fzf.vim'
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Multiple cursor
Plugin 'mg979/vim-visual-multi'
" Indent Guides
Plugin 'nathanaelkane/vim-indent-guides'
" Autocomplete
" Plugin 'Shougo/deoplete.nvim'
" Plugin 'roxma/nvim-yarp'
" Plugin 'roxma/vim-hug-neovim-rpc'
" Theme
" Plugin 'tomasiser/vim-code-dark'
" Plugin 'GlennLeo/cobalt2'
Plugin 'NLKNguyen/papercolor-theme'
" Use fd instead of find so node_modules doesn't get indexed
let FZF_DEFAULT_COMMAND='fd --type f'
" ripgrep if we have it
if executable('rg')
let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!.git/*"'
endif
" Nerdtree
let g:NERDTreeShowHidden = 1
let g:NERDTreeWinSize = 40
let g:NERDTreeRespectWildIgnore=1
" Plugin configurations & overrides
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tagbar#enabled = 1
" Add Ag default options
" let s:ag_options = ' --one-device --skip-vcs-ignores --smart-case'
" Indent Guides
let g:indent_guides_auto_colors = 0
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 2
" Autocomplete
" let g:deoplete#enable_at_startup = 1
" Auto open NERDTree on vim startup
" Add <bookmark> can be useful if you have a dir that you frequently
" open with vim
" autocmd VimEnter * NERDTree <bookmark>
let g:ctrlp_working_path_mode = 0
let g:ctrlp_open_new_file = 'r'
let g:ctrlp_match_window = 'bottom,order:ttb,min:1,max:10,results:10'
let g:ctrlp_custom_ignore = 'node_modules\|DS_Store\|git'
let g:ctrlp_switch_buffer = 0
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " requiredlet NERDTreeWinSize = 1
"
" Brief help
" :PluginList - list configured plugins
" :PluginInstall(!) - install (update) plugins
" :PluginSearch(!) foo - search (or refresh cache first) for foo
" :PluginClean(!) - confirm (or auto-approve) removal of unused plugins
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line syntax on
" Custom functions
" Make Ripgrep ONLY search file contents and not filenames
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --hidden --ignore-case --no-heading --color=always '
\ .(len(<q-args>) > 0 ? shellescape(<q-args>) : '""'), 1,
\ <bang>0 ? fzf#vim#with_preview({'options': '--delimiter : --nth 4..'}, 'up:60%')
\ : fzf#vim#with_preview({'options': '--delimiter : --nth 4.. -e'}, 'right:50%:hidden', '?'),
\ <bang>0)
" Add fun to trim trailing whitespaces
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
" Define a command to make it easier to use
command! TrimWS call TrimWhitespace()
" Function that does the work
function! QFDo(command)
" Create a dictionary so that we can
" get the list of buffers rather than the
" list of lines in buffers (easy way
let NERDTreeRespectWildIgnore=1 " to get unique entries)
let buffer_numbers = {}
" For each entry, use the buffer number as
" a dictionary key (won't get repeats)
for fixlist_entry in getqflist()
let buffer_numbers[fixlist_entry['bufnr']] = 1
endfor
" Make it into a list as it seems cleaner
let buffer_number_list = keys(buffer_numbers)
" For each buffer
for num in buffer_number_list
" Select the buffer
exe 'buffer' num
" Run the command that's passed as an argument
exe a:command
" Save if necessary
update
endfor
endfunction
" Define a command to make it easier to use
command! -nargs=+ QFDo call QFDo(<q-args>)
" Close all buffers except for the current one
command! BdOnly silent! execute "%bd|e#|bd#"
" Theme configurations
if has('termguicolors')
set termguicolors
endif
" Color settingslet NERDTreeWinSize = 1
set background=dark
colorscheme PaperColor
" Enable syntax highlighting
syntax on
" Appearance
" 80-column mark
augroup OverLengthHighlight
autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#5f8787
autocmd BufEnter * match OverLength /\%160v.*/
augroup END
" Current line
augroup CursorLine
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline cursorcolumn
au VimEnter,WinEnter,BufWinEnter * highlight CursorColumn guibg=#303030
au WinLeave * setlocal nocursorline nocursorcolumn
augroup END
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=238
autocmd VimEnter,Colorscheme * :hi IndentGuidesOld ctermbg=236
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clear
if system('uname -r') =~ "microsoft"
augroup WSLYank
autocmd!
autocmd TextYankPost * :call system('/mnt/c/windows/system32/clip.exe ',@")
augroup END
endif
" Common settings
set backspace=2
set tabstop=2
set shiftwidth=2
set encoding=utf-8
set fileencodings=urf-8
set clipboard=unnamed
set numberwidth=4
set history=10000
set shell=/bin/zsh
set expandtab " Converting tabs to spaces
set autoread " Set to auto read when a file is changed from the outside
set autowriteall " Set to auto write file
set noshowmode " No need to show mode due to Powerline
" Auto completion menu with matches list
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildmode=list:longest
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*DS_Store*
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*app/cache/**
set wildignore+=*.png,*.jpg,*.gif
set wildignore+=*.so,*.swp,*.zip,*.swo
set wildignore+=*.git/**,.svn/**,*.git,*.svn,*.bundle
" Display unprintable chars
set list
set listchars=tab:▸\ ,trail:·,extends:❯,precedes:❮,nbsp:␣
set showbreak=↪
" Higlighting
set redrawtime=10000
set hlsearch " Highlight search (very useful!)
set incsearch " Search incremently (search while typing)
set ignorecase " Ignore case searching
set showcmd " Show command in bottom bar
set cursorline " Highlight current line"
" Remapings
" Nerdtree plugin mappings
nnoremap <Leader>n :NERDTreeToggle<CR>
nnoremap <Leader>sf :NERDTreeFind<CR>
" Other helpers mappings
nnoremap <C-p> :Files<CR>
nnoremap <C-b> :Buffers<CR>
nnoremap <C-f> :Rg<CR>
nnoremap <C-n> :Lines<CR>
nnoremap <C-s> :GFiles?<CR>
nnoremap <Leader>h :History<CR>
" Tags plugin mappings
nnoremap <Leader>t :BTags<CR>
nnoremap <Leader>T :Tags<CR>
" Tab mappings
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>
" Quickfix mappings
map <C-j> :cn<CR>
map <C-k> :cp<CR>
" Buffers mappings
map <S-j> :bprev<CR>
map <S-k> :bnext<CR>
" Delete a line without putting it into my default buffer
nnoremap x "_x
nnoremap <leader>d "_d
xnoremap <leader>d "_d
xnoremap <leader>p "_dP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment