Add vim snippets for many languages
This commit is contained in:
parent
391e61f9ea
commit
fd0fd90fe0
|
@ -8,9 +8,12 @@ set smartindent
|
|||
set nocp
|
||||
set bo=all
|
||||
colorscheme torte
|
||||
set ts=8
|
||||
set list
|
||||
set listchars=tab:*·,lead:·,trail:~,extends:>,precedes:<
|
||||
set noet
|
||||
set ts=8
|
||||
set sw=8
|
||||
filetype indent off
|
||||
hi Whitespace ctermfg=233
|
||||
hi SignColumn ctermbg=233
|
||||
|
||||
|
@ -32,18 +35,149 @@ vnoremap <leader>" <esc>a"<esc>`<i"<esc>`>
|
|||
nnoremap H 0
|
||||
nnoremap L $
|
||||
|
||||
" Used in abbrevs to remove a space
|
||||
" append: <c-r>=Eatchar('\s')<cr>
|
||||
func Eatchar(pat)
|
||||
let c = nr2char(getchar(0))
|
||||
return (c =~ a:pat) ? '' : c
|
||||
endfunc
|
||||
|
||||
augroup html
|
||||
autocmd!
|
||||
autocmd FileType html inoremap <buffer> > ><esc>F<"tyef>"tpa><esc>T<i/<c-o>T>
|
||||
autocmd FileType html inoremap <buffer> = =""<left>
|
||||
autocmd FileType html inoremap <buffer> \= =
|
||||
autocmd FileType html inoremap <buffer> \> >
|
||||
autocmd FileType html iabbrev <buffer> <! <!DOCTYPE html><c-o>df>
|
||||
autocmd FileType html iabbrev <buffer> <! <!DOCTYPE html><c-o>df><cr><html><cr><cr><up><head><cr><c-o>o<body><cr><c-o>2k<c-o>O<meta charset=utf-8<c-o>A><c-o>df><cr><title><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType html nnoremap <buffer> <localleader>f Vatzf
|
||||
autocmd FileType html vnoremap <buffer> H "tdh?><CR>"tpvT>
|
||||
autocmd FileType html vnoremap <buffer> L "td/<<CR>"tPg;vt<
|
||||
augroup END
|
||||
|
||||
augroup javascript
|
||||
autocmd!
|
||||
autocmd FileType javascript inoremap <buffer> '. ><esc>F<"tyef>"tpa><esc>T<i/<c-o>T>
|
||||
autocmd FileType javascript nnoremap <buffer> <localleader>f Vatzf
|
||||
autocmd FileType javascript vnoremap <buffer> H "tdh?><CR>"tpvT>
|
||||
autocmd FileType javascript vnoremap <buffer> L "td/<<CR>"tPg;vt<
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> log console.log("")<left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> for for(let i = 0; i < ; i++) {<cr>}<up><c-o>f;<c-o>;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> while while() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> if if() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> fn function () {<cr>}<up><c-o>f(<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> ret return<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType javascript iabbrev <silent> <buffer> let let = <left><left><left><c-r>=Eatchar('\s')<cr>
|
||||
augroup javascript
|
||||
|
||||
augroup python
|
||||
autocmd!
|
||||
autocmd FileType python iabbrev <silent> <buffer> for for x in :<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> while while :<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> if if :<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> elif elif :<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> def def ():<left><left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> met def (self):<c-o>F(<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> class class :<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> ret return<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python iabbrev <silent> <buffer> #! #!/bin/python3<cr><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType python set noet
|
||||
autocmd FileType python set ts=8
|
||||
autocmd FileType python set sw=8
|
||||
augroup END
|
||||
|
||||
augroup rust
|
||||
autocmd!
|
||||
autocmd FileType rust set noet
|
||||
autocmd FileType rust set ts=8
|
||||
autocmd FileType rust set sw=8
|
||||
autocmd FileType rust iabbrev <silent> <buffer> for for x in {<cr>}<up><c-o>f{<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> impl impl x for x {<cr>}<up><c-o>fx<delete><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> struct struct {<cr>}<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> match match {<cr>}<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> der #[derive ()]<left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> fn fn () {<cr>}<up><c-o>f(<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> let let = ;<c-o>F=<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> use use ;<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> type type = ;<c-o>F=<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> if if {<cr>}<up><c-o>f{<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> ret return
|
||||
autocmd FileType rust iabbrev <silent> <buffer> log@ println!("");<left><left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType rust iabbrev <silent> <buffer> main@ fn main() {<cr>}<c-o>O<c-r>=Eatchar('\s')<cr>
|
||||
augroup END
|
||||
|
||||
augroup c
|
||||
autocmd!
|
||||
autocmd FileType c iabbrev <silent> <buffer> main@ int main(int argc, char* argv[]) {<cr><cr><cr>return 0;<cr>}<up><up><up><tab><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> printf printf("");<left><left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> log@ fprintf(stderr, "");<left><left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> for for(int i = 0; i < ; i++) {<cr>}<up><c-o>f;<c-o>;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> if if() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> while while() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> struct struct {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> enum enum {<cr>}<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> fn@ void () {<cr>}<up><c-o>f(<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> ret return ;<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> retv return;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> incl #include <<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType c iabbrev <silent> <buffer> def #define <c-r>=Eatchar('\s')<cr>
|
||||
augroup END
|
||||
|
||||
augroup cpp
|
||||
autocmd!
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> main@ using namespace std;<cr><cr>int main(int argc, char* argv[]) {<cr><cr><cr>return 0;<cr>}<up><up><up><tab><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> cerr cerr << "" << endl;<c-o>F"<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> cout cout << "" << endl;<c-o>F"<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> for for(int i = 0; i < ; i++) {<cr>}<up><c-o>f;<c-o>;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> if if() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> while while() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> struct struct {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> class class {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> pub public:<cr><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> priv private:<cr><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> enum enum {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> fn@ void () {<cr>}<up><c-o>f(<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> templ template <typename T><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> ret return ;<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> retv return;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> incl #include <<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cpp iabbrev <silent> <buffer> def #define <c-r>=Eatchar('\s')<cr>
|
||||
augroup END
|
||||
|
||||
augroup cs
|
||||
autocmd!
|
||||
autocmd FileType cs iabbrev <silent> <buffer> main@ using System;<cr><cr>class Program {<cr>static void Main(string[] args) {<cr>}<cr>}<up><c-o>O<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> log@ Console.WriteLine("");<left><left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> for for(int i = 0; i < ; i++) {<cr>}<up><c-o>f;<c-o>;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> if if() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> while while() {<cr>}<up><c-o>f)<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> struct struct {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> class class {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> pub public
|
||||
autocmd FileType cs iabbrev <silent> <buffer> priv private
|
||||
autocmd FileType cs iabbrev <silent> <buffer> enum enum {<cr>};<up><c-o>f<space><space><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> fn@ void () {<cr>}<up><c-o>f(<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> ret return ;<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType cs iabbrev <silent> <buffer> retv return;<c-r>=Eatchar('\s')<cr>
|
||||
augroup END
|
||||
|
||||
augroup sh
|
||||
autocmd FileType sh iabbrev <silent> <buffer> #! #!/bin/sh<cr>set -e<cr><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType sh iabbrev <silent> <buffer> if if [ ]; then<cr>fi<up><c-o>f]<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType sh iabbrev <silent> <buffer> elif elif [ ]; then<c-o>F]<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType sh iabbrev <silent> <buffer> for for x in ; do<cr>done<up><c-o>f;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType sh iabbrev <silent> <buffer> while while ; do<cr>done<up><c-o>f;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType sh iabbrev <silent> <buffer> fn@ () {<cr>}<up><c-o>0<c-r>=Eatchar('\s')<cr>
|
||||
augroup END
|
||||
|
||||
augroup bash
|
||||
autocmd FileType bash iabbrev <silent> <buffer> while while ; do<cr>done<up><c-o>f;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType bash iabbrev <silent> <buffer> for for x in ; do<cr>done<up><c-o>f;<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType bash iabbrev <silent> <buffer> fn@ () {<cr>}<up><c-o>0<c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType bash iabbrev <silent> <buffer> if if [[ ]]; then<cr>fi<up><c-o>f]<left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType bash iabbrev <silent> <buffer> elif elif [[ ]]; then<c-o>F]<left><left><c-r>=Eatchar('\s')<cr>
|
||||
autocmd FileType bash iabbrev <silent> <buffer> #! #!/bin/bash<cr>set -e<cr><c-r>=Eatchar('\s')<cr>
|
||||
augroup END
|
||||
|
||||
call plug#begin('~/.config/nvim/plugged')
|
||||
|
||||
Plug 'vim-airline/vim-airline'
|
||||
|
@ -63,10 +197,6 @@ call plug#end()
|
|||
|
||||
nnoremap <C-n> :silent NERDTreeToggle<CR>
|
||||
|
||||
augroup nerdtree_start
|
||||
autocmd FileType c silent if !exists('b:NERDTree') | silent NERDTree | au! nerdtree_start | endif
|
||||
augroup END
|
||||
|
||||
augroup nerdtree
|
||||
" Exit Vim if NERDTree is the only window remaining in the only tab.
|
||||
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
|
||||
|
@ -121,7 +251,7 @@ end
|
|||
|
||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
||||
-- map buffer local keybindings when the language server attaches
|
||||
local servers = { 'pyright', 'clangd' }
|
||||
local servers = { 'pyright', 'clangd', 'rls', 'tsserver' }
|
||||
for _, lsp in ipairs(servers) do
|
||||
nvim_lsp[lsp].setup {
|
||||
on_attach = on_attach,
|
||||
|
@ -130,6 +260,34 @@ for _, lsp in ipairs(servers) do
|
|||
}
|
||||
}
|
||||
end
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
|
||||
local html = nvim_lsp.html
|
||||
local css = nvim_lsp.html
|
||||
html.setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
cmd = { "vscode-html-languageserver", "--stdio" },
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
settings = {
|
||||
html = {
|
||||
validate = true
|
||||
}
|
||||
}
|
||||
}
|
||||
css.setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
cmd = { "vscode-css-languageserver", "--stdio" },
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
}
|
||||
|
||||
EOF
|
||||
|
||||
" auto close scratch buffer (preview window)
|
||||
|
|
Loading…
Reference in New Issue