Skip to content

Instantly share code, notes, and snippets.

@cherryramatisdev
Last active December 21, 2023 18:21
Show Gist options
  • Save cherryramatisdev/a0aeb8e6a883f8720c3cd55f2bf0dd02 to your computer and use it in GitHub Desktop.
Save cherryramatisdev/a0aeb8e6a883f8720c3cd55f2bf0dd02 to your computer and use it in GitHub Desktop.
let mapleader = ' '
" Enable filetype detection and plugin functionality
filetype plugin on
" Enable syntax highlighting
syntax on
" Set the tab size to 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
set laststatus=2
set statusline=%f\ %r%y%m%*%h%w%=[%l,%v]\ [%p%%]
set splitbelow
set splitright
set wildmenu
set re=0
" Automatically indent new lines to match the previous line
set autoindent
" set path
set path+=**
" set grep
if executable('rg')
set grepprg=rg\ --vimgrep
endif
" Highlight search results as you type
set incsearch
" Increase redrawtime
" set redrawtime=2000
" Ignore case when searching
set ignorecase
" Enable smart case when searching (ignore case when search pattern contains lowercase letters)
set smartcase
" To facilitate edit in multiple tmux panes
set autoread
set hidden
" Disable swap
set noswapfile
set nobackup
set background=dark
" Stop being annoying with completion
set completeopt=menuone,noinsert
" A hate the pink Pmenu
hi Pmenu ctermbg=darkgray
" Automatically install Vim-Plug if not available
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Configure Vim-Plug
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | Plug 'junegunn/fzf.vim'
Plug 'justinmk/vim-dirvish'
Plug 'conradirwin/vim-bracketed-paste'
Plug 'pbrisbin/vim-mkdir'
Plug 'bogado/file-line'
Plug 'prabirshrestha/vim-lsp'
Plug 'morhetz/gruvbox'
Plug 'tpope/vim-fugitive' | Plug 'tpope/vim-rhubarb' | Plug 'rhysd/committia.vim'
Plug 'elixir-editors/vim-elixir'
call plug#end()
set background=dark
colorscheme gruvbox
let g:markdown_fenced_languages = ["sh=bash", "typescript", "js=javascript", "tsx=typescriptreact"]
if executable('typescript-language-server')
" npm i -g typescript typescript-language-server
au User lsp_setup call lsp#register_server({
\ 'name': 'tsserver',
\ 'cmd': {server_info->['typescript-language-server', '--stdio']},
\ 'allowlist': ['typescript', 'typescriptreact', 'javascript', 'javascriptreact'],
\ })
endif
if executable('rust-analyzer')
" rustup component add rust-analyzer
au User lsp_setup call lsp#register_server({
\ 'name': 'rust-analyzer',
\ 'cmd': {server_info->['rust-analyzer']},
\ 'allowlist': ['rust'],
\ })
endif
if executable(expand('~/.local/share/elixir-ls/language_server.sh'))
" Download release and put into the path: https://github.com/elixir-lsp/elixir-ls/releases/tag/v0.17.10
au User lsp_setup call lsp#register_server({
\ 'name': 'elixirls',
\ 'cmd': {server_info->[expand('~/.local/share/elixir-ls/language_server.sh')]},
\ 'allowlist': ['elixir', 'heex', 'eelixir'],
\ })
endif
let g:lsp_diagnostics_echo_cursor = 0
let g:lsp_document_highlight_enabled = 0
let g:lsp_diagnostics_signs_enabled = 0
let g:lsp_diagnostics_virtual_text_enabled = 0
let g:lsp_completion_documentation_enabled = 0
let g:lsp_signature_help_enabled = 0
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=no
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gR <plug>(lsp-references)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [d <plug>(lsp-previous-diagnostic)
nmap <buffer> ]d <plug>(lsp-next-diagnostic)
nmap <buffer> <leader>q <plug>(lsp-document-diagnostics)
nmap <buffer> ga <plug>(lsp-code-action)
xmap <buffer> ga <plug>(lsp-code-action)
nmap <buffer> K <plug>(lsp-hover)
nmap <buffer> <leader><cr> <plug>(lsp-document-format)
nmap <expr><buffer> <c-d> popup_list()->empty() ? '<c-d>' : lsp#scroll(+4)
nmap <expr><buffer> <c-u> popup_list()->empty() ? '<c-u>' : lsp#scroll(-4)
" let g:lsp_format_sync_timeout = 1000
" autocmd! BufWritePre *.ts,*.tsx call execute('LspDocumentFormatSync')
endfunction
augroup lsp_install
au!
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" Abbrevs:
au FileType typescript,typescriptreact,javascript,javascriptreact iabbrev log@ console.log()<left>
" Bindings:
nnoremap <tab> gt
nnoremap <s-tab> gT
nnoremap <c-p> <cmd>Files<cr>
inoremap <expr> <c-x><c-f> fzf#vim#complete#path('fd')
inoremap <expr> <c-x><c-l> fzf#vim#complete(fzf#wrap({
\ 'prefix': '^.*$',
\ 'source': 'rg -n ^ --color always',
\ 'options': '--ansi --delimiter : --nth 3..',
\ 'reducer': { lines -> join(split(lines[0], ':\zs')[2:], '') }}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment