Created
January 12, 2022 19:56
-
-
Save eduardoarandah/8cff548f986b5b8aae637bf4722e5447 to your computer and use it in GitHub Desktop.
My .vimrc configuration
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
" I split my config into separate files so my real ~/.vimrc is just: | |
" source ~/scripts/.vimrc | |
" source ~/scripts/.vimrcplugins | |
" Update everthing: | |
" PlugUpgrade | |
" PlugUpdate | |
" CocUpdate | |
scriptencoding utf-8 " basic | |
set nocompatible " basic | |
filetype off " basic | |
filetype plugin on " Enable filetype plugins | |
filetype indent on " Enable loading the indent file for specific file types | |
syntax enable " Enable syntax highlighting | |
set redrawtime=30000 " Maximum time for syntax milliseconds | |
set maxmempattern=1000000 " Max memory for syntax in Kb | |
set encoding=utf-8 " Encoding (needed in youcompleteme) | |
set fileencoding=utf-8 " The encoding written to file. | |
set noerrorbells " No annoying sound on errors | |
set number " Line numbers on | |
set hidden " Allow buffer switching without saving | |
set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility | |
set lazyredraw " Don't redraw while executing macros (good performance config) | |
set magic " For regular expressions turn magic on | |
set showmatch " Show matching brackets/parenthesis | |
set mat=2 " How many tenths of a second to blink when matching brackets | |
set autoread " Detect changes | |
set t_vb= " Flashing screen is annoying | |
set ruler " Always show current position | |
set cmdheight=1 " Height of the command bar | |
set showcmd " Show command in status bar | |
set formatoptions=tcqj " Format options, each letter means something | |
set history=10000 " Sets how many lines of history VIM has to remember | |
set so=5 " Set 7 lines to the cursor - when moving vertically using j/k | |
set backspace=indent,eol,start " fix: backspace past start of operation | |
set linespace=0 " No extra spaces between rows | |
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too | |
set ff=unix " Use Unix as the standard file type | |
set ffs=unix,dos,mac " This gives the end-of-line (<EOL>) formats that will be tried | |
set virtualedit=block " If you need to define a block in visual block mode with bounds outside the actual text (that is, past the end of lines), you can allow this with: | |
set relativenumber " Use relative numbers instead of absolute | |
set wrap! " Don't wrap long lines | |
set background=dark " Dark | |
set autoindent " Auto indent | |
set shiftwidth=2 " Use indents of 2 spaces | |
set expandtab " Tabs are spaces, not tabs | |
set tabstop=2 " An indentation every four columns | |
set softtabstop=2 " Let backspace delete indent | |
set ai " Auto indent | |
set si " Smart indent | |
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J) | |
set switchbuf=useopen,usetab " Specify the behavior when switching between buffers | |
set hlsearch " Highlight search results | |
set incsearch " Makes search act like search in modern browsers | |
set ignorecase " Ignore case when searching | |
set smartcase " When searching try to be smart about cases | |
set gdefault " Add g (global) to substitute operations, :s/pattern/replacement/ | |
set splitbelow " Open split below | |
set splitright " Open split right | |
set listchars=trail:- | |
set mouse=a " Mouse support in all modes | |
" Wildmenu | |
set wildmenu " Show list instead of just completing | |
set wildignore=*.o,*~,*.pyc " Ignore compiled files | |
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store | |
set wildcharm=<tab> | |
" Temporary files | |
" Create tmp dir if not exists | |
if !isdirectory($HOME."/.vim/tmp") | |
call mkdir($HOME."/.vim/tmp","p") | |
endif | |
set backupdir=$HOME/.vim/tmp// | |
set directory=$HOME/.vim/tmp// | |
set undodir=$HOME/.vim/tmp// | |
set undofile | |
" Leader Key | |
let mapleader=" " | |
let maplocalleader = "\\" | |
" Copy text to the end of line | |
nnoremap Y y$ | |
" Repeat last command | |
nnoremap g. @: | |
" Scroll viewport faster: > | |
nnoremap <C-e> 2<C-e> | |
nnoremap <C-y> 2<C-y> | |
" Deleting to blackhole | |
nnoremap <leader>x "_x | |
nnoremap <leader>d "_d | |
nnoremap <leader>c "_c | |
" Refresh | |
nnoremap <F5> :e<CR> | |
" Save | |
nnoremap <C-s> :w!<CR> | |
vnoremap <C-s> <Esc>:w!<CR> | |
inoremap <C-s> <Esc>:w!<CR> | |
""""""""""""""""""""""" | |
" Clipboard | |
""""""""""""""""""""""" | |
" Fix issues when pasting a lot of code | |
nnoremap F2 :set pastetoggle<CR> | |
if has('clipboard') | |
if has('unnamedplus') | |
" When possible use + register for copy-paste | |
set clipboard=unnamedplus | |
else | |
" On mac and Windows, use * register for copy-paste | |
set clipboard=unnamed | |
endif | |
endif | |
" Don't lose clipboard when pasting | |
vnoremap p pgvy | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" search replace | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Clear search | |
nnoremap <silent> <leader><Esc> :let @/=""<cr> | |
" No highlight search | |
nnoremap <leader>/ :nohlsearch<cr> | |
" don't move cursor on * # | |
nmap * *N | |
nmap # #N | |
" * search selection (uses z register) | |
vnoremap * "zy:set hlsearch<cr>:let @z=escape(@z,'\\/')<cr>:let @/='\V'.@z<cr> | |
" <leader>r replace, repeat with . | |
nmap <leader>r viw*cgn | |
vmap <leader>r *cgn | |
" <leader>R replace all | |
nmap <leader>R viw*:%s/\V<C-r>z/<C-r>z | |
vmap <leader>R *:%s/\V<C-r>z/<C-r>z | |
" spanish keyboard | |
nnoremap ñ / | |
"""""""""""""""""""""""""""""""""""" | |
" Copy all matches in document | |
"""""""""""""""""""""""""""""""""""" | |
" Strategy: execute add command on each match on each line into an array | |
" then join with new line \n | |
" g flag: repeat on each match in the line | |
" n report matches only, don't make any substitutions | |
" e no errors please | |
" The |submatch()| function can be used to obtain matched text. The whole matched text can be accessed with submatch(0) | |
" read more | |
" :h substitute | |
" :h s_flags | |
" :h submatch() | |
command! CopyMatches let hits = [] | %substitute//\=add(hits, submatch(0))/gne | let @+ = join(hits, "\n") | |
""""""""""""""""""""""""""""""""""" | |
" Appereance / GUI | |
""""""""""""""""""""""""""""""""""" | |
colorscheme desert | |
" wrap/unwrap | |
nnoremap <leader>gw :set wrap<CR> | |
nnoremap <leader>gW :set wrap!<CR> | |
" Set extra options when running in GUI mode | |
if has("gui_running") | |
set guioptions-=m "remove menu bar | |
set guioptions-=T "remove toolbar | |
" Good fonts: source code pro, jetbrains mono, consolas, cascadia | |
" select with: set guifont=* | |
" check current with: :echo &guifont | |
set guifont=CascadiaCode-Regular:h13 | |
" set guifont=Cascadia_Code_SemiBold:h10:W600:cANSI:qDRAFT | |
" in windows, set render option for ligatures <> != >= <= | |
if (has('win32') || has('win64')) | |
set renderoptions=type:directx | |
endif | |
else | |
" Cursor in terminal | |
" https://vim.fandom.com/wiki/Configuring_the_cursor | |
" 1 or 0 -> blinking block | |
" 2 solid block | |
" 3 -> blinking underscore | |
" 4 solid underscore | |
" Recent versions of xterm (282 or above) also support | |
" 5 -> blinking vertical bar | |
" 6 -> solid vertical bar | |
if &term =~ '^xterm' | |
" normal mode | |
let &t_EI .= "\<Esc>[3 q" | |
" insert mode | |
let &t_SI .= "\<Esc>[6 q" | |
endif | |
endif | |
" Run maximized in GUI | |
if ((has('win32') || has('win64')) && has("gui_running")) | |
set lines=999 columns=999 | |
autocmd GUIEnter * simalt ~x " https://vim.fandom.com/wiki/Maximize_or_set_initial_window_size | |
endif | |
"""""""""""""""""""""""" | |
" OS saving, exploring | |
"""""""""""""""""""""""" | |
function! SaveAsNative() | |
browse confirm saveas | |
endfunction | |
command! SaveAsNative :call SaveAsNative() | |
" Open finder/explorer | |
if (has('win32') || has('win64')) | |
nnoremap <leader>e :!start explorer /e,%:p:h<CR> | |
nnoremap <leader>E :execute "!start explorer /e," . shellescape(getcwd(),1)<CR> | |
endif | |
if(has('unix')) | |
if(has('macunix')) | |
nnoremap <leader>e :silent execute '![ -f "%:p" ] && open -R "%:p" \|\| open "%:p:h"'<CR> | |
nnoremap <leader>E :!open .<CR> | |
else | |
nnoremap <leader>e :execute '!explorer.exe `wslpath -w ' . expand('%:p:h'). '`'<CR> | |
nnoremap <leader>E :!explorer.exe .<CR> | |
endif | |
endif | |
""""""""""""""""""""""""" | |
" Files browsing | |
""""""""""""""""""""""""" | |
let g:netrw_altfile = 1 " Don't register netrw as the alternate buffer | |
noremap <F4> :Explore<CR> | |
" Change dir to current path | |
command! ChangeDir :cd %:p:h<CR> | |
" Expand %% to current dir in command line | |
cnoremap %% <C-R>=fnameescape(expand("%:p:h")."/")<CR> | |
" Expand ^^ to current file path in command line | |
cnoremap ^^ <C-R>=fnameescape(expand("%:p"))<CR> | |
" Expand && to only file name (tail) | |
cnoremap && <C-R>=fnameescape(expand("%:t"))<CR> | |
" Insert filename | |
nnoremap <localleader>fn :let @z=expand('%:t')<Cr>"zp | |
imap <localleader>fn <esc><localleader>fn | |
" Insert other window filename | |
nnoremap <localleader>wn <C-w><C-w>:let @z=expand('%:t')<Cr><C-w><C-w>"zp | |
imap <localleader>wn <esc><localleader>wn | |
" Duplicate File | |
function! s:duplicate(name) | |
if a:name != '' | |
execute "w %:h/" . a:name | |
execute "e %:h/" . a:name | |
endif | |
endfunction | |
:command! -nargs=1 -bar Duplicate :call s:duplicate(<f-args>) | |
""""""""""""""""""""""""""""""""""" | |
" Neovim | |
""""""""""""""""""""""""""""""""""" | |
if (has("nvim")) | |
" Shows the effects of a command incrementally, as you type. | |
set inccommand=nosplit | |
" Fixes copying special chars | |
lang en_US | |
endif | |
"""""""""""""" | |
" Movement | |
"""""""""""""" | |
" Lines | |
nnoremap <C-l> g_ | |
vnoremap <C-l> g_ | |
nnoremap <C-h> ^ | |
vnoremap <C-h> ^ | |
" Buffers | |
nnoremap <C-j> :bn<CR> | |
nnoremap <C-k> :bp<CR> | |
" Alternate buffer | |
nnoremap <leader>k :b#<CR> | |
" Tabs | |
nnoremap <leader>tt :tabnew<CR> | |
nnoremap <leader>tc :tabclose<CR> | |
nnoremap ]t :tabnext<CR> | |
nnoremap [t :tabprevious<CR> | |
" Go to end of page and center | |
nnoremap G Gzz | |
" Add movement to jumplist when using relative numbers | |
nnoremap <expr> k (v:count > 2 ? "m'" . v:count : "") . 'k' | |
nnoremap <expr> j (v:count > 2 ? "m'" . v:count : "") . 'j' | |
""""""""" | |
" Buffers | |
""""""""" | |
" close buffer | |
nnoremap <leader>q :bd<CR> | |
" close unsaved buffer, no save | |
nnoremap <leader>Q :bd!<CR> | |
" just die please | |
nnoremap <leader>gq :qa!<CR> | |
" write | |
nnoremap <leader>w :w!<CR> | |
" close all buffers | |
nnoremap <leader>bd :%bd<CR> | |
" keep current window only | |
nnoremap <leader>o :only<CR> | |
"""""""" | |
" Splits | |
"""""""" | |
nnoremap <leader><up> :resize -10<CR> | |
nnoremap <leader><down> :resize +10<CR> | |
nnoremap <leader><left> :vertical resize -10<CR> | |
nnoremap <leader><right> :vertical resize +10<CR> | |
"""""""""""""""""" | |
" Visual Shortcuts | |
"""""""""""""""""" | |
" Visual line | |
nnoremap <leader>l _vg_ | |
" Visual document | |
nnoremap <leader>a ggVG | |
" Move lines in visual mode | |
vnoremap N :m '>+1<CR>gv=gv | |
vnoremap P :m '<-2<CR>gv=gv | |
" J K just move | |
vnoremap J j | |
vnoremap K k | |
""""""""""" | |
" Quick fix | |
""""""""""" | |
nnoremap [c :cprevious<cr> | |
nnoremap ]c :cnext<cr> | |
nnoremap <leader>co :copen<CR>; | |
nnoremap <leader>cc :cclose<CR>; | |
"""""""" | |
" Macros | |
"""""""" | |
" Execute macro q | |
nnoremap Q @q | |
" Execute macro q on visual selection | |
vnoremap Q :normal @q<CR> | |
""""""""""" | |
" Registers | |
""""""""""" | |
" Delete all registers | |
command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor | |
""""""""""""""""""""""""" | |
" Code formatting | |
""""""""""""""""""""""""" | |
" Indent all document | |
nnoremap == gg=G | |
" Delete blank lines | |
:command! DeleteBlankLines g/^\s*$/d | |
" Replace multiple blank lines for single line | |
function! DoubleBlankLinesRemove(...) | |
let save_pos = getpos(".") | |
silent! %s/\(\n\n\)\n\+/\1/e | |
nohlsearch | |
call setpos('.', save_pos) | |
endfunction | |
command! DoubleBlankLinesRemove :call DoubleBlankLinesRemove() | |
" Replace multiple horizontal spacing to single space | |
function! DoubleSpacesRemove(...) | |
let save_pos = getpos(".") | |
silent! %s/\S\zs \+/ /e | |
nohlsearch | |
call setpos('.', save_pos) | |
endfunction | |
command! DoubleSpacesRemove :call DoubleSpacesRemove() | |
" Delete trailing white space | |
function! DeleteTrailingWhiteSpace(...) | |
let save_pos = getpos(".") | |
silent! %s/\s\+$//e | |
call setpos('.', save_pos) | |
endfunction | |
command! DeleteTrailingWhiteSpace :call DeleteTrailingWhiteSpace() | |
" Clean bad spaces | |
command! SpacesClean :call DeleteTrailingWhiteSpace() | call DoubleSpacesRemove() | call DoubleBlankLinesRemove() | |
""""""""""""""""""""""""""" | |
" Filetypes specific tuning | |
""""""""""""""""""""""""""" | |
augroup filetypes | |
autocmd! | |
" PHP | |
autocmd BufReadPost *.php setlocal iskeyword-=- | |
" Blade filetype | |
autocmd BufRead,BufNewFile *.blade.php set filetype=blade | |
autocmd BufReadPost *.blade.php setlocal iskeyword+=-,$ | |
" Txt as markdown | |
autocmd BufReadPost *.txt set filetype=markdown | |
" Html | |
autocmd BufRead,BufNewFile {*.html,*.css,*.scss} setlocal iskeyword+=#,-,$ | |
autocmd BufRead,BufNewFile *.html setlocal formatprg=prettier\ --parser=html\ --print-width=999 | |
" Css | |
autocmd BufRead,BufNewFile *.css setlocal iskeyword+=#,- | |
" Scss | |
autocmd BufRead,BufNewFile *.scss setlocal iskeyword+=#,-,$ | |
augroup END | |
""""""""""""""""""""""""""""""""""" | |
" Utils | |
""""""""""""""""""""""""""""""""""" | |
" Insert date | |
nnoremap <localleader>h i<c-r>=strftime("%Y-%m-%d")<CR><esc> | |
inoremap <localleader>h <c-r>=strftime("%Y-%m-%d")<CR> | |
" Underline | |
nnoremap <leader>- "zyy"zpVr-o<esc> | |
nnoremap <leader>= "zyy"zpVr=o<esc> | |
" Append colon and semicolon | |
nnoremap <leader>, A,<ESC> | |
nnoremap <leader>; A;<ESC> | |
" Open url under cursor | |
function! OpenURLUnderCursor() | |
let s:uri = expand('<cWORD>') | |
let s:uri = substitute(s:uri, '?', '\\?', '') | |
let s:uri = shellescape(s:uri, 1) | |
if s:uri != '' | |
silent exec "!open '".s:uri."'" | |
:redraw! | |
endif | |
endfunction | |
nnoremap gx :call OpenURLUnderCursor()<CR> |
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
" Download vim-plug if not exists | |
if !filereadable($HOME."/.vim/autoload/plug.vim") | |
!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
endif | |
" Create plugged dir if not exists | |
if !isdirectory($HOME."/.vim/plugged") | |
call mkdir($HOME."/.vim/plugged","p") | |
endif | |
" set runtimepath to use .vim folder instead of vimfiles | |
set rtp+=$HOME/.vim | |
call plug#begin('$HOME/.vim/plugged') | |
" surround with ys | |
Plug 'tpope/vim-surround' | |
" Create html tag | |
nmap <localleader>t yslt | |
imap <localleader>t <C-o>yslt | |
" Better repeating | |
Plug 'tpope/vim-repeat' | |
" Comments | |
Plug 'tpope/vim-commentary' | |
" Git Fugitive | |
Plug 'tpope/vim-fugitive' | |
nnoremap <leader>gs :Git<cr> | |
nnoremap <leader>ga :Git add %<cr> | |
nnoremap <leader>gA :Git add -A<cr> | |
nnoremap <leader>gl :Git log<cr> | |
nnoremap <leader>gp :Git push<cr> | |
command! Gammend :Git commit --amend | |
" git diff (:Gdiffsplit! for merge conflicts) | |
nnoremap <leader>gd :Gdiffsplit<cr> | |
" git merge left-right | |
nnoremap <leader>mh :diffget //2<cr> | |
nnoremap <leader>ml :diffget //3<cr> | |
" All commits | |
command! Ghistory :Gclog | |
" Commits for current file | |
command! Ghistoryfile :0Gclog! | |
" Shows a git diff in the sign column. | |
Plug 'mhinz/vim-signify' | |
" Maximizes and restores the current window in Vim. | |
Plug 'szw/vim-maximizer' | |
nnoremap <leader>z :MaximizerToggle<CR> | |
vnoremap <leader>z :MaximizerToggle<CR>gv | |
" NerdTree | |
Plug 'scrooloose/nerdtree', { 'on': [ 'NERDTreeToggle', 'NERDTreeFind', 'NERDTreeCWD' ] } | |
let NERDTreeShowHidden=1 | |
nnoremap <F7> :NERDTreeToggle<CR> | |
nnoremap <F8> :NERDTreeFind<CR> | |
" Change current dir to current file | |
nnoremap <leader>cd :cd %:p:h<CR>:NERDTreeCWD<CR> | |
" Auto close brackets | |
Plug 'jiangmiao/auto-pairs' | |
let g:AutoPairsShortcutToggle='' | |
let g:AutoPairsMapCh=0 " don't map this one | |
" RipGrep :Rg | |
Plug 'jremmen/vim-ripgrep' | |
let g:rg_command='rg --vimgrep --pcre2' | |
" Sessions | |
Plug 'xolox/vim-misc' "requirement | |
Plug 'romgrk/vim-session' | |
let g:session_autoload = 'no' | |
let g:session_autosave = 'yes' | |
let g:session_directory = $HOME."/.vim/sessions" | |
let g:session_extension = '' | |
" Create dir if not exists | |
if !isdirectory($HOME."/.vim/sessions") | |
call mkdir($HOME."/.vim/sessions","p") | |
endif | |
" Open session (project) | |
nnoremap <leader>s :OpenSession | |
" Highlight yank | |
Plug 'machakann/vim-highlightedyank' | |
" Status/tabline | |
Plug 'vim-airline/vim-airline' | |
let g:airline#extensions#tabline#enabled = 1 | |
" Show just the filename | |
let g:airline#extensions#tabline#fnamemod = ':t' | |
" Show terminal buffers | |
let g:airline#extensions#tabline#ignore_bufadd_pat = 'defx|gundo|nerd_tree|startify|tagbar|undotree|vimfiler' | |
" Color | |
set background=dark | |
set termguicolors | |
" if terminal has 256 colors | |
if !has("gui_running") | |
let g:rehash256 = 1 | |
endif | |
" Mejores | |
Plug 'tomasr/molokai' | |
" Useful commands | |
Plug 'tpope/vim-eunuch' | |
" :Delete: Delete a buffer and the file on disk simultaneously. | |
" :Unlink: Like :Delete, but keeps the now empty buffer. | |
" :Move: Rename a buffer and the file on disk simultaneously. | |
" :Rename: Like :Move, but relative to the current file's containing directory. | |
" :Chmod: Change the permissions of the current file. | |
" :Mkdir: Create a directory, defaulting to the parent of the current file. | |
" :Cfind: Run find and load the results into the quickfix list. | |
" :Clocate: Run locate and load the results into the quickfix list. | |
" :Lfind/:Llocate: Like above, but use the location list. | |
" :Wall: Write every open window. Handy for kicking off tools like guard. | |
" :SudoWrite: Write a privileged file with sudo. | |
" :SudoEdit: Edit a privileged file with sudo. | |
" File type detection for sudo -e is based on original file name. | |
" New files created with a shebang line are automatically made executable. | |
" New init scripts are automatically prepopulated with /etc/init.d/skeleton. | |
" Syntax | |
" https://github.com/sheerun/vim-polyglot | |
Plug 'sheerun/vim-polyglot' | |
" Calculate, how much? | |
" https://github.com/sk1418/HowMuch | |
Plug 'sk1418/HowMuch' | |
let g:HowMuch_scale = 8 | |
nmap <leader>hm V<Plug>AutoCalcAppendWithEq | |
vmap <leader>hm <Plug>AutoCalcAppendWithEq | |
vmap <leader>hms <Plug>AutoCalcAppendWithEqAndSum | |
vmap <leader>hmr <Plug>AutoCalcReplace | |
" FZF Fuzzy Finder | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' | |
if executable('rg') | |
" Use RipGrep to list files for fzf, include dotfiles in current directory | |
let $FZF_DEFAULT_COMMAND='{ rg --files; find . -type f -name ".*" -depth 1 }' | |
else | |
" Open GIT files if is a git repo, otherwise, just list files | |
nnoremap <expr> <C-p> (len(system('git rev-parse')) ? ':Files' : ':GFiles --exclude-standard --others --cached')."\<cr>" | |
endif | |
" Files | |
nnoremap <C-p> :Files<CR> | |
function! ChangeFZFDir() | |
let g:dir=expand('%:h') | |
nnoremap <C-p> :Files <c-r>=g:dir<CR><CR> | |
echo 'FZF files dir changed to: '. g:dir | |
endfunction | |
nnoremap <leader>cz :call ChangeFZFDir()<CR> | |
" History files | |
noremap <leader>hi :History<CR> | |
" Commands History | |
nnoremap <leader>: :History:<CR> | |
" All lines in all buffers | |
nnoremap <leader>j :Lines<CR> | |
" Find buffer | |
nnoremap <C-f> :Buffers<CR> | |
" Z plugin integration | |
" jump around recent directories | |
" https://github.com/rupa/z | |
nnoremap <localleader>z :call fzf#run({'source': 'cat ~/.z \| cut -d"\|" -f1', 'sink':'e'})<cr> | |
" Align in | with :Tabularize /| | |
Plug 'godlygeek/tabular' | |
" Display markers " | |
Plug 'kshenoy/vim-signature' | |
" Css Color | |
Plug 'ap/vim-css-color', { 'for': [ 'css', 'scss' ] } | |
" Change case (casing) | |
Plug 'arthurxavierx/vim-caser' | |
" gsp PascalCase | |
" gsc camelCase | |
" gs_ snake_case | |
" gsU UPPER_CASE | |
" gst Title Case | |
" gss Sentence case | |
" gs<space> space case | |
" gs- dash-case | |
" gsK Title-Dash-Case | |
" gs. dot.case | |
" Visual select and change case | |
function! Case() | |
let l:myMakeTargets = ["", "gsc", "gs-", "gsp", "gs_", "gsU", "gst", "gss", "gs\<space>", "gsKse", "gs."] | |
let l:c=0 | |
let l:c = confirm("Change case","&c camelCase\n&d dash-case\n&p PascalCase\n&_ snake_case\n&u UPPER_CASE\n&t Title Case\n&s Sentence case\n&a space case\n&k Title-Dash-Case\n&. dot.case") | |
if l:c != 0 | |
exec "norm gv" . l:myMakeTargets[l:c] | |
endif | |
endfunction | |
command! -range Case :call Case() | |
"""""""""""""""""""""""""""""""""""""""""" | |
" Markdown | |
"""""""""""""""""""""""""""""""""""""""""" | |
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } | |
"""""""""""""""""""""""""""""""""""""""""" | |
" Prettier | |
" https://github.com/prettier/vim-prettier | |
"""""""""""""""""""""""""""""""""""""""""" | |
Plug 'prettier/vim-prettier', { | |
\ 'do': 'yarn install', | |
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'yaml', 'html', 'php'] } | |
let g:prettier#exec_cmd_path = "/usr/local/bin/prettier" | |
""""""""""""""""""""""""""""""""""""""" | |
" REPL, send commands to another window | |
""""""""""""""""""""""""""""""""""""""" | |
" https://github.com/jpalardy/vim-slime | |
Plug 'jpalardy/vim-slime' | |
" make it work with tmux | |
let g:slime_target = "tmux" | |
" target_pane | |
" {last} current window, last pane, | |
" :.2 current window, second pane | |
" %pane_id get it with echo $TMUX_PANE | |
let g:slime_default_config = {"socket_name": get(split($TMUX, ","), 0), "target_pane": "{last}"} | |
let g:slime_no_mappings = 1 | |
xmap <F9> <Plug>SlimeRegionSend | |
nmap <F9> <Plug>SlimeParagraphSend | |
""""""""""""""""""""""""""""""""""""""""""" | |
" CoC Code Completion | |
" https://github.com/neoclide/coc.nvim | |
"""""""""""""""""""""""""""""""""""""""""" | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
let g:coc_filetype_map = { | |
\ 'blade.php': 'blade', | |
\ } | |
" " Install if not installed | |
let g:coc_global_extensions = [ | |
\ 'coc-snippets', | |
\ 'coc-dictionary', | |
\ 'coc-html', | |
\ 'coc-css' , | |
\ 'coc-tsserver', | |
\ 'coc-json', | |
\ 'coc-eslint', | |
\ 'coc-yaml', | |
\ 'coc-vetur' | |
\ ] | |
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable | |
" delays and poor user experience. | |
set updatetime=50 | |
" Don't pass messages to |ins-completion-menu|. | |
set shortmess+=c | |
" Always show the signcolumn, otherwise it would shift the text each time diagnostics appear/become resolved. | |
set signcolumn=yes | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? coc#_select_confirm() : | |
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
let g:coc_snippet_next = '<c-j>' | |
let g:coc_snippet_prev = '<c-k>' | |
" Use <C-j> for both expand and jump (make expand higher priority.) | |
imap <C-j> <Plug>(coc-snippets-expand-jump) | |
" Use <c-space> to trigger completion. | |
inoremap <silent><expr> <localleader><localleader> coc#refresh() | |
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current | |
" position. Coc only does snippet and additional edit on confirm. | |
if exists('*complete_info') | |
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
else | |
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
endif | |
" navigate diagnostics `[g` and `]g` | |
nmap <silent> [g <Plug>(coc-diagnostic-prev) | |
nmap <silent> ]g <Plug>(coc-diagnostic-next) | |
" GoTo code navigation. | |
nmap <silent> <localleader>d <Plug>(coc-definition) | |
nmap <silent> <localleader>e <Plug>(coc-references) | |
nmap <silent> <localleader>y <Plug>(coc-type-definition) | |
" nmap <silent> gi <Plug>(coc-implementation) | |
" Use K to show documentation in preview window. | |
nnoremap <silent> K :call <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
else | |
call CocAction('doHover') | |
endif | |
endfunction | |
" Hover help | |
" :h coc#float#has_scroll() | |
if has('nvim-0.4.0') || has('patch-8.2.0750') | |
nnoremap <silent><nowait><expr> <Down> coc#float#has_scroll() ? coc#float#scroll(1) : "\<Down>" | |
nnoremap <silent><nowait><expr> <Up> coc#float#has_scroll() ? coc#float#scroll(0) : "\<Up>" | |
inoremap <silent><nowait><expr> <Down> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>" | |
inoremap <silent><nowait><expr> <Up> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>" | |
vnoremap <silent><nowait><expr> <Down> coc#float#has_scroll() ? coc#float#scroll(1) : "\<Down>" | |
vnoremap <silent><nowait><expr> <Up> coc#float#has_scroll() ? coc#float#scroll(0) : "\<Up>" | |
endif | |
augroup cursor | |
autocmd! | |
" Highlight the symbol and its references when holding the cursor. | |
autocmd CursorHold * silent call CocActionAsync('highlight') | |
augroup END | |
" Symbol rename | |
nmap <localleader>r <Plug>(coc-rename) | |
" Global search | |
noremap <localleader>s yiw:CocSearch <C-r>"<CR> | |
vnoremap <localleader>s y<esc>:CocSearch <C-r>"<CR> | |
" Range format like <leader>fip | |
vmap <localleader>f <Plug>(coc-format-selected) | |
nmap <localleader>f <Plug>(coc-format-selected) | |
" augroup mygroup | |
" autocmd! | |
" Setup formatexpr specified filetype(s). | |
" autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected') | |
" Update signature help on jump placeholder. | |
" autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') | |
" augroup end | |
" Applying codeAction to the selected region. | |
" Example: `<leader>aap` for current paragraph | |
xmap <localleader>a <Plug>(coc-codeaction-selected)<cr> | |
nmap <localleader>a <Plug>(coc-codeaction-selected)<cr> | |
" Remap keys for applying codeAction to the current line. | |
" nmap <leader>ac <Plug>(coc-codeaction) | |
" " Apply AutoFix to problem on the current line. | |
nnoremap <localleader>x <Plug>(coc-fix-current) | |
" Introduce function text object | |
" NOTE: Requires 'textDocument.documentSymbol' support from the language server. | |
" xmap if <Plug>(coc-funcobj-i) | |
" xmap af <Plug>(coc-funcobj-a) | |
" omap if <Plug>(coc-funcobj-i) | |
" omap af <Plug>(coc-funcobj-a) | |
" Use <TAB> for selections ranges. | |
" NOTE: Requires 'textDocument/selectionRange' support from the language server. | |
" coc-tsserver, coc-python are the examples of servers that support it. | |
" nmap <silent> <TAB> <Plug>(coc-range-select) | |
" xmap <silent> <TAB> <Plug>(coc-range-select) | |
" Add `:Format` command to format current buffer. | |
command! -nargs=0 Format :call CocAction('format') | |
" Add `:Fold` command to fold current buffer. | |
command! -nargs=? Fold :call CocAction('fold', <f-args>) | |
" Add `:OR` command for organize imports of the current buffer. | |
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') | |
" Add (Neo)Vim's native statusline support. | |
" NOTE: Please see `:h coc-status` for integrations with external plugins that | |
" provide custom statusline: lightline.vim, vim-airline. | |
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} | |
" Mappings using CoCList: | |
" Show all diagnostics. | |
" nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr> | |
" Manage extensions. | |
" nnoremap <silent> <space>e :<C-u>CocList extensions<cr> | |
" Show commands. | |
" nnoremap <silent> <space>c :<C-u>CocList commands<cr> | |
" Find symbol of current document. | |
" nnoremap <silent> <space>o :<C-u>CocList outline<cr> | |
" Search workspace symbols. | |
" nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr> | |
" Do default action for next item. | |
" nnoremap <silent> <space>j :<C-u>CocNext<CR> | |
" Do default action for previous item. | |
" nnoremap <silent> <space>k :<C-u>CocPrev<CR> | |
" Resume latest coc list. | |
" nnoremap <silent> <space>p :<C-u>CocListResume<CR> | |
" | |
"""""""""""""""""""""""""""" | |
" Coc snippets | |
" https://github.com/neoclide/coc-snippets | |
"""""""""""""""""""""""""""" | |
" Use <C-l> for trigger snippet expand. | |
" imap <C-l> <Plug>(coc-snippets-expand) | |
" Use <C-j> for select text for visual placeholder of snippet. | |
" vmap <C-j> <Plug>(coc-snippets-select) | |
" Use <C-j> for jump to next placeholder, it's default of coc.nvim | |
let g:coc_snippet_next = '<c-n>' | |
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim | |
let g:coc_snippet_prev = '<c-p>' | |
" Use <C-j> for both expand and jump (make expand higher priority.) | |
" imap <C-j> <Plug>(coc-snippets-expand-jump) | |
" Edit snippets | |
nnoremap <leader>u :CocCommand snippets.editSnippets<CR> | |
" Add to CocConfig | |
" { | |
" 'snippets': { | |
" 'userSnippetsDirectory': '~/scripts/vim/ultisnips' | |
" }, | |
" 'languageserver': { | |
" 'intelephense': { | |
" 'command': 'intelephense', | |
" 'args': ['--stdio'], | |
" 'filetypes': ['php'], | |
" 'initializationOptions': { | |
" 'storagePath': '/tmp/intelephense' | |
" } | |
" } | |
" }, | |
" 'stylelint.enable': true, | |
" 'stylelint.config': '~/.stylelint' | |
" } | |
" | |
call plug#end() | |
" After loading plugins | |
" colorscheme onedark | |
" colorscheme palenight | |
colorscheme molokai | |
" Better cursor highlighting | |
" hi Search cterm=NONE ctermfg=255 guifg=#eeeeee ctermbg=88 guibg=#870000 | |
" treesitter enable | |
" if (has("nvim")) | |
" lua <<EOF | |
" require'nvim-treesitter.configs'.setup { | |
" ensure_installed ={ "javascript", "json", "css", "php", "html", "python", "bash", "regex", "ruby", "yaml", "jsonc", "tsx", "lua", "vue" }, -- one of "all", "maintained" (parsers with maintainers), or a list of languages | |
" highlight = { | |
" enable = true, | |
" disable = { "php" }, -- list of language that will be disabled | |
" }, | |
" indent = { | |
" enable = false | |
" }, | |
" context_commentstring = { | |
" enable = true | |
" } | |
" } | |
" EOF | |
" endif | |
" disable = { "php" }, -- list of language that will be disabled | |
" context_commentstring = { | |
" enable = true, | |
" config = { | |
" php = { | |
" element = "XXXX %s ", | |
" start_tag = "YYYYYYY %s zzz", | |
" attribute = "ZZZZZZz %s zzz", | |
" html = "111111 %s zzz" | |
" } | |
" } | |
" }, | |
" playground = { | |
" enable = true, | |
" disable = {}, | |
" updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code | |
" persist_queries = false, -- Whether the query persists across vim sessions | |
" keybindings = { | |
" toggle_query_editor = 'o', | |
" toggle_hl_groups = 'i', | |
" toggle_injected_languages = 't', | |
" toggle_anonymous_nodes = 'a', | |
" toggle_language_display = 'I', | |
" focus_language = 'f', | |
" unfocus_language = 'F', | |
" update = 'R', | |
" goto_node = '<cr>', | |
" show_help = '?', | |
" }, | |
" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment