Skip to content

Commit

Permalink
Add neovim config
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Oct 15, 2020
1 parent a653677 commit e754947
Show file tree
Hide file tree
Showing 7 changed files with 1,196 additions and 0 deletions.
150 changes: 150 additions & 0 deletions .config/nvim/general.vim
@@ -0,0 +1,150 @@
" Basics
set nocompatible
set hidden
syntax enable

set incsearch " serach as characters are entered
set hlsearch " enable search highlight
set ignorecase " ignore search case
set smartcase " smart search

" Encoding
set encoding=utf-8

" reasonable backups
set backup
set backupdir=/tmp,~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,
set backupskip=/tmp/*
set directory=/tmp,~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,
set writebackup

" Enable mouse
set mouse=a

set cursorline " enable vertical cursor indicator
set updatetime=300 " quicker update time

set signcolumn=auto:2 " always show signcolumns

" disable auto file cd
set noautochdir

" set tab options to use 4 spaces instead of tabs
"set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
" Shift to the next round tab stop.
set shiftround
"set shiftwidth=4 noexpandtab smarttab " tab appear as 4 width with mixture of tabs and spaces
"let &softtabstop = &shiftwidth

" set nolist " Don't show invisible characters
"set showbreak=↪\ " Line breaks for wrap option
" set listchars+=tab:→\ ,nbsp:␣,trail:·,extends:⟩,precedes:⟨,eol:↵
" show invisible chars
set list
" show tab guidelines
set list listchars=tab:\│\ " note the space

set number " ruler
set relativenumber " relative number

set wildignore+=.git,.svn,CVS,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,*.pyc,tags,*.tags,node_modules
" set wildignore+=*/.git/*,*/tmp/*,*.swp

" right margin
"set textwidth=80
"let &colorcolumn='+'.join(range(1,256), ',+')
" let &colorcolumn='81,'.join(range(120,256), ',') " highlight one column after textwidth and columns 120,256
set colorcolumn=81

" whichwrap
set whichwrap+=<,>,[,] " allows cursor to move prev/next line

" complete options
set completeopt+=menuone,noinsert

" backspace
set backspace+=indent,eol,start " allow backspacing to join lines

" set autoindent smartindent " vim autoindent
filetype plugin indent on

" indent wrapped line
set breakindent

" spelling
set spell spelllang=en_us

" dict
set dictionary+=/usr/share/dict/words

" thesaurus
set thesaurus+=$HOME/.local/nvim/thesaurus/words.txt

" folding
"set foldmethod=marker
set foldenable " enable folding
set foldmethod=syntax " based on syntax
set foldlevelstart=10 " auto fold if level >= 10
set foldcolumn=0 " disable foldcolumn

" sane spliting
" set splitbelow
set splitright

" menu on command mode
set wildmenu

command! -nargs=? Explorer :CocCommand explorer
\ --toggle
\ --sources=file+
\ <args>

" configuration group
augroup configgroup
autocmd!
autocmd InsertEnter * set norelativenumber nocursorline
autocmd InsertLeave * set relativenumber cursorline
" use NERDTRee when opening a dir
" autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") |
\ exe 'Explorer' argv()[0] | wincmd p | ene | endif
" " close vim if NERDTRee is the only one open
" autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" use litecorrect with markdown
autocmd FileType markdown,mkd call litecorrect#init()
" jump to the last position
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" tab settings
autocmd Filetype vimwiki,javascript*,typescript*,css,scss,json setlocal expandtab tabstop=2 shiftwidth=2
" disable spell check in quickfix buffers
autocmd BufWinEnter * if &bt == 'quickfix' | setlocal nospell | endif
" formatters
autocmd FileType javascript,typescript*,html,markdown,json,css,scss setlocal formatprg=prettier\ --stdin\ --stdin-filepath\ \"%\"
autocmd FileType javascript*,typescript* let b:AutoPairs = AutoPairsDefine({'<>' : '</>'}) | let b:ale_fix_on_save = 1
autocmd FileType spec setlocal commentstring=#\ %s
autocmd Filetype python set foldmethod=indent foldnestmax=2
augroup END

" copy to clipboard
set clipboard+=unnamed

" diff mode settings
set diffopt+=foldcolumn:0

" netrw until netrw in stable and not buggy use Nerdtree
" let g:netrw_banner = 0
" let g:netrw_liststyle = 3
" let g:netrw_browse_split = 4
" let g:netrw_altv = 1
" let g:netrw_winsize = 25
" let g:netrw_fastbrowse = 0

" enable per project .vimrc .nvimrc .exrc
set exrc
set secure

" live substitution
set inccommand=nosplit

set noshowmode " lightline give us mode
7 changes: 7 additions & 0 deletions .config/nvim/init.vim
@@ -0,0 +1,7 @@
runtime! plugins.vim
runtime! general.vim
runtime! theme.vim
" runtime! functions.vim
runtime! misc.vim
runtime! keys.vim
runtime! statusline.vim
199 changes: 199 additions & 0 deletions .config/nvim/keys.vim
@@ -0,0 +1,199 @@
" set leader
let g:mapleader = ' '
let g:maplocalleader = ','

" toggle highlighted search
nnoremap <leader>ch :nohls<cr>
" move vertically by visual line
nnoremap <expr> j v:count ? 'j' : 'gj'
nnoremap <expr> k v:count ? 'k' : 'gk'
" tabs
nnoremap <silent> <M-S-K> :tabnext<CR>
nnoremap <silent> <M-S-J> :tabprevious<CR>
nnoremap <silent><leader>ct :tabclose<CR>
" buffers
nnoremap <silent> <Tab> :bn<CR>
nnoremap <silent> <S-Tab> :bp<CR>
nnoremap <silent> <Del> :bd<CR>
nnoremap <silent><leader>cb :Wipeout<CR>
" diff mode
" nnoremap <silent> <leader>dp V:diffput<cr>
" nnoremap <silent> <leader>dg V:diffget<cr>
" nnoremap <silent> <leader>du :wincmd w<cr>:normal u<cr>:wincmd w<cr>
" save session
nnoremap <leader>sl<cr> :SLoad<cr>
nnoremap <leader>sl<space> :SLoad<space>
nnoremap <leader>ss :SSave<cr>
nnoremap <leader>R :source $MYVIMRC<CR>
" unimpaired preview window
nnoremap ]op :pclose<cr>
nnoremap [op :ppop<cr>
" increase/decrease foldcolumn
nnoremap Zr :call IncFoldCol()<CR>
nnoremap Zm :call DecFoldCol()<CR>
" toggle loc/quick list
nnoremap <silent> <F3> :call LoclistToggle()<cr>
nnoremap <silent> <F4> :call QuickfixToggle()<cr>
" remap \ to ripgrep
" nnoremap \ :Rg<space>

" netrw
" nnoremap <leader>f :Vexplore<CR>

" copy to clipboard
vmap <C-c> "+y
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <C-r><C-o>+
" vim-fugitive
nnoremap <leader>gi :G<CR>
nnoremap <leader>gc :Gcommit<CR>
nnoremap <leader>gd :Gdiff<CR>
nnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gh :Gbrowse<CR>
" vim-gitgutter
nmap ]g <Plug>(GitGutterNextHunk)
nmap [g <Plug>(GitGutterPrevHunk)
nmap <leader>gp <Plug>(GitGutterPreviewHunk)
nmap <leader>gs <Plug>(GitGutterStageHunk)
nmap <leader>gu <Plug>(GitGutterUndoHunk)
" git-messenger
nmap <leader>gm <Plug>(git-messenger)
" vim-ale
nnoremap <leader>f :ALEFix<cr>
nnoremap <leader>e :ALEDetail<cr>
nnoremap ]d :ALENextWrap<CR> " move to the next ALE warning / error
nnoremap [d :ALEPreviousWrap<CR> " move to the previous ALE warning / error
" coc.nvim
" Make autocompletion behave sanely
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ CheckBackSpace() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Remap keys for gotos
nmap <silent><leader>d <Plug>(coc-definition)
nmap <silent><leader>td <Plug>(coc-type-definition)
nmap <silent><leader>D <Plug>(coc-declaration)
nmap <silent><leader>i <Plug>(coc-implementation)
nmap <silent><leader>r <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>
nnoremap <silent><leader>h :call ShowDocumentation()<CR>
" Remap for rename current word
nmap <silent><leader>n <Plug>(coc-rename)
xmap <silent><leader>A <Plug>(coc-codeaction-selected)
nmap <silent><leader>A <Plug>(coc-codeaction-selected)
nmap <silent><leader>a <Plug>(coc-codeaction)
nmap <silent><leader>l <Plug>(coc-codelens-action)
nmap <silent><leader>q <Plug>(coc-fix-current)
nmap <silent><leader>F <Plug>(coc-format-selected)
xmap <silent><leader>F <Plug>(coc-format-selected)
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Show all diagnostics
" nnoremap <silent> <localleader>d :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <leader>ce :<C-u>CocFzfListExtensions<cr>
" Show commands
nnoremap <silent> <leader>cc :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <leader>/s :<C-u>CocFzfListOutline<cr>
" Search workspace symbols
nnoremap <silent> <leader>/S :<C-u>CocFzfListSymbols<cr>
" Do default action for next item.
nnoremap <silent> <leader>cj :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <leader>ck :<C-u>CocPrev<CR>
" Resume latest coc list
" nnoremap <silent> <leader>p :<C-u>CocListResume<CR>
nnoremap <silent><localleader>f :Explorer<CR>
" vim kitty nav
if $TERM =~# '.*kitty.*'
nnoremap <silent> <M-h> :KittyNavigateLeft<cr>
nnoremap <silent> <M-j> :KittyNavigateDown<cr>
nnoremap <silent> <M-k> :KittyNavigateUp<cr>
nnoremap <silent> <M-l> :KittyNavigateRight<cr>
else
" vim tmux nav
tnoremap <silent> <M-h> :TmuxNavigateLeft<cr>
tnoremap <silent> <M-j> :TmuxNavigateDown<cr>
tnoremap <silent> <M-k> :TmuxNavigateUp<cr>
tnoremap <silent> <M-l> :TmuxNavigateRight<cr>
nnoremap <silent> <M-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <M-j> :TmuxNavigateDown<cr>
nnoremap <silent> <M-k> :TmuxNavigateUp<cr>
nnoremap <silent> <M-l> :TmuxNavigateRight<cr>
nnoremap <silent> <M-\> :TmuxNavigatePrevious<cr>
endif

" undotree
nnoremap <F5> :UndotreeToggle<CR>
nnoremap <leader>u :UndotreeToggle<CR>
" vim-test
nnoremap <leader>Tn :TestNearest<CR>
nnoremap <leader>Tf :TestFile<CR>
nnoremap <leader>Ts :TestSuite<CR>
nnoremap <leader>Tl :TestLast<CR>
nnoremap <leader>Tv :TestVisit<CR>
" vim-easymotion
map <leader>// <Plug>(easymotion-prefix)
" vim-easy-align
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" vim-translate
nmap <silent> <Leader>tw <Plug>TranslateW
vmap <silent> <Leader>tw <Plug>TranslateWV
" Vista.vim better tagbar.vim replacement
nmap <silent><leader>o :Vista!!<CR>
nmap <F8> :Vista!!<CR>
" \ if exists('.git') |
" \ call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(), <bang>0) |
" \ else |
" \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0) |
" \ endif
" fzf
nnoremap <silent><leader>/f :Files<CR>
nnoremap <silent><expr> <C-p> exists('.git') ? ':GFiles<CR>' : ':Files<CR>'
nnoremap <leader><Space> :Files ~<CR>
nnoremap <localleader>m :FZFMru<CR>
nnoremap <leader>; :Buffers<CR>
nnoremap <localleader>co :Commits<CR>
nnoremap <localleader>cb :BCommits<CR>
nnoremap <localleader>t :Tags<CR>
nnoremap \ :GGrep<space>
nnoremap \| :Rg<space>
nnoremap <leader>vm :Maps<CR>
nnoremap <leader>vh :Helptags<CR>
nnoremap <leader>vc :Commands<CR>
nmap <leader><tab> <plug>(fzf-maps-n)
xmap <leader><tab> <plug>(fzf-maps-x)
omap <leader><tab> <plug>(fzf-maps-o)
" vim-dispatch
nnoremap <localleader>m<CR> :Make<CR>
nnoremap <localleader>m<Space> :Make<Space>

0 comments on commit e754947

Please sign in to comment.