Skip to content

Instantly share code, notes, and snippets.

@d1che
Last active September 7, 2022 15:38
Show Gist options
  • Save d1che/290ca48ff43876700231a1079388dd1b to your computer and use it in GitHub Desktop.
Save d1che/290ca48ff43876700231a1079388dd1b to your computer and use it in GitHub Desktop.
Neovim config
" To do
" - Configure feline
" - Configure LSP starting from scratch
" - Learn tmux
call plug#begin('~/.vim/plugged')
" initialize plugin system
call plug#end()
" ===============
" GENERAL OPTIONS
" ===============
set number
set tabstop=2
set shiftwidth=2 " always uses spaces instead of tab characters
set expandtab
set updatetime=500
set shortmess+=c " don't give |ins-completion-menu| messages.
set signcolumn=yes " always show signcolumns
set mouse=a " enable mouse in all modes
" ===========
" KEY MAPPING
" ===========
inoremap jk <ESC> " non-recurively cancel insert mode with jk
nnoremap <C-n> :NERDTreeToggle<CR>
vnoremap ++ <plug>NERDCommenterToggle " these use a key binding in iTerm2
nnoremap ++ <plug>NERDCommenterToggle " these use a key binding in iTerm2
" moving line(s) up or down
nnoremap m :m -2<CR> " move line up
nnoremap n :m +1<CR> " move line down
xnoremap m :m-2<CR>gv=gv " move selected lines up one line
xnoremap n :m'>+<CR>gv=gv " move selected lines down one line
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
" =============
" AUTO COMMANDS
" =============
" open NERDTree automatically
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree
" highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()
" push this config file to github gist when saving it
autocmd BufWritePost * if expand('%:t') == "init.vim" | call GitPushConfig() | endif
" ====================
" PLUGIN CONFIGURATION
" ====================
colorscheme tokyonight
" call feline initialization in lua
lua << EOF
require('feline').setup()
EOF
" configure language servers
lua << EOF
require('lspconfig').tsserver.setup {}
EOF
let g:NERDTreeGitStatusWithFlags = 1
"let g:WebDevIconsUnicodeDecorateFolderNodes = 1
"let g:NERDTreeGitStatusNodeColorization = 1
"let g:NERDTreeColorMapCustom = {
"\ "Staged" : "#0ee375",
"\ "Modified" : "#d9bf91",
"\ "Renamed" : "#51C9FC",
"\ "Untracked" : "#FCE77C",
"\ "Unmerged" : "#FC51E6",
"\ "Dirty" : "#FFBD61",
"\ "Clean" : "#87939A",
"\ "Ignored" : "#808080"
"\ }
" let g:NERDTreeIgnore = ['^node_modules$']
" =========
" FUNCTIONS
" =========
" sync open file with NERDTree
" check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" this function should only be called when this config file is saved!
function! GitPushConfig()
let l:path = expand('%:p:h')
let l:d = strftime("%d-%m-%y_%T")
silent execute "!cd " . l:path . " && git add init.vim && git commit -am ". l:d ." && git push &"
endfunction
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment