Skip to content

Instantly share code, notes, and snippets.

@edrpls
Last active Dec 25, 2021
Embed
What would you like to do?
My neovim config on WSL/Ubuntu
set shell=/bin/sh
set termguicolors
set number
set ruler
set relativenumber
set cursorline
"set synmaxcol=1000
set clipboard=unnamed
"set list listchars=tab:\ ,eol:¬,trail:
" create Prettier command on start
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" fzf configuration
let $FZF_DEFAULT_COMMAND = 'fd -t f -H'
let $FZF_DEFAULT_OPTS = '--border --reverse --inline-info'
let g:fzf_layout = { 'window': 'FzfFloatingCenteredWindow' }
let g:fzf_buffers_jump = 1
nnoremap <silent> <leader><leader> :Files<CR>
nnoremap <M-l> :Lines <C-R><C-w><CR>
" refine quickfix results
command! RefineQuickfix call fzf#run({
\ 'source': map(getqflist(), function('<sid>qf_to_fzf')),
\ 'down': '20',
\ 'sink*': function('<sid>fzf_to_qf'),
\ 'options': '--multi --bind=ctrl-a:select-all,ctrl-d:deselect-all --prompt "quickfix> "',
\ 'window': 'FzfQuickfixFloatingWindow',
\ })
command! FzfFloatingCenteredWindow call s:fzf_floating_window({
\ 'width': 150,
\ 'height': 20,
\ 'relative': 'editor',
\ 'anchor': 'SW',
\ 'row': (&lines/2) + 10,
\ 'col': (&columns/2) - 75
\})
" Matches the height of the quickfix window and places the floating window at
" the bottom of the screen.
" The idea is to make it look like the quickfix window itself is being edited
command! FzfQuickfixFloatingWindow call s:fzf_floating_window({
\ 'height': min([20, len(getqflist())]) + 1,
\ 'width': &columns,
\ 'relative': 'editor',
\ 'anchor': 'SW',
\ 'row': &lines,
\ 'col': 0,
\})
command! -nargs=* Find call fzf#run({
\ 'source': printf('rg -a --vimgrep --color always "%s"',
\ escape(empty(<q-args>) ? '^(?=.)' : <q-args>, '"\')),
\ 'options': '--ansi --expect=ctrl-t,ctrl-v,ctrl-x --delimiter : --nth 4.. '.
\ '--multi --bind=ctrl-a:select-all,ctrl-d:deselect-all '.
\ '--color hl:68,hl+:110 -x',
\ 'sink*': function('<sid>rg_handler'),
\ 'down': '50%',
\ })
" Find string inside the CWD
nnoremap <leader>p/ :silent! Find <C-R><C-W><CR>
vnoremap <leader>p/ y:silent Find <C-R>"<CR>
" helpers
" auto-adjust window height to a max of N lines
function! AdjustWindowHeight(minheight, ...)
exe max([min([line("$"), (a:0 >= 1) ? a:1 : a:minheight]), a:minheight]) . "wincmd _"
endfunction
augroup WindowSizing
au!
au FileType qf call AdjustWindowHeight(1, 20)
augroup END
function! s:rg_handler(lines)
if len(a:lines) < 2 | return | endif
let cmd = get({ 'ctrl-x': 'split'
\,'ctrl-v': 'vertical split'
\,'ctrl-t': 'tabe'
\ } , a:lines[0], 'e' )
let list = map(a:lines[1:], 's:ag_to_qf(v:val)')
let first = list[0]
execute cmd escape(first.filename, ' %#\')
execute first.lnum
execute 'normal!' first.col.'|zz'
if len(list) > 1
call setqflist(list)
copen
endif
endfunction
function! s:qf_to_fzf(key, line) abort
let l:filepath = expand('#' . a:line.bufnr . ':p')
return l:filepath . ':' . a:line.lnum . ':' . a:line.col . ':' . a:line.text
endfunction
function! s:fzf_to_qf(filtered_list) abort
let list = map(a:filtered_list, 's:ag_to_qf(v:val)')
if len(list) > 1
call setqflist(list)
copen
wincmd p
endif
endfunction
" ({ 'width': number,
" 'height': number,
" 'message': array<string>,
" 'relative': 'editor' | 'cursor',
" 'anchor': 'NW' | 'NE' | 'SW' | 'SE',
" 'enter': 0 | 1,
" 'centered': boolean }) -> window_id
function! s:fzf_floating_window(opts) abort
let l:buff = nvim_create_buf(v:false, v:true)
let l:message = get(a:opts, 'message', [])
" Window size
" TODO: get the width from the longest line in l:message
let l:width = get(a:opts, 'width', 150)
let l:height = max([get(a:opts, 'height', 1), len(l:message)])
let l:col = get(a:opts, 'col', 1)
let l:row = get(a:opts, 'row', 0)
let l:anchor = get(a:opts, 'anchor', 'SW')
let l:relative = get(a:opts, 'relative', 'cursor')
let l:win_opts = {
\ 'relative': l:relative,
\ 'anchor': l:anchor,
\ 'col': l:col,
\ 'row': l:row,
\ 'width': l:width,
\ 'height': l:height,
\ 'style': 'minimal'
\ }
let l:enter = get(a:opts, 'enter', 0)
if len(l:message) > 0
call nvim_buf_set_lines(l:buff, 0, -1, v:true, l:message)
else
" force the enter option if we're operating on the current buffer
let l:enter = 1
endif
" Window position
if get(a:opts, 'centered', v:false)
let l:win_opts.relative = 'editor'
let l:win_opts.anchor = 'NW'
let l:win_opts.col = (&columns/2) - (l:width/2)
let l:win_opts.row = (&lines/2) - (l:height/2)
endif
" Window id
let l:win_id = nvim_open_win(l:buff, l:enter, l:win_opts)
doautocmd User FloatingWindowEnter
return l:win_id
endfunction
function! s:ag_to_qf(line)
let parts = split(a:line, ':')
return { 'filename': parts[0],
\ 'lnum': parts[1],
\ 'col': parts[2],
\ 'text': join(parts[3:], ':')
\ }
endfunction
" auto-reload
augroup VimConfig
au!
au BufWritePost ~/.config/nvim/init.vim so <afile>
augroup END
" preview replace changes in split window
set inccommand=split
nmap <bs> :<c-u>TmuxNavigateLeft<cr>
"Terminal Mappings
"https://neovim.io/doc/user/nvim_terminal_emulator.html
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
tnoremap <A-l> <C-\><C-n><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
" Conquer of Completion
let g:coc_global_extensions = ['coc-eslint', 'coc-json', 'coc-tsserver']
let g:airline_section_error = '%{airline#util#wrap(airline#extensions#coc#get_error(),0)}'
let g:airline_section_warning = '%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}'
nmap <silent> <M-h> :call CocActionAsync('doHover')<CR>
nmap <silent> <M-d> <Plug>(coc-definition)
nmap <silent> <M-t> <Plug>(coc-type-definition)
nmap <silent> <M-i> <Plug>(coc-implementation)
nmap <silent> <M-f> <Plug>(coc-references)
nmap <silent> <M-r> <Plug>(coc-rename)
nmap <silent> <M-x> :CocCommand<CR>
" Open terminal
nnoremap <leader>ot :bot pedit +terminal<CR><C-W><C-j>A
"NerdTree
map <C-n> :NERDTreeToggle<CR>
"mxw/jsx
" add json syntax highlighting
"au BufNewFile,BufRead *.json set ft=javascript
au BufRead,BufNewFile *.mdx set filetype=markdown
" Whitespace stuff
"set nowrap
set tabstop=8
set shiftwidth=4
set softtabstop=0
set softtabstop=0
set expandtab
set smarttab
"set list listchars=tab:\ ,trail:
" Wordwrap
set wrap
set linebreak
set nolist " list disables linebreak
set textwidth=0
set wrapmargin=0
"Folders
set fdm=marker
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*
" Status bar
set laststatus=2
" " Copy to clipboard
"vnoremap <leader>y "+y
"nnoremap <leader>Y "+yg_
"nnoremap <leader>y "+y
" " Paste from clipboard
"nnoremap <leader>p "+p
"nnoremap <leader>P "+P
"vnoremap <leader>p "+p
"vnoremap <leader>P "+P
" make userreal 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
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
"fzf regular search
set rtp+=~/.fzf
let $FZF_DEFAULT_COMMAND = 'ag -l --nocolor -g "" | grep -v ".*(ico|png|jpe?g|gif|svg|ttf|otf|eot|woff|map|dat)\$"'
nnoremap <silent> <C-p> :FZF<cr>
" [Files] File preview
let g:fzf_files_options = '--preview "highlight -O xterm256 -s moria {} 2> /dev/null; or cat {} | head -'.&lines.'"'
" MRU
"command! FZFMru call fzf#run({
"\ 'source': v:oldfiles,
"\ 'sink': 'e',
"\ 'options': '-m -x +s',
"\ 'down': '40%'})
"nnoremap <silent> <Leader>m :FZFMru<CR>
command! FZFLines call fzf#run({
\ 'source': <sid>buffer_lines(),
\ 'sink': function('<sid>line_handler'),
\ 'options': '--extended --nth=3..',
\ 'down': '60%'
\})
nmap <leader>/ :FZFLines<CR>
" bb opens fzf Buffers
nnoremap <leader>bb :Buffers<CR>
" UndoTree map to F5
nnoremap <F5> :UndotreeToggle<cr>
" Clear selection map to F11
"nnoremap <silent> <F5> :noh<cr>
set pastetoggle=<F6>
"nnoremap <silent> <F6> :set nopaste<cr>
nmap <silent> <F7> :LivedownToggle<CR>
set background=dark
"set background=light
" Default color scheme
"colorscheme solarized
"colorscheme molokayo
colorscheme tender
"Airline
" vim-airline
let g:airline_powerline_fonts = 1
let g:airline_theme="tender"
let g:airline#extensions#tabline#enabled = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" let g:airline_symbols.space = '\ua0'
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
" coc.vim ->
"let g:airline_section_error = '%{airline#util#wrap(airline#extensions#coc#get_error(),0)}'
"let g:airline_section_warning = '%{airline#util#wrap(airline#extensions#coc#get_warning(),0)}'
"let g:airline_section_b = airline#section#create('%{airline#util#wrap(airline#extensions#hunks#get_hunks(),100)} %{airline#util#wrap(airline#extensions#branch#get_head(),120)}')
" search on open buffers
function! s:line_handler(l)
let keys = split(a:l, ':\t')
exec 'buf' keys[0]
exec keys[1]
normal! ^zz
endfunction
function! s:buffer_lines()
let res = []
for b in filter(range(1, bufnr('$')), 'buflisted(v:val)')
call extend(res, map(getbufline(b,0,"$"), 'b . ":\t" . (v:key + 1) . ":\t" . v:val '))
endfor
return res
endfunction
"No ctrl+w while changing split Not working :(
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
"UndoTree
if has("persistent_undo")
set undodir=~/.vim/undodir/
set undofile
endif
"UltiSnips
let g:UltiSnipsExpandTrigger="<c-t>"
let g:UltiSnipsJumpForwardTrigger="<c-f>"
let g:UltiSnipsJumpBackwardTrigger="<c-b>"
" use tab to forward cycle
inoremap <silent><expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
" use tab to backward cycle
inoremap <silent><expr><s-tab> pumvisible() ? "\<c-p>" : "\<s-tab>"
" ALE configs
"let g:ale_fixers = { 'javascript': ['eslint', 'prettier']}
"let g:ale_javascript_eslint_use_global = 1
"let g:ale_javascript_prettier_use_local_config = 1
"let g:ale_fix_on_save = 1
"" ALE helpers
"nnoremap <silent> gH :ALEHover<CR>
"nnoremap <silent> gD :ALEDetail<CR>
"nnoremap <silent> gG :ALEGoToDefinition<CR>
" coc.nvim
" correct comment highlight
autocmd FileType json syntax match Comment +\/\/.\+$+
" Use <Tab> and <S-Tab> to navigate the completion list:
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"<Paste>
" Use <cr> to confirm completion
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" omnifuncs
"augroup omnifuncs
" autocmd!
" autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
" autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
" autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
" autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
" autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
"augroup end
"vim-plug
call plug#begin('~/.config/nvim/plugged')
" Make sure you use single quotes
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
Plug 'junegunn/vim-pseudocl'
Plug 'junegunn/vim-oblique'
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" Group dependencies, vim-snippets depends on ultisnips
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plugin outside ~/.vim/plugged with post-update hook
Plug 'arcticicestudio/nord-vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/gv.vim'
Plug 'junegunn/vim-peekaboo'
Plug 'junegunn/seoul256.vim'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-commentary'
Plug 'rking/ag.vim'
Plug 'kshenoy/vim-signature'
Plug 'othree/html5.vim'
Plug 'othree/es.next.syntax.vim'
Plug 'othree/javascript-libraries-syntax.vim'
Plug 'othree/yajs.vim'
Plug 'mxw/vim-jsx'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'unblevable/quick-scope'
Plug 'mbbill/undotree'
Plug 'airblade/vim-gitgutter'
Plug 'christoomey/vim-tmux-navigator'
Plug 'christoomey/vim-tmux-runner'
Plug 'vim-scripts/Tabmerge'
Plug 'tomasr/molokai'
Plug 'fmoralesc/molokayo'
Plug 'shime/vim-livedown'
Plug 'leafgarland/typescript-vim'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
"Plug 'peitalin/vim-jsx-typescript'
Plug 'jacoborus/tender.vim'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'machakann/vim-highlightedyank'
" Use release branch (recommend)
Plug 'neoclide/coc.nvim', {'branch': 'release'}
function! DoRemote(arg)
UpdateRemotePlugins
endfunction
" Add plugins to &runtimepath
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment