Skip to content

Instantly share code, notes, and snippets.

@lucianoratamero
Last active April 2, 2023 15:37
Show Gist options
  • Save lucianoratamero/e20c19f68879ca5b4dec15778b60039d to your computer and use it in GitHub Desktop.
Save lucianoratamero/e20c19f68879ca5b4dec15778b60039d to your computer and use it in GitHub Desktop.
neovim configs - put inside ~/.config/nvim/

Neovim configs

Instructions:

{
"suggest.noselect": false,
"coc.preferences.formatOnType": true,
"eslint.autoFixOnSave": true,
"eslint.filetypes": ["javascript", "javascriptreact"],
"explorer.quitOnOpen": true,
"explorer.file.showHiddenFiles": true,
"explorer.previewAction.onHover": false,
"explorer.icon.enableNerdfont": true,
"python.jediEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"pairs.enableCharacters": ["(", "[", "{", "'", "\"", "`"],
"coc.preferences.formatOnSaveFiletypes": [
"javascript",
"typescript",
"typescriptreact",
"json",
"javascriptreact",
"typescript.tsx",
"graphql"
],
"explorer.keyMappings": {
"i": false,
"gk": "expandablePrev",
"gj": "expandableNext",
"*": "toggleSelection",
"<tab>": "actionMenu",
"h": "collapse",
"l": ["expandable?", "expand", "open"],
"J": ["toggleSelection", "nodeNext"],
"K": ["toggleSelection", "nodePrev"],
"gl": "expandRecursive",
"gh": "collapseRecursive",
"<2-LeftMouse>": [
"expandable?",
["expanded?", "collapse", "expand"],
"open"
],
"o": ["expanded?", "collapse", "expand"],
"<cr>": [
"expandable?",
["expanded?", "collapse", "expand"],
"open"
],
"e": "open",
"s": "open:split",
"S": "open:split:plain",
"E": "open:vsplit",
"t": "open:tab",
"<bs>": "gotoParent",
"gp": "preview:labeling",
"y": "copyFilepath",
"Y": "copyFilename",
"c": "copyFile",
"x": "cutFile",
"p": "pasteFile",
"d": "delete",
"D": "deleteForever",
"a": "addFile",
"A": "addDirectory",
"r": "rename",
".": "toggleHidden",
"R": "refresh",
"?": "help",
"q": "quit",
"<esc>": "esc",
"X": "systemExecute",
"gd": "listDrive",
"f": "search",
"F": "searchRecursive",
"gf": "gotoSource:file",
"gb": "gotoSource:buffer",
"[[": "sourcePrev",
"]]": "sourceNext",
"[d": "diagnosticPrev",
"]d": "diagnosticNext",
"[c": "gitPrev",
"]c": "gitNext",
"<<": "gitStage",
">>": "gitUnstage"
}
}
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'itchyny/lightline.vim'
Plug 'editorconfig/editorconfig-vim'
Plug 'alvan/vim-closetag'
Plug 'tpope/vim-abolish'
Plug 'ayu-theme/ayu-vim'
Plug 'romainl/vim-qf'
Plug 'lfv89/vim-interestingwords'
Plug 'ryanoasis/vim-devicons'
Plug 'airblade/vim-gitgutter'
Plug 'ctrlpvim/ctrlp.vim' " fuzzy find files
Plug 'scrooloose/nerdcommenter'
Plug 'Shougo/denite.nvim', { 'do': ':UpdateRemotePlugins' }
" Initialize plugin system
call plug#end()
let mapleader = ","
" Show tabs and trailing whitespace visually
set list listchars=tab:>\ ,trail:.,extends:>,nbsp:_
" prettier command for coc
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" ctrlp
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
" j/k will move virtual lines (lines that wrap)
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
set autoread
set clipboard+=unnamedplus
set smarttab
set cindent
set tabstop=2
set shiftwidth=2
set noswapfile
set splitbelow
set splitright
set encoding=UTF-8
set fileencoding=utf-8
set fileencodings=utf-8
set termencoding=utf-8
set ttyfast
set number
set expandtab
set guifont=FiraCode\ Nerd\ Font\ Retina-12
set mouse=a
let g:NERDTreeQuitOnOpen = 1
"" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
let loaded_netrwPlugin = 1
autocmd BufWritePre * :%s/\s\+$//e
"" Keymaps
inoremap jk <ESC>
map <F5> mzggVGg?`z
nnoremap <C-t> :CocCommand explorer<CR>
vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle
nnoremap <C-Down> :m .+1<CR>==
nnoremap <C-Up> :m .-2<CR>==
inoremap <C-Down> <Esc>:m .+1<CR>==gi
inoremap <C-Up> <Esc>:m .-2<CR>==gi
vnoremap <C-Down> :m '>+1<CR>gv=gv
vnoremap <C-Up> :m '<-2<CR>gv=gv
map <Leader>y "*y
map <Leader>p "*p
inoremap <A-Del> <C-o>de
inoremap <C-s> <C-o>:w<CR>
nnoremap <C-s> :w<CR>
nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>
vnoremap < <gv
vnoremap > >gv
nmap ç <Plug>(qf_qf_switch)
nmap Ç :cclose<CR>
map <A-S-Left> <c-w><
map <A-S-Right> <c-w>>
map <A-S-Up> <c-w>+
map <A-S-Down> <c-w>-
set keymodel=startsel
"" Buffer nav
noremap <leader>z :bp<CR>
noremap <leader>q :bp<CR>
noremap <leader>x :bn<CR>
noremap <leader>w :bn<CR>
"" Close buffer
noremap <leader>c :bd<CR>
"" Tabs
nnoremap <Tab> gt
nnoremap <S-Tab> gT
nnoremap <silent> <S-t> :tabnew<CR>
"" Split
noremap <Leader>h :<C-u>split<CR>
noremap <Leader>v :<C-u>vsplit<CR>
"" no one is really happy until you have this shortcuts
cnoreabbrev W! w!
cnoreabbrev Q! q!
cnoreabbrev Qall! qall!
cnoreabbrev Wq wq
cnoreabbrev Wa wa
cnoreabbrev wQ wq
cnoreabbrev WQ wq
cnoreabbrev W w
cnoreabbrev Q q
cnoreabbrev Qall qall
let g:interestingWordsGUIColors = ['#8CCBEA', '#A4E57E', '#FFDB72', '#FF7272', '#FFB3FF', '#9999FF']
let g:closetag_filetypes = 'html,xhtml,phtml,js,jsx,ts'
set termguicolors " enable true colors support
let ayucolor="dark" " for dark version of theme
colorscheme ayu
let g:lightline = {
\ 'colorscheme': 'PaperColor_light',
\ }
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s --ignore=dist -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
" coc config
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-explorer',
\ 'coc-pairs',
\ 'coc-tsserver',
\ 'coc-tslint-plugin',
\ 'coc-python',
\ 'coc-prettier',
\ 'coc-eslint',
\ 'coc-json',
\ 'coc-jest',
\ ]
" from readme
" if hidden is not set, TextEdit might fail.
set hidden " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " Better display for messages set cmdheight=2 " You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> 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.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Or use `complete_info` if your vim support it, like:
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" 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
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <F2> <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>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
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" 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)
" Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <C-d> <Plug>(coc-range-select)
xmap <silent> <C-d> <Plug>(coc-range-select)
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" === Denite setup ==="
" Use ripgrep for searching current directory for files
" By default, ripgrep will respect rules in .gitignore
" --files: Print each file that would be searched (but don't search)
" --glob: Include or exclues files for searching that match the given glob
" (aka ignore .git files)
"
call denite#custom#var('file/rec', 'command', ['rg', '--files', '--glob', '!.git'])
" Use ripgrep in place of "grep"
call denite#custom#var('grep', 'command', ['rg'])
" Custom options for ripgrep
" --vimgrep: Show results with every match on it's own line
" --hidden: Search hidden directories and files
" --heading: Show the file name above clusters of matches from each file
" --S: Search case insensitively if the pattern is all lowercase
call denite#custom#var('grep', 'default_opts', ['--hidden', '--vimgrep', '--heading', '-S'])
" Recommended defaults for ripgrep via Denite docs
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])
" Remove date from buffer list
call denite#custom#var('buffer', 'date_format', '')
" Custom options for Denite
" auto_resize - Auto resize the Denite window height automatically.
" prompt - Customize denite prompt
" direction - Specify Denite window direction as directly below current pane
" winminheight - Specify min height for Denite window
" highlight_mode_insert - Specify h1-CursorLine in insert mode
" prompt_highlight - Specify color of prompt
" highlight_matched_char - Matched characters highlight
" highlight_matched_range - matched range highlight
let s:denite_options = {'default' : {
\ 'split': 'floating',
\ 'start_filter': 1,
\ 'auto_resize': 1,
\ 'source_names': 'short',
\ 'prompt': 'λ ',
\ 'highlight_matched_char': 'QuickFixLine',
\ 'highlight_matched_range': 'Visual',
\ 'highlight_window_background': 'Visual',
\ 'highlight_filter_background': 'DiffAdd',
\ 'winrow': 1,
\ 'vertical_preview': 1
\ }}
" Loop through denite options and enable them
function! s:profile(opts) abort
for l:fname in keys(a:opts)
for l:dopt in keys(a:opts[l:fname])
call denite#custom#option(l:fname, l:dopt, a:opts[l:fname][l:dopt])
endfor
endfor
endfunction
"
" Define mappings while in 'filter' mode
" <C-o> - Switch to normal mode inside of search results
" <Esc> - Exit denite window in any mode
" <CR> - Open currently selected file in any mode
" <C-t> - Open currently selected file in a new tab
" <C-v> - Open currently selected file a vertical split
" <C-h> - Open currently selected file in a horizontal split
autocmd FileType denite-filter call s:denite_filter_my_settings()
function! s:denite_filter_my_settings() abort
imap <silent><buffer> <C-o>
\ <Plug>(denite_filter_quit)
inoremap <silent><buffer><expr> <Esc>
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> <Esc>
\ denite#do_map('quit')
inoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
inoremap <silent><buffer><expr> <C-t>
\ denite#do_map('do_action', 'tabopen')
inoremap <silent><buffer><expr> <C-v>
\ denite#do_map('do_action', 'vsplit')
inoremap <silent><buffer><expr> <C-h>
\ denite#do_map('do_action', 'split')
endfunction
" Define mappings while in denite window
" <CR> - Opens currently selected file
" q or <Esc> - Quit Denite window
" d - Delete currenly selected file
" p - Preview currently selected file
" <C-o> or i - Switch to insert mode inside of filter prompt
" <C-t> - Open currently selected file in a new tab
" <C-v> - Open currently selected file a vertical split
" <C-h> - Open currently selected file in a horizontal split
autocmd FileType denite call s:denite_my_settings()
function! s:denite_my_settings() abort
nnoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
nnoremap <silent><buffer><expr> q
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> <Esc>
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> d
\ denite#do_map('do_action', 'delete')
nnoremap <silent><buffer><expr> p
\ denite#do_map('do_action', 'preview')
nnoremap <silent><buffer><expr> i
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <C-o>
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <C-t>
\ denite#do_map('do_action', 'tabopen')
nnoremap <silent><buffer><expr> <C-v>
\ denite#do_map('do_action', 'vsplit')
nnoremap <silent><buffer><expr> <C-h>
\ denite#do_map('do_action', 'split')
endfunction
nmap ; :Denite buffer<CR>
nmap <leader>t :DeniteProjectDir file/rec<CR>
nnoremap <leader>g :<C-u>Denite grep:. -no-empty<CR>
nnoremap <leader>j :<C-u>DeniteCursorWord grep:.<CR>
"""
call s:profile(s:denite_options)
function ToggleFold()
if foldlevel('.') == 0
" No fold exists at the current line,
" so create a fold based on indentation
let l_min = line('.') " the current line number
let l_max = line('$') " the last line number
let i_min = indent('.') " the indentation of the current line
let l = l_min + 1
" Search downward for the last line whose indentation > i_min
while l <= l_max
" if this line is not blank ...
if strlen(getline(l)) > 0 && getline(l) !~ '^\s*$'
if indent(l) <= i_min
" we've gone too far
let l = l - 1 " backtrack one line
break
endif
endif
let l = l + 1
endwhile
" Clamp l to the last line
if l > l_max
let l = l_max
endif
" Backtrack to the last non-blank line
while l > l_min
if strlen(getline(l)) > 0 && getline(l) !~ '^\s*$'
break
endif
let l = l - 1
endwhile
"execute "normal i" . l_min . "," . l . " fold" " print debug info
if l > l_min
" Create the fold from l_min to l
execute l_min . "," . l . " fold"
endif
else
" Delete the fold on the current line
normal zd
endif
endfunction
"Mapping para code fold
vmap <space> zf
nmap <space> :call ToggleFold()<CR>
"
" use `:OR` for organize import of current buffer
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Indent after pressing enter inside a dict
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" Run jest for current project
command! -nargs=0 Jest :call CocAction('runCommand', 'jest.projectTest')
" Run jest for current file
command! -nargs=0 JestCurrent :call CocAction('runCommand', 'jest.fileTest', ['%'])
" Run jest for current test
nnoremap <leader>te :call CocAction('runCommand', 'jest.projectTest')<CR>
nnoremap <leader>ti :call CocAction('runCommand', 'jest.singleTest')<CR>
" Init jest in current cwd, require global jest command exists
command! JestInit :call CocAction('runCommand', 'jest.init')
#!/usr/bin/env python3
import os
GIST_URL = "https://gist.github.com/lucianoratamero/e20c19f68879ca5b4dec15778b60039d"
def get_files_from_gist():
os.system("mkdir -p ~/.config/nvim/")
os.system(f"wget {GIST_URL}/raw/coc-settings.json")
os.system(f"wget {GIST_URL}/raw/init.vim")
os.system("mv init.vim ~/.config/nvim/")
os.system("mv coc-settings.json ~/.config/nvim/")
if __name__ == "__main__":
get_files_from_gist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment