Skip to content

Instantly share code, notes, and snippets.

@SpencerAung
Last active Aug 11, 2021
Embed
What would you like to do?
Vim and Neovim setup
[credential]
helper = osxkeychain
[core]
editor = nvim
[Alias]
trail = log --all --graph --decorate --oneline
b = branch
c = commit
d = diff
l = log
p = push
s = status
f = "fetch --all"
cp = "!f() { git commit -am $1; git push }; f"
pl = pull
po = "!f() { git pull origin $1; }; f"
co = checkout
nb = "!f() { git checkout -b $1; git push --set-upstream origin $1; }; f"
cam = "!f() { git c -am $1; }; f"
tree = "log --graph --decorate --pretty=oneline --abbrev-commit"
fire = "!f() { git commit -am emergency; git pull; git push -f }"
subupdate = "submodule update --recursive --remote --merge"
show-current = rev-parse --abbrev-ref HEAD
[mergetool "nvim"]
cmd = nvim -f -c \"Gdiffsplit!\" \"$MERGED\"
[merge]
tool = fugitive
[mergetool]
prompt = false
[mergetool "fugitive"]
cmd = nvim -f -c \"Gvdiffsplit!\" \"$MERGED\"
# plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
# fix key binding
set -g prefix C-b
bind C-b send-prefix
unbind C-a
set -g focus-events on
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'
so ~/.vim/plugins.vim
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab "expand tabs to spaces
"set autochdir
set relativenumber
set number
set autoread
au CursorHold * checktime
" Search down into subfolders
" Provides tab-completion for all file-related tasks
set path+=**
" Display all matching files when we tab complete
set wildmenu
" Ignore node_modules folder
set wildignore+=**/node_modules/**
"##### Color
" set color scheme
" set t_Co=256
" set termguicolors
"##### Key mappings
imap jk <Esc>
imap kj <Esc>
" Delete all buffer except current one
nnoremap cb :%bd \| e#<CR>
" Copy content to clipboard
nnoremap <leader>ca ggVG"*y<Esc><C-o>
" Add a blank line below
nnoremap al o<Esc>
" Add a blank line above
nnoremap aL O<Esc>
" Open ~/.vimrc in a vsplit
nnoremap <leader>ev :vsplit ~/.vimrc<CR>
" Open ~/.vim/plugins.vim in a vsplit
nnoremap <leader>ep :vsplit ~/.vim/plugins.vim<CR>
" Source .vimrc
nnoremap <leader>sv :source ~/.vimrc<CR>
" PrettierAsync
nnoremap <leader>pa :PrettierAsync<CR>
" Markdown Preview
nnoremap <leader>mp :MarkdownPreview<CR>
" Open current dir
nnoremap dir :e .<CR>
" Open notes dir
nnoremap <leader>on :vsplit ~/Notes<CR>
" Behave Vim
nnoremap Y y$
" Keeping it centered
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap J mzJ`z
" Undo break points
inoremap , ,<C-g>u
inoremap . .<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
" Jumplist mutations
nnoremap <expr> k (v:count > 5 ? "m'" . v:count : "") . 'k'
nnoremap <expr> j (v:count > 5 ? "m'" . v:count : "") . 'j'
" Moving text
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
inoremap <C-j> <esc>:m .+1<CR>==
inoremap <C-k> <esc>:m .-2<CR>==
nnoremap <leader>j :m .+1<CR>==
nnoremap <leader>k :m .-2<CR>==
echo "Hello, Spencer >^.^<"
" ~/.config/nvim/init.vim
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc
" LSP config (the mappings used in the default file don't quite work right)
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> [g <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
nnoremap <silent> ]g <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
" LSP auto format
" autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100)
" autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
" TS server
" Dependency: npm install -g typescript typescript-language-server
:lua require('lspconfig').tsserver.setup{}
" Ember
" Dependency: npm install -g @lifeart/ember-language-server
:lua require('lspconfig').ember.setup{}
" Css & Html
" Dependency: npm i -g vscode-langservers-extracted
lua << EOF
--Enable (broadcasting) snippet capability for completion
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require('lspconfig').cssls.setup {
capabilities = capabilities,
}
require('lspconfig').html.setup {
capabilities = capabilities,
}
EOF
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
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'junegunn/vim-plug'
Plug 'airblade/vim-gitgutter'
Plug 'kien/rainbow_parentheses.vim'
Plug 'tpope/vim-commentary'
Plug 'joegesualdo/jsdoc.vim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'tmux-plugins/vim-tmux-focus-events'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
Plug 'tpope/vim-unimpaired'
Plug 'edkolev/tmuxline.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'airblade/vim-rooter'
Plug 'nathanaelkane/vim-indent-guides'
" NerdTree
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Fzf
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" Fixer
" Plug 'dense-analysis/ale'
Plug 'prettier/vim-prettier', { 'do': 'npm install' }
Plug 'ntpeters/vim-better-whitespace'
Plug 'editorconfig/editorconfig-vim'
" Vim Airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Telescope Requirements
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
" Neovim LSP
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-compe'
" Treesitter
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' }
" Themes
Plug 'jaredgorski/spacecamp'
Plug 'morhetz/gruvbox'
call plug#end()
" coc
let g:coc_disable_startup_warning = 1
" coc multi cursor
nmap <silent> <C-c> <Plug>(coc-cursors-position)
nmap <silent> <C-d> <Plug>(coc-cursors-word)
xmap <silent> <C-d> <Plug>(coc-cursors-range)
" use normal command like `<leader>xi(`
nmap <leader>x <Plug>(coc-cursors-operator)
highlight NormalFloat ctermbg=17
" 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)
" rename
nmap <leader> rr <Plug>(coc-rename)
nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
" vim fugitive
nmap <leader>gl :diffget //2<CR>
nmap <leader>gr :diffget //3<CR>
nmap <leader>gu :diffupdate<CR>
nmap <leader>gs :G<CR>
" ale
" \ 'javascript': ['tsserver'],
" \ 'javascript': ['prettier', 'tsserver']
" let g:ale_fixers = {
" \ '*': ['remove_trailing_lines', 'trim_whitespace'],
" \ 'scss': ['prettier', 'sasslint', 'stylelint'],
" \ 'handlebars': ['prettier', 'ember-template-lint'],
" \ 'html': ['prettier']
" \}
" let g:ale_linters = {
" \ 'handlebars': ['ember-template-lint']
" \}
" let g:ale_typescript_standard_options = '--fix'
" let g:ale_typescript_standard_use_global = 1
" let g:ale_sign_error = '>>'
" let g:ale_sign_warning = '--'
" let g:ale_lint_on_save = 1
" let g:ale_fix_on_save = 1
" " run ale linting explicit
" let g:ale_linters_explicit = 0
" let g:ale_completion_tsserver_autoimport = 1
" let g:ale_set_highlights = 0
" let g:ale_hover_to_preview = 1
" let g:ale_set_balloons =1
" highlight normalfloat ctermbg=17
" nerdtree
let g:nerdtreeshowhidden = 1
" open a nerdtree automatically when vim starts up if no files were specified
autocmd stdinreadpre * let s:std_in=1
"autocmd vimenter * if argc() == 0 && !exists("s:std_in") | nerdtree | endif
" close vim if the only window left open is a nerdtree
autocmd bufenter * if (winnr("$") == 1 && exists("b:nerdtree") && b:nerdtree.istabtree()) | q | endif
" ignore
let g:nerdtreeignore = ['^node_modules']
nmap ,n :NERDTreeFind<cr>
nmap ,m :NERDTreeToggle<cr>
" vim-airline config
let g:airline_powerline_fonts = 0
" let g:airline#extensions#ale#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline_theme= "wombat"
" tmux powerline
let g:tmuxline_powerline_separators = 0
" rainbow_parentheses
au vimenter * RainbowParenthesesToggle
au syntax * RainbowParenthesesLoadRound
au syntax * RainbowParenthesesLoadSquare
au syntax * RainbowParenthesesLoadBraces
" vim-better-whitespace
let g:better_whitespace_enabled = 1
let g:strip_whitespace_on_save = 1
let g:strip_whitespace_confirm = 0
" gitgutter
" let g:gitgutter_highlight_linenrs = 1
set updatetime=100
set signcolumn=yes
nmap ghs <Plug>(GitGutterStageHunk)
nmap ghu <Plug>(GitGutterUndoHunk)
nmap ghp <Plug>(GitGutterPreviewHunk)
omap ih <Plug>(GitGutterTextObjectInnerPending)
omap ah <Plug>(GitGutterTextObjectOuterPending)
xmap ih <Plug>(GitGutterTextObjectInnerVisual)
xmap ah <Plug>(GitGutterTextObjectOuterVisual)
nmap ]h <Plug>(GitGutterNextHunk)
nmap [h <Plug>(GitGutterPrevHunk)
" fzf
fun! FzfOmniFiles()
let is_git = system('git status')
if v:shell_error
:Files
else
:GitFiles
endif
endfun
" nnoremap <C-g>b :Buffers<CR>
nnoremap <C-g>g :Ag<CR>
" nnoremap <leader><leader> :Commands<CR>
" nnoremap <C-p> :call FzfOmniFiles()<CR>
" vim-rooter
let g:rooter_patterns = ['.git/']
let g:rooter_manual_only = 1
"##############################
" vim-mustache-handlebars
" au BufReadPost *.hbs set syntax=mustache
au BufRead,BufNewFile *.handlebars,*.hbs set ft=html syntax=mustache
" vim-indent-guide
let g:indent_guides_enable_on_vim_startup = 0
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 2
" vim cursor
" if exists('$TMUX')
" let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
" let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
" else
" let &t_SI = "\<Esc>]50;CursorShape=1\x7"
" let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" endif
" :autocmd InsertEnter * set cul
" :autocmd InsertLeave * set nocul
"
" Telescope mapping
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <C-p> <cmd>Telescope git_files<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" LSP config
so ~/.vim/lsp-config.vim
" Theme
"
" Spacecamp Theme
" colorscheme spacecamp
" colorscheme spacecamp_lite
" Gruxbox Theme
colorscheme gruvbox
" Prettier
" vim-prettier
let g:prettier#autoformat = 1 "Enable auto formatting of files that havve "@format" or "@prettier" tag
" let g:prettier#autoformat_config_present = 1 "Toggle the g:prettier#autoformat setting based on whether a config file can be found in the current directory or any parent directory.
let g:prettier#autoformat_config_files = ['.prettierrc']
let g:prettier#automat_require_pragma = 0
#!/bin/bash
# install oh-my-zsh!
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install tmux
brew install python
brew install neovim
brew install the_silver_searcher
# install tmux plugin manager
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# if needed, install these
pip3 install --user pynvim
pip3 install --user --upgrade pynv0im
# git config
brew install git
git config --global user.name "username"
git config --global user.email "emailaddress"
# save git credential
git config --global credential.helper osxkeychain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment