Created
August 6, 2019 06:24
-
-
Save edhana/fd089f2b730e7a3dc5d70e69fa43c127 to your computer and use it in GitHub Desktop.
My personal neovim config
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
call plug#begin('~/.config/nvim/bundle') | |
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } | |
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } | |
Plug 'jodosha/vim-godebug' " Debugger integration via delve | |
Plug 'godoctor/godoctor.vim' " Some refactoring tools | |
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } | |
Plug 'zchee/deoplete-go', {'build': {'unix': 'make'}} | |
Plug 'jodosha/vim-godebug' " Debugger integration via delve | |
Plug 'mattn/emmet-vim' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'jlanzarotta/bufexplorer' | |
Plug 'yuttie/comfortable-motion.vim' | |
Plug 'jceb/vim-orgmode' | |
Plug 'mileszs/ack.vim' | |
Plug 'ctrlpvim/ctrlp.vim' | |
" Call :PlugInstall to install new plugins | |
call plug#end() | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Basics | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
filetype plugin indent on | |
syntax on | |
set number | |
set clipboard=unnamed | |
" set relativenumber | |
if !&scrolloff | |
set scrolloff=3 " Show next 3 lines while scrolling. | |
endif | |
if !&sidescrolloff | |
set sidescrolloff=5 " Show next 5 columns while side-scrolling. | |
endif | |
set display+=lastline | |
set nostartofline " Do not jump to first character with page commands. | |
set noerrorbells " No beeps | |
set backspace=indent,eol,start " Makes backspace key more powerful | |
filetype plugin on | |
filetype indent on | |
set autowrite " Automatically save before :next, :make etc. | |
set autoread | |
" With a map leader it's possible to do extra key combinations | |
" like <leader>w saves the current file | |
" noremap <Space> <Nop> | |
let mapleader = "," | |
nmap <Space> , | |
" Fast saving | |
nmap <leader>w :w!<cr> | |
" nmap <M-s> :w!<cr> | |
" vmap <M-s> :w!<cr> | |
" :W sudo saves the file <Nvim - command already exist> | |
" (useful for handling the permission-denied error) | |
" command W w !sudo tee % > /dev/null | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => VIM user interface | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Set 7 lines to the cursor - when moving vertically using j/k | |
set so=7 | |
" Turn on the Wild menu | |
set wildmenu | |
" Ignore compiled files | |
set wildignore=*.o,*~,*.pyc | |
if has("win16") || has("win32") | |
set wildignore+=.git\*,.hg\*,.svn\* | |
else | |
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store | |
endif | |
"Always show current position | |
set ruler | |
" Height of the command bar | |
set cmdheight=2 | |
" A buffer becomes hidden when it is abandoned | |
set hid | |
" Ignore case when searching | |
set ignorecase | |
" When searching try to be smart about cases | |
set smartcase | |
" Highlight search results | |
set hlsearch | |
" Makes search act like search in modern browsers | |
set incsearch | |
" Don't redraw while executing macros (good performance config) | |
set lazyredraw | |
" For regular expressions turn magic on | |
set magic | |
" Show matching brackets when text indicator is over them | |
set showmatch | |
" How many tenths of a second to blink when matching brackets | |
set mat=2 | |
" Add a bit extra margin to the left | |
set foldcolumn=1 | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Colors and Fonts | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
syntax enable | |
" Set extra options when running in GUI mode | |
if has("gui_running") | |
set guioptions-=T | |
set guioptions-=e | |
set t_Co=256 | |
set guitablabel=%M\ %t | |
endif | |
" Set utf8 as standard encoding and en_US as the standard language | |
set encoding=utf8 | |
" Use Unix as the stadard file type | |
set ffs=unix,dos,mac | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Files, backups and undo | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Turn backup off, since most stuff is in SVN, git et.c anyway... | |
set nobackup | |
set nowb | |
set noswapfile | |
""nd indent related | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Use spaces instead of tabs | |
set expandtab | |
" Be smart when using tabs ;) | |
set smarttab | |
" 1 tab == 4 spaces | |
set shiftwidth=4 | |
set tabstop=4 | |
" Linebreak on 500 characters | |
set lbr | |
set tw=500 | |
set ai "Auto indent | |
set si "Smart indent | |
set wrap "Wrap lines | |
"""""""""""""""""""""""""""""" | |
" => Visual mode related | |
"""""""""""""""""""""""""""""" | |
" Visual mode pressing * or # searches for the current selection | |
" Super useful! From an idea by Michael Naumann | |
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR> | |
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Moving around, tabs, windows and buffers | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Disable highlight when <leader><cr> is pressed | |
map <silent> <leader><cr> :noh<cr> | |
" Smart way to move between windows | |
map <C-j> <C-W>j | |
map <C-k> <C-W>k | |
map <C-h> <C-W>h | |
map <C-l> <C-W>l | |
map <leader>bn <C-W>l | |
map <leader>bp <C-W>h | |
map <leader>wc <C-W>q | |
map <leader>bj <C-W>j | |
map <leader>bk <C-W>k | |
map <leader>bh <C-W>h | |
map <leader>bl <C-W>l | |
" Close the current buffer | |
map <leader>bd :Bclose<cr>:tabclose<cr>gT | |
" Close all the buffers | |
map <leader>ba :bufdo bd<cr> | |
map <leader>l :bnext<cr> | |
map <leader>h :bprevious<cr> | |
" Useful mappings for managing tabs | |
map <leader>tn :tabnew<cr> | |
map <leader>to :tabonly<cr> | |
map <leader>tc :tabclose<cr> | |
map <leader>tm :tabmove | |
map <leader>t<leader> :tabnext | |
" Let 'tl' toggle between this and the last accessed tab | |
let g:lasttab = 1 | |
nmap <Leader>tl :exe "tabn ".g:lasttab<CR> | |
au TabLeave * let g:lasttab = tabpagenr() | |
" Opens a new tab with the current buffer's path | |
" Super useful when editing files in the same directory | |
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/ | |
" Switch CWD to the directory of the open buffer | |
map <leader>cd :cd %:p:h<cr>:pwd<cr> | |
" Specify the behavior when switching between buffers | |
try | |
set switchbuf=useopen,usetab,newtab | |
set stal=2 | |
catch | |
endtry | |
" Return to last edit position when opening files (You want this!) | |
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif | |
"""""""""""""""""""""""""""""" | |
" => Status line | |
"""""""""""""""""""""""""""""" | |
" Always show the status line | |
set laststatus=2 | |
" Format the status line | |
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Editing mappings | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Remap VIM 0 to first non-blank character | |
map 0 ^ | |
" Move a line of text using ALT+[jk] or Command+[jk] on mac | |
nmap <M-j> mz:m+<cr>`z | |
nmap <M-k> mz:m-2<cr>`z | |
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z | |
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z | |
if has("mac") || has("macunix") | |
nmap <D-j> <M-j> | |
nmap <D-k> <M-k> | |
vmap <D-j> <M-j> | |
vmap <D-k> <M-k> | |
endif | |
" Delete trailing white space on save, useful for some filetypes ;) | |
fun! CleanExtraSpaces() | |
let save_cursor = getpos(".") | |
let old_query = getreg('/') | |
silent! %s/\s\+$//e | |
call setpos('.', save_cursor) | |
call setreg('/', old_query) | |
endfun | |
if has("autocmd") | |
autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces() | |
endif | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Misc | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Remove the Windows ^M - when the encodings gets messed up | |
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm | |
" Quickly open a buffer for scribble | |
map <leader>q :e ~/buffer<cr> | |
" Quickly open a markdown buffer for scribble | |
map <leader>x :e ~/buffer.md<cr> | |
" Toggle paste mode on and off | |
map <leader>pp :setlocal paste!<cr> | |
set clipboard=unnamed | |
map <Space><Tab> :e#<cr> | |
"map + :.w !pbcopy<CR><CR> | |
"map <F3> :r !pbpaste<CR> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Plug in specific stuff | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Use deoplete. | |
let g:deoplete#enable_at_startup = 1 | |
" => Nerd Tree | |
let g:NERDTreeWinPos = "left" | |
let NERDTreeShowHidden=0 | |
let NERDTreeIgnore = ['\.pyc$', '__pycache__'] | |
let g:NERDTreeWinSize=35 | |
map <leader>nn :NERDTreeToggle<cr> | |
map <leader>ft :NERDTreeToggle<cr> | |
map <leader>nb :NERDTreeFromBookmark<Space> | |
map <leader>nf :NERDTreeFind<cr> | |
" => bufExplorer plugin | |
let g:bufExplorerDefaultHelp=0 | |
let g:bufExplorerShowRelativePath=1 | |
let g:bufExplorerFindActive=1 | |
let g:bufExplorerSortBy='name' | |
map <leader>o :BufExplorer<cr> | |
" Ag vim - silver searcher with ack.vim | |
let g:ackprg = 'ag --nogroup --nocolor --column' | |
map <leader>g :Ack | |
"""""""""""""""""""""""""""""" | |
" => CTRL-P | |
"""""""""""""""""""""""""""""" | |
let g:ctrlp_working_path_mode = 0 | |
let g:ctrlp_map = '<c-p>' | |
" map <leader>j :CtrlP<cr> | |
" map <c-p> :CtrlPBuffer<cr> | |
map <leader>bl :CtrlPBuffer<cr> | |
map <leader>zz :CtrlPMRU<cr> | |
let g:ctrlp_max_height = 20 | |
let g:ctrlp_custom_ignore = 'node_modules\|^\.DS_Store\|^\.git\|^\.coffee|^\vendor' | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Helper functions | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Returns true if paste mode is enabled | |
function! HasPaste() | |
if &paste | |
return 'PASTE MODE ' | |
endif | |
return '' | |
endfunction | |
" Don't close window, when deleting a buffer | |
command! Bclose call <SID>BufcloseCloseIt() | |
function! <SID>BufcloseCloseIt() | |
let l:currentBufNum = bufnr("%") | |
let l:alternateBufNum = bufnr("#") | |
if buflisted(l:alternateBufNum) | |
buffer # | |
else | |
bnext | |
endif | |
if bufnr("%") == l:currentBufNum | |
new | |
endif | |
if buflisted(l:currentBufNum) | |
execute("bdelete! ".l:currentBufNum) | |
endif | |
endfunction | |
function! CmdLine(str) | |
call feedkeys(":" . a:str) | |
endfunction | |
function! VisualSelection(direction, extra_filter) range | |
let l:saved_reg = @" | |
execute "normal! vgvy" | |
let l:pattern = escape(@", "\\/.*'$^~[]") | |
let l:pattern = substitute(l:pattern, "\n$", "", "") | |
if a:direction == 'gv' | |
call CmdLine("Ack '" . l:pattern . "' " ) | |
elseif a:direction == 'replace' | |
call CmdLine("%s" . '/'. l:pattern . '/') | |
endif | |
let @/ = l:pattern | |
let @" = l:saved_reg | |
endfunction | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment