" As recommended by `:help provider`, define a venv just for neovim that has " the neovim module and some Python linters let g:python3_host_prog = expand('~/.config/nvim/env/bin/python') " Enable nocompatible if has('vim_starting') " set default encoding to utf-8 " Let Vim use utf-8 internally, because many scripts require this exe 'set encoding=utf-8' scriptencoding utf-8 if &compatible set nocompatible endif " python host if !empty($PYTHON_HOST_PROG) let g:python_host_prog = $PYTHON_HOST_PROG endif if !empty($PYTHON3_HOST_PROG) let g:python3_host_prog = $PYTHON3_HOST_PROG endif endif """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Sections: " -> Settings (01-settings) " -> Theme (02-theme) " -> Keymap (10-keymap-general, 11-keymap-rtl) " -> File type specific (31-file-type.vim) " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " ================================================== " Basic Settings " ================================================== let mapleader="\" " Change the leader to be a space set cmdheight=2 " Make command line two lines high set scrolloff=7 " Set 7 lines to the cursor - when moving vertically using j/k set sidescrolloff=5 " Have some context around the current line always on screen set cursorline " Have a line indicate the cursor location (slow) set autoindent " Always set autoindenting on set smartindent " Set smart indent set showcmd " Display incomplete commands set ruler " Show the cursor position all the time set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) set number norelativenumber " Show line numbers set ttyfast " Smoother changes set modeline " Last lines in document sets vim mode set shortmess=atIc " Abbreviate messages set nostartofline " Don't jump to first character when paging set backspace=indent,eol,start set matchpairs+=<:> " Show matching <> (html mainly) as well set showmatch " Show matching brackets when text indicator is over them set matchtime=3 " How many tenths of a second to blink when matching brackets set showmatch " Show matching braces, somewhat annoying... set history=1000 " Sets how many lines of history VIM has to remember set showmode " Show the default mode text (e.g. -- INSERT -- below the statusline) set timeout ttimeoutlen=50 set updatetime=300 " Smaller updatetime for CursorHold & CursorHoldI set signcolumn=yes set whichwrap+=<,>,h,l,[,] set fileformats=unix,dos,mac set encoding=utf-8 set completeopt=longest,menuone " Preview mode causes flickering set clipboard+=unnamedplus " Share the system clipboard set splitright " Splits to the right autocmd VimResized * wincmd = " Automatically equalize splits when Vim is resized set wildmenu " show list instead of just completing set wildmode=list:longest,full " command completion, list matches, then longest common part, then all. set completeopt=menu " Just show the menu upon completion (faster) syntax on set synmaxcol=200 " Syntax highlight only the first 200 chars" filetype plugin on filetype indent plugin on set colorcolumn=80 "set colorcolumn=125 " Comfortable _and_ Github's line length if has('linebreak') " Break indent wrapped lines set breakindent let &showbreak = '↳ ' set cpo+=n end " Linebreak on 500 characters set lbr set tw=80 " ================================================== " Turn persistent undo on means that you can undo " even when you close a buffer/VIM " ================================================== set directory=~/.nvim_runtime/temp_dirs/swap/ set backupdir=~/.nvim_runtime/temp_dirs/backup/ try set undodir=~/.nvim_runtime/temp_dirs/undodir set undofile catch endtry " ================================================== " 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 " Returns true if paste mode is enabled function! HasPaste() if &paste return 'PASTE MODE ' endif return '' endfunction " ================================================== " Use terminal title as an output " ================================================== set title set titleold="Terminal" set titlestring=%F " ================================================== " No annoying sound on errors " ================================================== set noerrorbells set novisualbell set t_vb= set tm=500 " Properly disable sound on errors on MacVim if has("gui_macvim") autocmd GUIEnter * set vb t_vb= endif " ================================================== " Tab expanded to 8 spaces " ================================================== set tabstop=8 " numbers of spaces of tab character set shiftwidth=8 " numbers of spaces to (auto)indent set expandtab " Tab to spaces by default set softtabstop=8 set smarttab " Be smart when using tabs ;) " ================================================== " Search settings " ================================================== set hlsearch " highlight searches set incsearch " do incremental searching set ignorecase " ignore case when searching set infercase " smarter completions that will be case aware when ignorecase is on set smartcase " if searching and search contains upper case, make case sensitive search set list listchars=trail:»,tab:»- set fillchars+=vert:\ " ================================================== " No modelines for security " ================================================== set modelines=0 set nomodeline " ================================================== " Trailing whitespace handling " ================================================== " Highlight end of line whitespace. highlight WhitespaceEOL ctermbg=red guibg=red match WhitespaceEOL /\s\+$/ " ================================================== " Further settings " ================================================== " Try to display very long lines, rather than showing @ set display+=lastline " show trailing whitespace as -, tabs as >- set listchars=tab:>-,trail:- set list " Live substitution set inccommand=split if has("nvim") set laststatus=1 endif " 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 " Don't redraw while executing macros (good performance config) set lazyredraw " For regular expressions turn magic on set magic " when at 3 spaces, and I hit > ... go to 4, not 7 set shiftround " number of undo saved in memory set undolevels=10000 " How many undos set undoreload=10000 " number of lines to save for undo " set list set list listchars=tab:\┆\ ,trail:·,nbsp:± " doesn't prompt a warning when opening a file and the current file was written but not saved set hidden " no swap file! This is just annoying set noswapfile " Fold related set foldlevelstart=0 " Start with all folds closed " Set foldtext set foldtext=general#FoldText() " Show the substitution LIVE set inccommand=nosplit " for vertical pane in git diff tool set diffopt+=vertical autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " Set to auto read when a file is changed from the outside set autoread " indentLine let g:indentLine_char = '▏' let g:indentLine_color_gui = '#363949' " vim:set et sw=2: " ================================================== " Color scheme and fonts " ================================================== let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle let g:material_theme_style = 'palenight' " disable the mouse - who needs a mouse?? set mouse-=a set guicursor= " Set font according to system if has("mac") || has("macunix") set gfn=IBM\ Plex\ Mono:h14,Hack:h14,Source\ Code\ Pro:h15,Menlo:h15 elseif has("win16") || has("win32") set gfn=IBM\ Plex\ Mono:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11 elseif has("gui_gtk2") set gfn=IBM\ Plex\ Mono:h14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11 elseif has("linux") set gfn=IBM\ Plex\ Mono:h14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11 elseif has("unix") set gfn=Monospace\ 11 endif " Disable scrollbars (real hackers don't use scrollbars for navigation!) set guioptions-=r set guioptions-=R set guioptions-=l set guioptions-=L if (has("nvim")) "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 > let $NVIM_TUI_ENABLE_TRUE_COLOR=1 endif " Enable 256 colors palette in Gnome Terminal if $COLORTERM == 'gnome-terminal' set t_Co=256 endif set background=dark "colorscheme material set t_Co=256 colorscheme desert hi Conceal guifg=#81A1C1 guibg=NONE ctermbg=NONE let g:palenight_terminal_italics=1 let g:material_terminal_italics = 1 "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 > "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd > " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 > if (has("termguicolors")) " Opaque Background (Comment out to use terminal's profile) set termguicolors endif " 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 highlight Pmenu guibg=white guifg=black gui=bold highlight Comment gui=bold highlight Normal gui=none highlight NonText guibg=none " Transparent Background (For i3 and compton) highlight Normal guibg=NONE ctermbg=NONE highlight LineNr guibg=NONE ctermbg=NONE "" This will repair colors in Tmux. let &t_8f = "\[38;2;%lu;%lu;%lum" let &t_8b = "\[48;2;%lu;%lu;%lum" "" Tmuxline let g:tmuxline_theme = 'vim_statusline_3' let g:tmuxline_preset = 'tmux' "" Bufferline let g:bufferline_echo = 0 " This will keep your messages from getting quickly hidden. " vim:set et sw=2: " ================================================== " Basic Mappings " ================================================== " Maps for jj to act as Esc in insert and command modes ino jj cno jj " One can map ctrl-c to something else if needed map imap " Smarter j/k navigation " Convert the j and k movement commands from strict linewise movements to " onscreen display line movements via the gj and gk commands. When " preceded with a count we want to go back to strict linewise movements. " will automatically save movements larger than 5 lines to the jumplist. nnoremap j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj' nnoremap k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk' " Center next/previous matched string nnoremap n nzz nnoremap N Nzz " Save session exec 'nnoremap ss :mksession! ~/.nvim_runtime/sessions/*.vim' " Reload session exec 'nnoremap sl :so ~/.nvim_runtime/sessions/*.vim' " quick make map :make " simple pasting from the system clipboard " http://tilvim.com/2014/03/18/a-better-paste.html map p :set pasteo"+]p:set nopaste " Quickly save, quit, or save-and-quit map w :w map x :x map q :q " un-highlight when esc is pressed map :noh " Quickly toggle relative line numbers function ToggleRelativeLineNumbers() set invnumber set invrelativenumber endfunction nnoremap l :call ToggleRelativeLineNumbers() " Toggle between absolute -> relative line number "nnoremap :let [&nu, &rnu] = [&nu, &nu+&rnu==1] " Save files as root cnoremap w!! execute ':w suda://%' " ================================================== " vimrc handling " ================================================== " ,v loads .vimrc " ,V reloads .vimrc -- activating changes (needs save) map v :sp ~/.config/nvim/init.vim_ map V :source ~/.config/nvim/init.vim:filetype detect:exe ":echo 'vimrc reloaded'" " ================================================== " Window navigation " ================================================== " control + vim direction key to navigate windows noremap j noremap k noremap h noremap l " control + arrow key to navigate windows noremap j noremap k noremap h noremap l " close all windows except the current one nnoremap wco :only nnoremap wcc :cclose " windows creation " create window on the bottom nnoremap wb s " create vertival window nnoremap wv v " " arrow keys resize windows " nnoremap :vertical resize -10 " nnoremap :vertical resize +10 " nnoremap :resize -10 " nnoremap :resize +10 " imap " imap " imap " imap " ================================================== " Splits handling " ================================================== " Make these all work in insert mode imap " - and + to resize horizontal splits map - - map + + " alt-< or alt-> for vertical splits map > map < " F2 close current split (window) noremap :close " Deleter buffer, keep the split (switch to prev buf, delete now prev buf) nmap d :b#bd# " ================================================== " Tab navigation " ================================================== map to :tabonly map tc :tabclose map tm :tabmove nnoremap tn :tabnew nnoremap th :tabfirst nnoremap tk :tabnext nnoremap tj :tabprev nnoremap tl :tablast " move tab to first position nnoremap tF :tabm 0 nnoremap tL :tabm " Navigate tabs with shift-{h,l} noremap gt noremap gT " Let 'tl' toggle between this and the last accessed tab let g:lasttab = 1 nmap tl :exe "tabn ".g:lasttab 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 te :tabedit =expand("%:p:h")/ " Switch CWD to the directory of the open buffer map cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry " ================================================== " Buffer navigation " ================================================== nmap :bnext nmap :bprevious " ================================================== " Clean all end of line whitespace with S " ================================================== ":nnoremap S :let _s=@/:%s/\s\+$//e:let @/=_s:nohl fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun :nnoremap S :call TrimWhitespace() " ================================================== " Visual mode related " ================================================== " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call VisualSelection('', '')/=@/ vnoremap # :call VisualSelection('', '')?=@/ 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 " ================================================== " 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 mz:m+`z nmap mz:m-2`z vmap :m'>+`mzgv`yo`z vmap :m'<-2`>my` nmap vmap vmap endif " ================================================== " Spell checking " ================================================== " Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! " Shortcuts using map sn ]s map sp [s map sa zg map s? z= " ================================================== " Other Configurations " ================================================== " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " Quickly open a buffer for scribble map q :e ~/buffer " Quickly open a markdown buffer for scribble map x :e ~/buffer.md " Toggle paste mode on and off map pp :setlocal paste! noremap :Denite buffer file_rec tag xmap a gaip* nmap t sj:terminal nmap vt vl:terminal nmap g :Goyo nmap j :set filetype=journal nmap l :Limelight!! autocmd FileType python nmap x :0,$!~/.config/nvim/env/bin/python -m yapf vmap !boxes -d stone " surround by quotes - frequently use cases of vim-surround map " ysiw" map ' ysiw' " Act like D and C nnoremap Y y$ " indent without kill the selection in vmode vmap < >gv " remap the annoying u in visual mode vmap u y " shortcut to substitute current word under cursor nnoremap [ :%s///g " Change in next bracket nmap cinb cib " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call general#VisualSelection('', '')/=@/ vnoremap # :call general#VisualSelection('', '')?=@/ " delete character after cursor in insert mode inoremap " highlight the line which is longer than the defined margin (120 character) highlight MaxLineChar ctermbg=red autocmd FileType php,js,vue,go call matchadd('MaxLineChar', '\%120v', 100) " open devdocs.io with waterfox and search the word under the cursor command! -nargs=? DevDocs :call system('type -p open >/dev/null 2>&1 && open https://devdocs.io/#q= || waterfox -url https://devdocs.io/#q=') autocmd FileType python,ruby,rspec,javascript,go,html,php,eruby,coffee,haml nmap D :exec "DevDocs " . fnameescape(expand('')) " Markdown autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown " Keep the cursor in place while joining lines nnoremap J mzJ`z " Quit neovim terminal tnoremap " Open images with feh autocmd BufEnter *.png,*.jpg,*gif silent! exec "! feh ".expand("%") | :bw " A |Dict| specifies the matcher for filtering and sorting the completion candidates. let g:cm_matcher={'module': 'cm_matchers.abbrev_matcher', 'case': 'smartcase'} " Disable anoying ex mode nnoremap Q " Neovim :Terminal tmap tmap autocmd BufWinEnter,WinEnter term://* startinsert autocmd BufLeave term://* stopinsert " vim:set et sw=2: " ================================================== " Right-to-Left (Hebrew etc) shortcuts " ================================================== " toggle direction mapping " this is useful for logical-order editing map :set invrl " do it when in insert mode as well (and return to insert mode) imap :set invrla " toggle reverse insertion " this is useful for visual-order editing map :set invrevins " do it when in insert mode as well (and return to insert mode) imap :set invrevinsa " vim:set et sw=2: " =================================================================== " FileType and Indentation settings " " Recommended: Don't rely on this, use editorconfig " in your project " =================================================================== " define less filetype au BufNewFile,BufRead *.less set filetype=less " make the smarty .tpl files html files for our purposes au BufNewFile,BufRead *.tpl set filetype=html " json au! BufRead,BufNewFile *.json set filetype=json " jquery au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery autocmd Filetype html setlocal ts=2 sw=2 expandtab autocmd Filetype xhtml setlocal ts=2 sw=2 expandtab autocmd Filetype xml setlocal ts=2 sw=2 expandtab autocmd Filetype css setlocal ts=2 sw=2 expandtab autocmd Filetype less setlocal ts=2 sw=2 expandtab autocmd Filetype ruby setlocal ts=2 sw=2 expandtab autocmd Filetype javascript setlocal ts=4 sw=4 sts=0 noexpandtab autocmd Filetype python setlocal omnifunc=jedi#completions tw=79 \ completeopt-=preview \ formatoptions+=c " HTML, XML, Jinja autocmd FileType html setlocal shiftwidth=2 tabstop=2 softtabstop=2 autocmd FileType css setlocal shiftwidth=2 tabstop=2 softtabstop=2 autocmd FileType xml setlocal shiftwidth=2 tabstop=2 softtabstop=2 autocmd FileType htmldjango setlocal shiftwidth=2 tabstop=2 softtabstop=2 autocmd FileType htmldjango inoremap {{ {{ }} autocmd FileType htmldjango inoremap {% {% %} autocmd FileType htmldjango inoremap {# {# #} " LaTeX let g:tex_flavor='latex' let g:vimtex_view_method='zathura' let g:vimtex_quickfix_mode=0 set conceallevel=1 let g:tex_conceal='abdmg' " Markdown and Journal autocmd FileType markdown setlocal shiftwidth=2 tabstop=2 softtabstop=2 autocmd FileType journal setlocal shiftwidth=2 tabstop=2 softtabstop=2 " Always assume .tex files are LaTeX let g:tex_flavor = "latex" " Don't autocomplete filenames that match these patterns " Version control set wildignore=.svn,.git " Compiled formats set wildignore+=*.o,*.pyc " Images set wildignore+=*.jpg,*.png,*.pdf " Auxilary LaTeX files set wildignore+=*.aux,*.bbl,*.blg,*.out,*.toc " Web development set wildignore+=vendor,_site,tmp,node_modules,bower_components " Script outputs set wildignore+=output au BufNewFile,BufRead ~/.mutt/tmp/neomutt-* setlocal filetype=mail " Makefiles require actual tabs au FileType make setlocal noexpandtab " Don't create backup files when editing crontabs au filetype crontab setlocal nobackup nowritebackup " Python style uses 4 spaces as tabs au FileType python setlocal tabstop=4 shiftwidth=4 au BufNewFile,BufRead *.md setlocal filetype=markdown syntax=markdown au BufNewFile,BufRead *.markdown setlocal syntax=markdown " Spellchecking in LaTeX, Markdown au FileType tex,plaintex,markdown setlocal spelllang=en_gb spell formatoptions=tcroqlj " Wrap Python automatically at 80 characters au FileType python setlocal textwidth=79 formatoptions=tcroqlj " relativenumber can be very slow when combined with a language whose syntax " highlighting regexs are complex " https://github.com/neovim/neovim/issues/2401 " https://groups.google.com/forum/#!topic/vim_use/ebRiypE2Xuw au FileType tex set norelativenumber " Enable marker folder for Beancount files au FileType beancount set foldmethod=marker foldlevel=0 foldlevelstart=0 " I often type `#` to start a comment, as alt-3, then hit space " alt-space is a UTF non-breaking space character, which can give encoding errors highlight UTFSpaceComment ctermfg=White ctermbg=1 au BufNewFile,BufRead * :syn match UTFSpaceComment '.\%uA0' augroup mail au! au FileType mail setlocal spell spelllang=en_gb " Common standard used in plaintext emails au FileType mail setlocal textwidth=72 " w: Lines ending with spaces continue on the next line, used in combination " with Mutt's text_flowed option " a: Format automatically " t: Wrap using textwidth " c: Wrap comments using textwidth " q: Format with gq macro au FileType mail setlocal formatoptions=watcq " Define comment leaders as in a Markdown document, that is: " * Treat *, -, +, and > as comment leaders " * Characters *, -, + begin comments when followed by a space, and wrapped " lines immediately after these should be indented " * Comments starting with > can be nested au FileType mail setlocal comments=fb:*,fb:-,fb:+,n:> " Install an autogroup that triggers when inside a `mail.*` syntax group au FileType mail call OnSyntaxChange#Install('NoWrapElements', '^mail', 1, 'a') " Use the trigger to disable/enable text wrapping when leaving/enter the " mail body (i.e. we only want wrapping in the mail body). au FileType mail autocmd User SyntaxNoWrapElementsEnterA setlocal formatoptions-=watc au FileType mail autocmd User SyntaxNoWrapElementsLeaveA setlocal formatoptions+=watc augroup end " Twig autocmd BufNewFile,BufRead *.twig set filetype=html.twig " PHP command! -nargs=1 Silent execute ':silent !'. | execute ':redraw!' map :w:Silent php-cs-fixer fix %:p --level=symfony " vim:set et sw=2: