Last active
September 3, 2020 09:31
-
-
Save medihack/1a2aeed5d47595b1a1a7ecdad57dd39b to your computer and use it in GitHub Desktop.
for Vim version >= 8.x
This file contains 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
set nocompatible " be iMproved, required | |
" My ultimate .vimrc for Vim 8.x | |
" Ideally python (works with python3 command) and yarn is preinstalled. | |
" I tried it with npm but it fails somehow. | |
" vim-plug and all plugins are automatically installed on first run of vim | |
" if not present (by code see below). | |
" Make sure ag (or ack-grep) and yarn is installed globally. All other stuff | |
" is installed automagically by this vim configuration :-) | |
" Install flake8 for Python syntax checking: | |
" pip install flake8 | |
" Install eslint for Javascript syntax checking, ideally insde the project | |
" (and not globally) and also add a .eslintc config to the project. | |
" npm install eslint --save-dev (and maybe also eslint-plugin-react) | |
" For type checking with Flow make sure the development dependency is | |
" added to package.json (yarn add --dev flow-bin), the project is initialized | |
" (yarn run flow init) and the Flow background process is started | |
" (yarn run flow status). | |
" Automatically install vim-plug if not already installed and install plugins | |
" see https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation | |
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 | |
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | |
endif | |
" Specify a directory for plugins | |
" - Avoid using standard Vim directory names like 'plugin' | |
" - Make sure you use single quotes | |
call plug#begin('~/.vim/plugged') | |
" Dependecies | |
Plug 'MarcWeber/vim-addon-mw-utils' " for vim-snipmate | |
Plug 'tomtom/tlib_vim' " for vim-snipmate | |
Plug 'mattn/webapi-vim' " for gist-vim | |
Plug 'JulesWang/css.vim' " for vim-less | |
" Themes | |
Plug 'flazz/vim-colorschemes' | |
" Languages | |
Plug 'tpope/vim-markdown' | |
Plug 'python-mode/python-mode' | |
Plug 'vim-ruby/vim-ruby' | |
Plug 'tpope/vim-rails' | |
Plug 'skwp/vim-rspec' | |
Plug 'tpope/vim-git' | |
Plug 'briancollins/vim-jst' | |
Plug 'slava/vim-spacebars' | |
Plug 'mmalecki/vim-node.js' | |
Plug 'vim-scripts/csv.vim' | |
Plug 'othree/html5.vim' | |
Plug 'genoma/vim-less' | |
Plug 'tweekmonster/django-plus.vim' | |
Plug 'pangloss/vim-javascript' | |
Plug 'mxw/vim-jsx' | |
Plug 'posva/vim-vue' | |
Plug 'mustache/vim-mustache-handlebars' | |
Plug 'elixir-lang/vim-elixir' | |
Plug 'posva/vim-vue' | |
Plug 'medihack/sh.vim' | |
" General Tools | |
Plug 'w0rp/ale' | |
Plug 'tmux-plugins/vim-tmux-focus-events' | |
Plug 'ctrlpvim/ctrlp.vim' | |
Plug 'scrooloose/nerdtree' | |
Plug 'EvanDotPro/nerdtree-chmod' | |
Plug 'mileszs/ack.vim' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'jeetsukumaran/vim-buffergator' | |
Plug 'mkitt/tabline.vim' | |
Plug 'tpope/vim-endwise' | |
Plug 'tpope/vim-fugitive' | |
Plug 'mattn/gist-vim' | |
Plug 'mbbill/undotree' | |
Plug 'scrooloose/nerdcommenter' | |
Plug 'vim-scripts/Rename2' | |
Plug 'garbas/vim-snipmate' | |
Plug 'honza/vim-snippets' | |
Plug 'ervandew/supertab' | |
Plug 'tpope/vim-surround' | |
Plug 'majutsushi/tagbar' | |
Plug 'tpope/vim-unimpaired' | |
Plug 'vim-scripts/vimwiki' | |
Plug 'regedarek/ZoomWin' | |
Plug 'tmhedberg/matchit' | |
Plug 'michaeljsmith/vim-indent-object' | |
Plug 'ap/vim-css-color' | |
Plug 'chrisbra/NrrwRgn' | |
Plug 'skalnik/vim-vroom' | |
Plug 'vim-scripts/mru.vim' | |
Plug 'bitc/vim-bad-whitespace' | |
Plug 'ivanov/vim-ipython' | |
Plug 'prettier/vim-prettier', { 'do': 'yarn install' } | |
Plug 'mattn/emmet-vim' | |
" Initialize plugin system | |
call plug#end() | |
" | |
" Normal Vim config: | |
" | |
set number | |
set ruler | |
syntax on | |
" Create a temporary directory for swap files if it doesn't exist | |
if !isdirectory($HOME . "/.vim/tmp") | |
call mkdir($HOME . "/.vim/tmp", "p") | |
endif | |
" Directories for swp files | |
set backupdir=~/.vim/tmp | |
set directory=~/.vim/tmp | |
" Default color scheme | |
if has('gui_running') | |
set background=dark | |
colorscheme solarized | |
else | |
set t_Co=256 | |
" Needs to be set when using Putty without a Solarized color scheme itself | |
" https://github.com/altercation/solarized/tree/master/putty-colors-solarized | |
let g:solarized_termcolors=256 | |
set background=dark | |
colorscheme solarized | |
" alterlative good looking theme | |
"colorscheme jellybeans | |
endif | |
" enable horizontal scrollbar | |
set guioptions+=b | |
" Set encoding | |
set encoding=utf-8 | |
" Whitespace stuff | |
set nowrap | |
set tabstop=2 | |
set shiftwidth=2 | |
set softtabstop=2 | |
set expandtab | |
set listchars=tab:>-,trail:. | |
" Searching | |
set hlsearch | |
set incsearch | |
set ignorecase | |
set smartcase | |
" Tab completion | |
set wildmode=list:longest,list:full | |
" Ignore files on tab completion, ctrl-p and ack.vim | |
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/* | |
set wildignore+=.meteor | |
set wildignore+=node_modules | |
" Status bar | |
set laststatus=2 | |
" Without setting this, ZoomWin restores windows in a way that causes | |
" equalalways behavior to be triggered the next time CommandT is used. | |
" This is likely a bludgeon to solve some other issue, but it works | |
set noequalalways | |
" Make , the leader key | |
let mapleader = "," | |
" resize window | |
map <C-j> <C-W>- | |
map <C-k> <C-W>+ | |
map <C-l> <C-W>> | |
map <C-h> <C-W>< | |
" Allow to resize windows and select tabs with mouse in terminal vim | |
" Unfortunately makes copy&paste with mouse cumbersome, but let's try | |
set mouse=a | |
" Remember last location in file | |
if has("autocmd") | |
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | |
\| exe "normal g'\"" | endif | |
endif | |
" make uses real tabs | |
au FileType make set noexpandtab | |
" Thorfile, Rakefile, Vagrantfile and Gemfile are Ruby | |
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru} set ft=ruby | |
" use zsh syntax highlighting for also for bash (better) | |
au BufNewFile,BufRead *.sh set ft=zsh | |
" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ ) | |
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79 | |
" make javascript to use jQuery code style | |
" Rails.vim always overrides the above (with autoload) but allows this: | |
au User Rails/**/*.js set shiftwidth=2 softtabstop=2 expandtab | |
" and also set it for non Rails Javascript files | |
au FileType javascript set shiftwidth=2 softtabstop=2 expandtab | |
" make htmldjango use 4 spaces as Django | |
au FileType htmldjango set softtabstop=4 tabstop=4 shiftwidth=4 expandtab | |
" make html files use 4 spaces | |
au FileType html set softtabstop=4 tabstop=4 shiftwidth=4 expandtab | |
" shortcuts to enable Django templates syntax in .html files | |
autocmd BufEnter *html map <F8> :setfiletype htmldjango<CR> | |
autocmd BufEnter *html map <S-F8> :setfiletype django<CR> | |
" shortcut to enable Handlebars templates syntax in .html files | |
autocmd BufEnter *html map <F9> :setfiletype html syntax=mustache<CR> | |
" allow backspacing over everything in insert mode | |
set backspace=indent,eol,start | |
" load the plugin and indent settings for the detected filetype | |
filetype plugin indent on | |
" Opens an edit command with the path of the currently edited file filled in | |
" Normal mode: <Leader>e | |
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR> | |
" Opens a tab edit command with the path of the currently edited file filled in | |
" Normal mode: <Leader>t | |
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR> | |
" Inserts the path of the currently edited file into a command | |
" Command mode: Ctrl+P | |
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR> | |
" Automatically reload externally edited files | |
" Needs the tmux-plugins/vim-tmux-focus-events plugin to work correctly | |
" see also https://unix.stackexchange.com/a/383044 | |
"set autoread " does not work, see link above | |
autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif | |
autocmd FileChangedShellPost * | |
\ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None | |
" Unimpaired configuration | |
" Bubble single lines | |
nmap <C-Up> [e | |
nmap <C-Down> ]e | |
" Bubble multiple lines | |
vmap <C-Up> [egv | |
vmap <C-Down> ]egv | |
" Use modeline overrides | |
set modeline | |
set modelines=10 | |
" % to bounce from do to end etc. | |
runtime! macros/matchit.vim | |
" Show (partial) command in the status line | |
set showcmd | |
" Include user's local vim config | |
if filereadable(expand("~/.vimrc.local")) | |
source ~/.vimrc.local | |
endif | |
" use system clipboard for yanking and deleting | |
if has('unnamedplus') | |
set clipboard=unnamedplus | |
else | |
set clipboard=unnamed | |
endif | |
" allow deleting selection without updating the clipboard (yank buffer) | |
vnoremap x "_x | |
vnoremap X "_X | |
" no bells at all | |
set noerrorbells | |
set novisualbell | |
" Indent with Tab in visual mode | |
vmap <Tab> >gv | |
vmap <S-Tab> <gv | |
" make öö leave edit mode | |
imap öö <Esc> | |
" Stay in visual mode after indent | |
" see http://vim.wikia.com/wiki/Shifting_blocks_visually | |
vnoremap > >gv | |
vnoremap < <gv | |
" Always display the status line (current mode, filename, ...) | |
set laststatus=2 | |
" For webpack hot module replacement (HMR) to work | |
" see https://github.com/webpack/webpack/issues/781 | |
set backupcopy=yes | |
" always use working directory as start point for search in ctrlp | |
let g:ctrlp_working_path_mode = 0 | |
" List index files in ctrlp | |
"let g:ctrlp_show_hidden = 1 # this would also list files like .pyc | |
let g:ctrlp_dotfiles = 1 | |
" NERDTree configuration | |
let NERDTreeIgnore=['\.pyc$', '\.rbc$', '\~$'] | |
map <Leader>n :NERDTreeToggle<CR> | |
map <Leader>s :NERDTreeFind<CR> | |
let NERDTreeShowHidden=1 | |
" To fix arrows in NERDTree inside Putty terminal | |
" see https://github.com/scrooloose/nerdtree/issues/522 | |
let g:NERDTreeDirArrowExpandable = '+' | |
let g:NERDTreeDirArrowCollapsible = '~' | |
" Buffergator configuration | |
let g:buffergator_viewport_split_policy = "T" | |
let g:buffergator_split_size = 10 | |
let g:buffergator_autoexpand_on_split = 0 | |
" ZoomWin configuration | |
map <Leader><Leader> :ZoomWin<CR> | |
" CTags | |
map <Leader>rt :!ctags --extra=+f -R *<CR><CR> | |
map <C-\> :tnext<CR> | |
" Enable JSDoc and Flow syntax for vim-javascript plugin | |
let g:javascript_plugin_jsdoc = 1 | |
let g:javascript_plugin_flow = 1 | |
" Allow also .js extensions for vim-jsx | |
let g:jsx_ext_required = 0 | |
" remap pymode toggle breakpoint as it conflicts with buffergator | |
let g:pymode_breakpoint_bind = '<leader>p' | |
" let ale handle code checking of python code and not python mode | |
let g:pymode_lint = 0 | |
" disable folding in python code (enabled by default in klen/python-mode) | |
let g:pymode_folding = 0 | |
" Turn off rope in python-mode | |
let g:pymode_rope = 0 | |
" gist-vim defaults | |
if has("mac") | |
let g:gist_clip_command = 'pbcopy' | |
elseif has("unix") | |
let g:gist_clip_command = 'xclip -selection clipboard' | |
endif | |
let g:gist_detect_filetype = 1 | |
let g:gist_open_browser_after_post = 1 | |
" Turn off jslint errors by default | |
let g:JSLintHighlightErrorLine = 0 | |
" MacVIM shift+arrow-keys behavior (required in .vimrc) | |
let macvim_hig_shift_movement = 1 | |
" Advanced setup for ack.vim and ctrlp.vim | |
if executable('ag') | |
" Use ag over grep | |
let g:ackprg = 'ag --vimgrep' | |
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore | |
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' | |
" ag is fast enough that CtrlP doesn't need to cache | |
let g:ctrlp_use_caching = 0 | |
elseif executable('ack-grep') | |
" make ack.vim use ack-grep command under debian/ubuntu | |
let g:ackprg="ack-grep -H --nocolor --nogroup --column" | |
endif | |
" bind K to search word under cursor with ack.vim | |
nnoremap K :Ack! "\b<C-R><C-W>\b"<CR>:cw<CR> | |
" Show recently used files (using mru.vim plugin) | |
map <leader>f :MRU<CR> | |
" Better indentations for shell scripts (uses sh.vim plugin) | |
let g:sh_indent_case_labels=1 | |
" vim-close configuration | |
let g:closetag_filenames = "*.html,*.xhtml,*.phtml,*.jsx,*.js" | |
let g:closetag_xhtml_filenames = "*.xhtml,*.jsx,*.js" | |
let g:closetag_emptyTags_caseSensitive = 1 | |
let g:closetag_shortcut = '>' | |
let g:closetag_close_shortcut = '<leader>>' | |
" vim-airline configuration | |
let g:airline_theme = 'solarized' | |
let g:airline_solarized_bg = 'dark' | |
" Use the default set of separators with a few customizations | |
if !exists('g:airline_powerline_fonts') | |
let g:airline_left_sep=' ›' " Slightly fancier than '>' | |
let g:airline_right_sep='‹ ' " Slightly fancier than '<' | |
endif | |
" Show the name of the currently active git branch | |
let g:airline#extensions#branch#enabled = 1 | |
" Show open buffer on top | |
let g:airline#extensions#tabline#enabled = 1 | |
" vim-prettier configuration | |
let g:prettier#config#parser = 'flow' | |
let g:prettier#config#semi = 'false' | |
let g:prettier#config#bracket_spacing = 'true' | |
let g:prettier#config#trailing_comma = 'none' | |
let g:prettier#config#jsx_bracket_same_line = 'false' | |
" For project specific settings | |
set exrc | |
set secure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment