summaryrefslogtreecommitdiff
path: root/vim/.vimrc
blob: c4568db3585729241e0c2ef4b4531478684d9a1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"TODO: add documentation in the vim folder for this vim config
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
endif
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'rafi/awesome-vim-colorschemes'
Plug 'mattn/emmet-vim'
Plug 'liuchengxu/vim-which-key'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'kamil-stachowski/flatwhite-vim'
Plug 'ap/vim-buftabline'
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-commentary'
Plug 'yegappan/lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'normen/vim-lsp-settings-adapter'
Plug 'kalbasit/vim-colemak'
call plug#end()
let mapleader = "\<Space>"
syntax on 
"filetype
filetype on
filetype indent on
filetype plugin on
"set
set nocompatible
set fileformat=unix
set encoding=UTF-8
set number
set nowrap
set rnu
set expandtab
set tabstop=4
set shiftwidth=4
set smarttab 
set smartindent
set noswapfile
set incsearch
set ignorecase
set smartcase
set autochdir
set hidden
set virtualedit=onemore
set timeoutlen=500
set ttimeoutlen=1
set termguicolors
set laststatus=2
set noshowmode
set undofile
set undodir=~/.vim/undodir
set signcolumn=yes
set shortmess+=c
" etc
colorscheme flatwhite
nnoremap <Space> <Nop>
nnoremap <silent> <leader> :WhichKey '<Space>'<CR>
inoremap <silent> <Esc> <Esc>l
nnoremap <nowait> y w
nnoremap <leader>c "+y
vnoremap <leader>c "+y
autocmd FileType html,css EmmetInstall
"let
let g:VM_maps = {}
let g:buftabline_show = 2
let g:buftabline_numbers = 1
let g:user_emmet_leader_key='<Space>'
let g:user_emmet_mode='n'
let g:user_emmet_install_global = 0
let g:lightline = {
            \ 'colorscheme': 'one',
            \ 'background': 'light',
            \ }
let g:which_key_map = {}
let g:which_key_map.f = ['Files', 'file buffer']
let g:which_key_map.b = {
            \ 'name' : '+buffer',
            \ 'n' : ['bn', 'next buffer'],
            \ 'p' : ['bp', 'previous buffer'],
            \ 'b' : ['Buffers', 'fuzzy find buffers'],
            \ }
call which_key#register('<Space>', 'g:which_key_map')
" lsp
autocmd User LspSetup call LspOptionsSet(#{
      \ autoComplete: v:true,
      \ autoHighlightDiags: v:true,
      \ })

" one list instead of N copy-pasted if-executable/augroup blocks
autocmd User LspSetup call LspAddServer([
      \ #{name: 'pylsp',  filetype: 'python',  path: 'pylsp'},
      \ #{name: 'clangd', filetype: ['c', 'cpp', 'objc', 'objcpp'],
      \   path: 'clangd', args: ['--background-index']},
      \ #{name: 'html', filetype: 'html',
      \   path: 'vscode-html-language-server', args: ['--stdio']},
      \ #{name: 'css', filetype: ['css', 'scss', 'less'],
      \   path: 'vscode-css-language-server', args: ['--stdio']},
      \ #{name: 'ts', filetype: ['javascript', 'javascript.jsx', 'javascriptreact'],
      \   path: 'typescript-language-server', args: ['--stdio']},
      \ ])

" keymaps: explicit :Lsp* commands mapped by hand, buffer-local, same idea as
" your old on_lsp_buffer_enabled() but no separate function/augroup needed —
" this fires once per attached buffer via the plugin's own event
autocmd User LspAttached call s:lsp_keymaps()
function! s:lsp_keymaps() abort
    nmap <buffer> gs  :LspDocumentSymbol<CR>
    nmap <buffer> gr  :LspShowReferences<CR>
    nmap <buffer> gi  :LspGotoImpl<CR>
    nmap <buffer> gt  :LspGotoTypeDef<CR>
    nmap <buffer> <leader>rn :LspRename<CR>
    nmap <buffer> [g  :LspDiagPrev<CR>
    nmap <buffer> ]g  :LspDiagNext<CR>
    nmap <buffer> K   :LspHover<CR>
if index(['python', 'c', 'cpp', 'objc', 'objcpp',
        \ 'javascript', 'javascript.jsx', 'javascriptreact'], &filetype) >= 0
    autocmd BufWritePre <buffer> LspFormat
endif
endfunction
function! s:prettier_format() abort
    if !executable('prettier')
        return
    endif
    let l:view = winsaveview()
    silent %!prettier --stdin-filepath % --html-whitespace-sensitivity=scrict  
    if v:shell_error
        silent undo
        echohl ErrorMsg | echom 'formatting failed'
    endif
    call winrestview(l:view)
endfunction
augroup prettierformat
    au!
    autocmd BufWritePre *.html,*.css call s:prettier_format()
augroup END