Skip to content

Instantly share code, notes, and snippets.

@lukasjoc
Created August 4, 2021 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukasjoc/25b22ddb670c7eb64ed7c8d477df1191 to your computer and use it in GitHub Desktop.
Save lukasjoc/25b22ddb670c7eb64ed7c8d477df1191 to your computer and use it in GitHub Desktop.
Set Commenting and FileTypes
if has('autocmd')
" Commenting
augroup comment
au FileType c,cpp,rust,javascript,java,pde,scala,go,php,v,sv,proto let b:comment_leader = "// "
au FileType sh,yml,yaml,bash,python,pyx,nim let b:comment_leader = "# "
au FileType vim let b:comment_leader = '" '
au FileType tex let b:comment_leader = "% "
au FileType sql let b:comment_leader = "-- "
augroup END
noremap <silent> ,cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,"\/")<CR>/<CR>:nohlsearch<CR>
noremap <silent> ,xx :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,"\/")<CR>//e<CR>:nohlsearch<CR>
" Setting specific filetypes
augroup filetypes
au BufRead,BufNewFile *.v,*.sv set filetype=verilog
au BufRead,BufNewFile *.js,*.ts,*.vue set filetype=javascript
au BufRead,BufNewFile *.pde set filetype=java
au BufRead,BufNewFile *.plist set filetype=xml
augroup END
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment