Skip to content

Instantly share code, notes, and snippets.

@ertankayalar
Forked from subfuzion/README.md
Created March 13, 2022 08:52
Show Gist options
  • Save ertankayalar/b1e7d0aabb35a594e60610069dcbef52 to your computer and use it in GitHub Desktop.
Save ertankayalar/b1e7d0aabb35a594e60610069dcbef52 to your computer and use it in GitHub Desktop.
vim/neovim configuration
" Plug (vim-plug) - plugin manager
" https://github.com/junegunn/vim-plug
" Basically: after adding a plug, just remember to run 'PlugInstall'
" This is best with neovim!
" https://neovim.io/
" http://nerditya.com/code/guide-to-neovim/
" Other helpful links:
" http://learnvimscriptthehardway.stevelosh.com/
" http://andrewradev.com/2011/08/06/making-vim-pretty-with-custom-colors/
" =====================================
call plug#begin('~/.vim/plugged')
" -------------------------------------
" various color schemes (neovim default is 'dark'; I like 'slate' with dark background)
" http://vimcolors.com/
Plug 'freeo/vim-kalisi'
Plug 'w0ng/vim-hybrid'
Plug 'bitterjug/vim-colors-bitterjug'
Plug 'jonathanfilip/vim-lucius'
Plug 'crusoexia/vim-monokai'
Plug 'jacoborus/tender.vim'
Plug 'pbrisbin/vim-colors-off'
Plug 'muellan/am-colors'
Plug 'blueshirts/darcula'
" NERD Tree - tree explorer
" https://github.com/scrooloose/nerdtree
" http://usevim.com/2012/07/18/nerdtree/
" (loaded on first invocation of the command)
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" nerdtree-git-plugin - show git status in NERD Tree
" https://github.com/Xuyuanp/nerdtree-git-plugin
Plug 'Xuyuanp/nerdtree-git-plugin'
" vim-airline
" Enhanced statusline
" https://github.com/vim-airline/vim-airline
Plug 'vim-airline/vim-airline'
" https://github.com/vim-airline/vim-airline-themes
Plug 'vim-airline/vim-airline-themes'
" Save/restore session support
" https://github.com/tpope/vim-obsession
" tmux users also see: https://github.com/tmux-plugins/tmux-resurrect/blob/master/docs/restoring_vim_and_neovim_sessions.md
Plug 'tpope/vim-obsession'
" Excellent git wrapper
" https://github.com/tpope/vim-fugitive
Plug 'tpope/vim-fugitive'
" Enforce editor settings
" https://github.com/editorconfig/editorconfig-vim
Plug 'editorconfig/editorconfig-vim'
" Make vim a first class Go development environment
" https://github.com/fatih/vim-go
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
" vim-misc
" https://github.com/xolox/vim-misc
Plug 'xolox/vim-misc'
" vim-easytags
" https://github.com/xolox/vim-easytags
Plug 'xolox/vim-easytags'
" Tagbar
" https://github.com/majutsushi/tagbar
Plug 'majutsushi/tagbar'
" https://github.com/nsf/gocode
Plug 'nsf/gocode', { 'rtp': 'nvim', 'do': '~/.config/nvim/plugged/gocode/nvim/symlink.sh' }
" deoplete (for gocode completion support)
" https://github.com/Shougo/deoplete.nvim
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" deoplete-go (for gocode completion support)
" https://github.com/zchee/deoplete-go
Plug 'zchee/deoplete-go', { 'do': 'make'}
" Markdown support
" https://github.com/plasticboy/vim-markdown
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
" Nice interaction with tmux
" https://github.com/benmills/vimux
Plug 'benmills/vimux'
" Fuzzy file, buffer, mru, tag, etc finder
" ctrlp.vim
" https://github.com/ctrlpvim/ctrlp.vim
Plug 'ctrlpvim/ctrlp.vim'
" A better grep (source code aware)
" You must install ack on your machine for the plugin to work
" sudo apt-get install ack-grep, brew install ack, etc.
Plug 'mileszs/ack.vim'
" OMG - insanely awesome fuzzy search and blazing fast grep
" https://github.com/junegunn/fzf (parent project)
" https://github.com/junegunn/fzf.vim (more extensive wrapper)
" https://medium.com/@crashybang/supercharge-vim-with-fzf-and-ripgrep-d4661fc853d2#.rkhrm332m
" To update: :PlugUpdate fzf
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" indentline
" https://github.com/Yggdroot/indentLine
Plug 'Yggdroot/indentLine'
" -------------------------------------
" Add plugins to &runtimepath
call plug#end()
" =====================================
" Auto start NERD tree when opening a directory
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | wincmd p | endif
" Auto start NERD tree if no files are specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | exe 'NERDTree' | endif
" Let quit work as expected if after entering :q the only window left open is NERD Tree itself
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" =====================================
" Initial settings
" =====================================
" Relax file compatibility restriction with original vi
" (not necessary to set with neovim, but useful for vim)
set nocompatible
" Disable beep / flash
set vb t_vb=
" Set tabs and indents (for go)
set ts=8
set shiftwidth=8
set ai sw=8
" replace tab with spaces
"set expandtab
" allow cursor to move to beginning of tab
" will interfere with soft line wrapping (set nolist)
set list lcs=tab:\ \
" highlight matches when searching
" Use C-l to clear (see key map section)
set hlsearch
" Line numbering
" Toggle set to ';n' in key map section
set nonumber
" Disable line wrapping
" Toggle set to ';w' in key map section
set nowrap
" enable line and column display
set ruler
"disable showmode since using vim-airline; otherwise use 'set showmode'
set noshowmode
" file type recognition
filetype on
filetype plugin on
filetype indent on
" syntax highlighting
syntax on
" scroll a bit horizontally when at the end of the line
set sidescroll=6
" Make it easier to work with buffers
" http://vim.wikia.com/wiki/Easier_buffer_switching
set hidden
set confirm
set autowriteall
set wildmenu wildmode=full
" markdown
" https://github.com/plasticboy/vim-markdown
let g:vim_markdown_folding_disabled = 1
" auto switch current working directory to current buffer (not recommended)
"autocmd BufEnter * :cd %:p:h
" open new split panes to right and below (as you probably expect)
set splitright
set splitbelow
" Use Ag (the silver searcher) instack of Ack
let g:ackprg = 'ag --nogroup --nocolor --column'
" =====================================
" Theme color scheme settings
" =====================================
" blue
" darkblue
" default
" delek
" desert
" elflord
" evening
" koehler
" morning
" murphy
" pablo
" peachpuff
" ron
" shine
" slate
" torte
" zellner
" -------------------------------------
function! Light()
echom "set bg=light"
set bg=light
colorscheme off
set list
endfunction
function! Dark()
echom "set bg=dark"
set bg=dark
colorscheme darcula
"darcula fix to hide the indents:
set nolist
endfunction
function! ToggleLightDark()
if &bg ==# "light"
call Dark()
else
call Light()
endif
endfunction
" adjustments
"hi Statement ctermfg=1 guifg=#60BB60
"hi Constant ctermfg=4
" for macvim
"
" Disable scrollbar in gui
" set scrolloff=9999
" hide right scrollbar
set guioptions-=r
"
set guifont=Menlo\ Regular:h16
" =====================================
" key map
" Understand mapping modes:
" http://stackoverflow.com/questions/3776117/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping#answer-3776182
" http://stackoverflow.com/questions/22849386/difference-between-nnoremap-and-inoremap#answer-22849425
" =====================================
" change the leader key from "\" to ";" ("," is also popular)
let mapleader=";"
" Shortcut to edit THIS configuration file: (e)dit (c)onfiguration
nnoremap <silent> <leader>ec :e $MYVIMRC<CR>
" Shortcut to source (reload) THIS configuration file after editing it: (s)ource (c)onfiguraiton
nnoremap <silent> <leader>sc :source $MYVIMRC<CR>
" use ;; for escape
" http://vim.wikia.com/wiki/Avoid_the_escape_key
inoremap ;; <Esc>
" Toggle NERDTree
" Can't get <C-Space> by itself to work, so this works as Ctrl - space - space
" https://github.com/neovim/neovim/issues/3101
" http://stackoverflow.com/questions/7722177/how-do-i-map-ctrl-x-ctrl-o-to-ctrl-space-in-terminal-vim#answer-24550772
"nnoremap <C-Space> :NERDTreeToggle<CR>
"nmap <C-@> <C-Space>
nnoremap <silent> <Space> :NERDTreeToggle<CR>
" toggle tagbar
nnoremap <silent> <leader>tb :TagbarToggle<CR>
" toggle line numbers
nnoremap <silent> <leader>n :set number! number?<CR>
" toggle line wrap
nnoremap <silent> <leader>w :set wrap! wrap?<CR>
" toggle buffer (switch between current and last buffer)
nnoremap <silent> <leader>bb <C-^>
" go to next buffer
nnoremap <silent> <leader>bn :bn<CR>
nnoremap <C-l> :bn<CR>
" go to previous buffer
nnoremap <silent> <leader>bp :bp<CR>
" https://github.com/neovim/neovim/issues/2048
nnoremap <C-h> :bp<CR>
" close buffer
nnoremap <silent> <leader>bd :bd<CR>
" kill buffer
nnoremap <silent> <leader>bk :bd!<CR>
" list buffers
nnoremap <silent> <leader>bl :ls<CR>
" list and select buffer
nnoremap <silent> <leader>bg :ls<CR>:buffer<Space>
" horizontal split with new buffer
nnoremap <silent> <leader>bh :new<CR>
" vertical split with new buffer
nnoremap <silent> <leader>bv :vnew<CR>
" redraw screan and clear search highlighted items
"http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting#answer-25569434
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
" vimux
" https://raw.githubusercontent.com/benmills/vimux/master/doc/vimux.txt
nnoremap <leader>vc :VimuxPromptCommand<CR>
nnoremap <leader>vl :VimuxRunLastCommand<CR>
nnoremap <leader>vq :VimuxCloseRunner<CR>
nnoremap <leader>vx: VimuxInterruptRunner<CR>
" improved keyboard navigation
nnoremap <leader>h <C-w>h
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>l <C-w>l
" improved keyboard support for navigation (especially terminal)
" https://neovim.io/doc/user/nvim_terminal_emulator.html
tnoremap <Esc> <C-\><C-n>
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
tnoremap <A-l> <C-\><C-n><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
" Start terminal in insert mode
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
nnoremap <silent> <leader>tt :terminal<CR>
nnoremap <silent> <leader>tv :vnew<CR>:terminal<CR>
nnoremap <silent> <leader>th :new<CR>:terminal<CR>
tnoremap <C-x> <C-\><C-n><C-w>q
" ctrlp.vim
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = ''
" toggle colors to optimize based on light or dark background
nnoremap <leader>c :call ToggleLightDark()<CR>
" =====================================
" Go
" https://github.com/fatih/vim-go
" =====================================
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
" go-def is automatically by default to plain "gd" (no leader required)
au FileType go nnoremap <Leader>gd <Plug>(go-def)
au FileType go nmap <Leader>gp <Plug>(go-def-pop)
au FileType go nnoremap <Leader>gv <Plug>(go-doc-vertical)
" or open in a browser...
au FileType go nnoremap <Leader>gb <Plug>(go-doc-browser)
au FileType go nnoremap <Leader>s <Plug>(go-implements)
au FileType go nnoremap <Leader>i <Plug>(go-info)
au FileType go nnoremap <Leader>gl <Plug>(go-metalinter)
au FileType go nnoremap <Leader>gc <Plug>(go-callers)
" =====================================
" vim-airline status
" configure: https://github.com/vim-airline/vim-airline#user-content-extensible-pipeline
" =====================================
let g:airline_theme='monochrome'
" show buffers (if only one tab)
"let g:airline#extensions#tabline#enabled = 1
let s:hidden_all = 0
function! ToggleHiddenAll()
if s:hidden_all == 0
let s:hidden_all = 1
set noshowmode
set noruler
set laststatus=0
set noshowcmd
TagbarClose
NERDTreeClose
set foldcolumn=10
else
set foldcolumn=0
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
NERDTree
" NERDTree takes focus, so move focus back to the right
" (note: "l" is lowercase L (mapped to moving right)
wincmd l
TagbarOpen
endif
endfunction
nnoremap <silent> <leader>h :call ToggleHiddenAll()<CR>
" =====================================
" Custom find
" =====================================
" --column: Show column number
" --line-number: Show line number
" --no-heading: Do not show file headings in results
" --fixed-strings: Search term as a literal string
" --ignore-case: Case insensitive search
" --no-ignore: Do not respect .gitignore, etc...
" --hidden: Search hidden files and folders
" --follow: Follow symlinks
" --glob: Additional conditions for search (in this case ignore everything in the .git/ folder)
" --color: Search color options
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>), 1, <bang>0)
" =====================================
" Custom styling
" =====================================
" http://stackoverflow.com/questions/9001337/vim-split-bar-styling
set fillchars+=vert:\
" http://vim.wikia.com/wiki/Highlight_current_line
" http://stackoverflow.com/questions/8750792/vim-highlight-the-whole-current-line
" http://vimdoc.sourceforge.net/htmldoc/autocmd.html#autocmd-events
autocmd BufEnter * setlocal cursorline
autocmd WinEnter * setlocal cursorline
autocmd BufLeave * setlocal nocursorline
autocmd WinLeave * setlocal nocursorline
" tagbar autopen
"autocmd VimEnter * nested :call tagbar#autoopen(1)
"autocmd FileType * nested :call tagbar#autoopen(0)
"autocmd BufEnter * nested :call tagbar#autoopen(0)
" =====================================
" auto completion
" =====================================
set completeopt+=noinsert
set completeopt+=noselect
let g:deoplete#enable_at_startup = 1
let g:deoplete#sources#go#use_cache = 1
" =====================================
" Init
" =====================================
silent call Dark()
autocmd VimEnter * wincmd p
I recently switched over to [neovim](https://neovim.io/) (see my screenshots at the bottom).
Below is my updated [config file](https://github.com/neovim/neovim/wiki/FAQ#where-should-i-put-my-config-vimrc).
It's currently synchronized with my `.vimrc` config except for a block of [neovim-specific terminal key mappings](https://neovim.io/doc/user/nvim_terminal_emulator.html).
This is still a work in progress (everyone's own config is always a labor of love), but I'm already extremely
pleased with how well this is working for me with neovim. While terminal mode isn't enough to make me stop using
tmux, it is quite good and I like having it since it simplifies my documentation workflow for yanking terminal output to paste in a markdown buffer.
These days I primarily develop in Go. I'm super thrilled and grateful for [fatih/vim-go](https://github.com/fatih/vim-go),
as well as all the other awesome plugins contributed by an excellent community.
## Key map features
I try to avoid C-<key> combinations for the things I do frequently, mapping things that make sense to the `<leader>` key. The
[leader key](http://usevim.com/2012/07/20/vim101-leader/) provides a facility for creating customized shortcuts that can be further restricted to apply only in certain modes, such as normal, insert, visual, terminal (neovim-specific), etc.
The leader key is normally defined by the `mapleader` variable as `\`. Many people like to redefine it to `,`. I prefer
`;` since it sits right under my right pinkie.
### Leader key
`;`
In the section below, you can substitute `;` for whatever you have configured for you `<leader>` key.
### Insert mode
| Shortcut | Action |
| -------- | ------ |
| `;;` | Escape (exit insert mode)
### Normal mode
| Shortcut | Action |
| -------- | ------ |
| `;c` | Toggle light and dark themes
| `;h` | Toggle distraction free mode (hide/show both nerdtree and tagbar)
| `Space` | Toggle [NERD Tree](https://github.com/scrooloose/nerdtree), a file tree explorer.
| `;tb` | Toggle tagbar
| `C-l` | Redraw and ald also clear current highlighted search items (note: `l' is lowercase `L`, not number `1`)
| `C-p` | Open fuzzy finder (for files, buffers, etc)
| Shortcut | Action |
| -------- | ------ |
| `;ec` | Edit vim/neovim config
| `;sc` | Source (reload) the config (save it first with `:w`)
|
| `;n` | Toggle line numbers
| `;w` | Toggle wrap
|
| `bv` | Create a new (empty) buffer to the right of a vertical split
| `bh` | Create a new (empty) buffer below a horizontal split
| `;bb` | Toggle between current and last buffer
| `;bn` | Go to next buffer
| `;bp` | Go tp prev buffer
| `;bd` | Delete current buffer
| `;bk` | Kill current buffer (don't prompt to save changes)
| `;bl` | List buffers
| `;bg` | List and select buffer by #
|
| `;tt` | Open a full screen terminal
| `;tv` | Open a terminal in a new split to the right
| `;th` | Open a terminal in a new split below
|
| `;c` | Toggle between light and dark backround modes (for supported themes)
#### Go support
| Shortcut | Action |
| -------- | ------ |
| `gd` | go-def
| `;gd` | go-doc
| `;gv` | go-doc in a new vertical split to the right
| `;gb` | go-doc for current word in a new browser window/tab
| `;gs` | go-implements
| `gi` | go-info
To learn more or customize yourself, see [fatih/vim-go](https://github.com/fatih/vim-go) and read [this](http://hackersome.com/p/fatih/vim-go).
### Terminal mode
| Shortcut | Action |
| -------- | ------ |
| `C-x` | Quit terminal buffer
### Any mode
| Shortcut | Action |
| -------- | ------ |
| `A-h` | Go to buffer to the left
| `A-j` | Go to buffer below
| `A-k` | Go to buffer above
| `A-l` | go to buffer to the right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment