Skip to content

Instantly share code, notes, and snippets.

@adham90
Last active July 8, 2021 02:48
Show Gist options
  • Save adham90/c00952e743572f14a9df32793a3b58fb to your computer and use it in GitHub Desktop.
Save adham90/c00952e743572f14a9df32793a3b58fb to your computer and use it in GitHub Desktop.
My vim and nvim(neovim) configurations
iabbrev myid adham90
"============== Custom Commands ===============
command! -nargs=0 Sinit :call <SID>Sinit('%:p:h')
command! -nargs=? W :w <args>
augroup AutoMkdir
autocmd!
autocmd BufWritePre * :call EnsureDirExists()
augroup END
command! DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis
command! JShint 80vnew +setlocal\ buftype=nofile\ bufhidden=hide\ noswapfile | r !jshint # --show-non-errors
command! CR 80vnew +setlocal\ buftype=nofile\ bufhidden=hide\ noswapfile | r !php-cs-fixer fix # --diff --dry-run -vvv
fun! Format_WhiteSpace_RemoveTrailing()
:%s/\v\s*$//g
endfun
fun! Format_Inflection_ToCamelCase()
:s/\v([a-z])_([a-z])/\1\u\2/g
endfun
fun! Format_Inflection_ToUnderscored()
:s/\v([a-z])([A-Z])/\L\1_\2/g
endfun
fun! CheckTabs()
if search("\t") != 0
echohl ErrorMsg | ec " !WARNING! "
\ | ec "There are tabs in the file, do you want to convert them to spaces? [Y/n]" | echohl None
let choice = nr2char(getchar())
if choice == 'y' || choice == "\<CR>"
retab 2
endif
else
return
endif
endfun
function! EnsureDirExists ()
let required_dir = expand("%:h")
if !isdirectory(required_dir)
call mkdir(required_dir, 'p')
endif
endfunction
function! GetCWD()
return expand(":pwd")
endfunction
function! IsHelp()
return &buftype=='help'?' (help) ':''
endfunction
function! GetName()
return expand("%:t")==''?'<none>':expand("%:t")
endfunction
command! -nargs=* -complete=file -bang Rename :call Rename("<args>", "<bang>")
function! Rename(name, bang)
let l:curfile = expand("%:p")
let l:curfilepath = expand("%:p:h")
let l:newname = l:curfilepath . "/" . a:name
let v:errmsg = ""
silent! exe "saveas" . a:bang . " " . l:newname
if v:errmsg =~# '^$\|^E329'
if expand("%:p") !=# l:curfile && filewritable(expand("%:p"))
silent exe "bwipe! " . l:curfile
if delete(l:curfile)
echoerr "Could not delete " . l:curfile
endif
endif
else
echoerr v:errmsg
endif
endfunction
set nocompatible
filetype on
filetype indent on
"===== Load config files =====
source ~/.config/nvim/startup/plugins.vim
source ~/.config/nvim/startup/abbreviations.vim
source ~/.config/nvim/startup/commands.vim
source ~/.config/nvim/startup/functions.vim
source ~/.config/nvim/startup/settings.vim
source ~/.config/nvim/startup/mappings.vim
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
noremap <F3> :Autoformat<CR>
map <leader>d :bd<CR> " \d delete buffer
map <C-b> :Buffers<CR>
map <leader>f :Ag
map \ :NERDTreeToggle<cr>
map <leader>t :Term<CR>
nmap <Leader>n :lnext<CR> " next error/warning
nmap <Leader>p :lprev<CR> " previous error/warning
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
nnoremap <C-H> <C-w>h
nnoremap <C-J> <C-w>j
nnoremap <C-L> <C-w>l
nnoremap <C-K> <C-w>k
"======== Insert mode mappings =========
imap <C-l> <space>=><space>
imap <C-s> <Esc>:w<CR>a
imap <leader>' ''<ESC>i
imap <leader>" ""<ESC>i
imap <leader>( ()<ESC>i
imap <leader>[ []<ESC>i
"======== Normal mode mappings ==========
" search rails app
nmap <leader>fv :FZF app/views<cr>
nmap <leader>fc :FZF app/controllers<cr>
nmap <leader>fm :FZF app/models<cr>
nmap <Leader>ga :A<CR>
nmap <Leader>gm :Emodel<CR>
nmap <Leader>gc :Econtroller<CR>
nmap <Leader>gv :Eview<CR>
nmap <leader>gr :e config/routes.rb<CR>
nmap <C-n> :noh<CR>
nmap <C-s> :w<CR>
nmap <leader>ev :vs $MYVIMRC<CR>
nmap <leader>gs :Gstatus<CR><C-W>15+
nmap <leader>m :VimFilerExplorer<CR>
nmap <leader>k :Ack
nmap <leader>d :bd<CR>
nmap <leader>w :w<CR>
nmap <leader>ls :ls<CR>:b
nmap <leader><leader> <c-^>
nmap <leader>re :call Rename()<cr>
" rspec test
nmap <Leader>s :A<CR>
nmap <Leader>l :call RunLastSpec()<CR>
nmap <Leader>rs :call RunAllSpecs()<CR>
"========= Visual mode mappings ==========
vmap < <gv
vmap > >gv
"Execute dot in the selection
vmap . :norm.<CR>
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
"autoformat code
Plug 'Chiel92/vim-autoformat'
"for editorconfig file
Plug 'editorconfig/editorconfig-vim'
"The fancy start screen for Vim.
Plug 'mhinz/vim-startify'
"===== search ======
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
Plug 'junegunn/fzf.vim'
Plug 'craigemery/vim-autotag'
"===== Git =========
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter' "shows a git diff in the gutter
" Plug 'mattn/Gist-vim' "vimscript for creating gists
Plug 'gregsexton/gitv'
" Plug 'tpope/vim-git'
"===== Ruby ========
Plug 'tpope/vim-rails'
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-rake'
Plug 'tpope/vim-endwise'
Plug 'bruno-/vim-ruby-fold'
Plug 't9md/vim-ruby-xmpfilter'
Plug 'tpope/vim-bundler'
Plug 'sunaku/vim-ruby-minitest'
Plug 'nelstrom/vim-textobj-rubyblock'
Plug 'slim-template/slim-rails'
Plug 'kana/vim-vspec'
Plug 'thoughtbot/vim-rspec'
Plug 'rhysd/vim-vspec-matchers'
Plug 'kchmck/vim-coffee-script'
"Multiple selections for Vim
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-markdown'
"improves HTML & CSS workflow
Plug 'mattn/emmet-vim'
"Vim runtime files for Haml, Sass, and SCSS
Plug 'tpope/vim-haml'
"Syntax highlighting for VIM
" Plug 'slim-template/vim-slim'
Plug 'sheerun/vim-polyglot'
"Is all about surroundings: parentheses, brackets, quotes, XML tags, and more.
Plug 'tpope/vim-surround'
"Vim script for text filtering and alignment
Plug 'godlygeek/tabular'
"Send command from vim to a running tmux session
Plug 'jgdavey/tslime.vim'
"plugin for commenting
Plug 'tpope/vim-commentary'
"Fold markdown documents by section.
" Plug 'nelstrom/vim-markdown-folding'
"extended % matching for HTML, LaTeX, and many other languages
"plugin to display the indention levels with thin vertical lines
Plug 'Yggdroot/indentLine'
"Create your own text objects
Plug 'kana/vim-textobj-user'
"A light and configurable statusline/tabline for Vim
Plug 'itchyny/lightline.vim'
"A vim plugin that simplifies the transition between multiline and single-line code
Plug 'AndrewRadev/splitjoin.vim'
"A simple, easy-to-use Vim alignment plugin.
Plug 'junegunn/vim-easy-align'
"Plug to move lines and selections up and down
Plug 'matze/vim-move'
Plug 'chriskempson/vim-tomorrow-theme'
Plug 'NLKNguyen/papercolor-theme'
Plug 'joshdick/onedark.vim'
Plug 'morhetz/gruvbox'
"======== AutoComplete =======
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install -g tern' }
Plug 'marijnh/tern_for_vim'
Plug 'mdempsky/gocode', { 'rtp': 'nvim', 'do': '~/.config/nvim/plugged/gocode/nvim/symlink.sh' }
Plug 'zchee/deoplete-go', { 'do': 'make'}
Plug 'ervandew/supertab'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
"linting and make framework for Neovim/Vim
" Plug 'benekastah/neomake'
Plug 'w0rp/ale'
" Insert or delete brackets, parens, quotes in pair.
Plug 'jiangmiao/auto-pairs'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'jeetsukumaran/vim-buffergator'
Plug 'mklabs/split-term.vim'
" j2 syntax
Plug 'glench/vim-jinja2-syntax'
" jsx
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
call plug#end()
let mapleader = ","
syntax on " enable syntax highlighting
set shell=fish
"================================
" Use deoplete.
let g:deoplete#enable_at_startup = 1
let g:deoplete#enable_smart_case = 1
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" ReactJS
let g:jsx_ext_required = 0
" GoLang
let g:go_fmt_command = "goimports"
" deoplete-go
let g:deoplete#enable_at_startup = 1
set completeopt+=noinsert
set completeopt+=noselect
set completeopt-=preview " disable preview window at the bottom of the screen
inoremap <silent><expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" open vimfiler by default
let g:vimfiler_as_default_explorer = 1
let g:pymode_rope_lookup_project = 0
let g:markdown_fenced_languages = ['coffee', 'css', 'erb=eruby', 'javascript', 'js=javascript', 'json=javascript', 'ruby', 'sass', 'xml', 'html'] " Specific configurations
let g:move_key_modifier = 'C'
let g:gist_clip_command = 'xclip -selection clipboard'
let g:gist_use_password_in_gitconfig = 1
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
"========================================
" General
"========================================
let g:python3_host_prog = "/usr/bin/python3"
let g:python_host_prog = "/usr/bin/python"
autocmd Filetype gitcommit setlocal spell textwidth=72
" tell it to use an undo file
set undofile
" set a directory to store the undo history
set undodir=~/.vimundo/
set clipboard+=unnamedplus
set cursorline
set encoding=utf-8
set fileencoding=utf-8
set gdefault
set list
" set listchars=tab:▸\ ,eol:¬,nbsp:⋅,trail:•
set listchars=tab:\│\ ,trail:-,extends:>,precedes:<,nbsp:+
set noswapfile
set smartindent
set relativenumber
set ruler " show the cursor position all the time
set backspace=indent,eol,start " enable <BS> for everything
set colorcolumn=80 " visual indicator of column
set number " Show line numbers
set hidden " hide when switching buffers, don't unload
set laststatus=2 " always show status line
set lazyredraw " don't update screen when executing macros
set mouse=a " enable mouse in all modes
set nowrap " disable word wrap
set showbreak="+++ " " String to show with wrap lines
set showcmd " show command on last line of screen
set showmatch " show bracket matches
set textwidth=0 " don't break lines after some maximum width
set ttyfast " increase chars sent to screen for redrawing
set title " use filename in window title
set wildmenu " enhanced cmd line completion
set wildchar=<TAB> " key for line completion
set noerrorbells " no error sound
set splitright " Split new buffer at right
set ts=2 sts=2 sw=2 expandtab
"========================================
"========================================
" Appearance
"========================================
set t_Co=256
set winheight=999
set winheight=5
set winminheight=5
set winwidth=84
syntax enable
set background=dark
" colorscheme Tomorrow-Night-Eighties
colorscheme gruvbox
let g:gruvbox_contrast='medium'
" let g:airline_theme='Tomorrow-Night'
"========================================
"========================================
" Folding
"========================================
set foldlevel=99
set foldignore= " don't ignore anything when folding
set foldlevelstart=99 " no folds closed on open
set foldmethod=marker " collapse code using markers
set foldnestmax=1 " limit max folds for indent and syntax methods
"========================================
"========================================
" Searches
"========================================
set hlsearch " highlight search results
set incsearch " search whilst typing
set ignorecase " case insensitive searching
set smartcase " override ignorecase if upper case typed
set more " Stop in list
"========================================
" auto save
let g:auto_save = 0
let g:auto_save_in_insert_mode = 0
"========================================
" StatusLine
"========================================
set statusline=%1*[%{GetName()}]\
set statusline+=%<pwd:%{getcwd()}\
set statusline+=%2*%{&modified?'\[+]':''}%*
set statusline+=%{IsHelp()}
set statusline+=%{&readonly?'\ (ro)\ ':''}
set statusline+=[
set statusline+=%{strlen(&fenc)?&fenc:'none'}\|
set statusline+=%{&ff}\|
set statusline+=%{strlen(&ft)?&ft:'<none>'}
set statusline+=]\
set statusline+=%=
set statusline+=c%c
set statusline+=,l%l
set statusline+=/%L\
hi User1 ctermbg=white ctermfg=black guibg=#89A1A1 guifg=#002B36
hi User2 ctermbg=red ctermfg=white guibg=#aa0000 guifg=#89a1a1
"========================================
"========================================
" Autocommands
"========================================
autocmd BufWritePre *.rb :%s/\s\+$//e " auto remove trailing whitespace in ruby files
au BufRead,BufNewFile *.ru set filetype=ruby
au BufRead,BufNewFile [vV]agrantfile set filetype=ruby
au Bufread,BufNewFile *.md set filetype=markdown textwidth=79
au Bufread,BufNewFile *.markdown set textwidth=79
au Bufread,BufNewFile *.feature set filetype=cucumber " .feature files are Cucumber.
"========================================
"========================================
" BACKUP / TMP FILES
"========================================
if isdirectory($HOME . '/.vim/backup') == 0
:silent !mkdir -p ~/.vim/backup >/dev/null 2>&1
endif
set backupdir-=.
set backupdir+=.
set backupdir-=~/
set backupdir^=~/.vim/backup/
set backupdir^=./.vim-backup/
set backup
if isdirectory($HOME . '/.vim/swap') == 0
:silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
endif
set directory=./.vim-swap//
set directory+=~/.vim/swap//
set directory+=~/tmp//
set directory+=.
"========================================
"========================================
" Make sure Vim returns to the same line when you reopen a file.
"========================================
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
"========================================
let g:rspec_command = 'call Send_to_Tmux("rspec {spec}\n")'
" fzf
nnoremap <silent><C-p> :Files<cr>
" This is the default extra key bindings
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" Default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
let $FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -g ""'
let g:ackprg = 'ag --nobreak --nonumbers --noheading . | fzf'
let g:vim_tags_auto_generate = 1
"Split-term
let g:split_term_vertical = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment