-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy path.vimrc
218 lines (170 loc) · 6.19 KB
/
.vimrc
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
set nocompatible " be iMproved, required
filetype off " required
" Keep Plug commands between plug#begin() and plug#end().
call plug#begin()
Plug 'janko/vim-test' " Run Ruby and Elixir tests
Plug 'nikolalsvk/vim-rails' " Rails plugin
Plug 'airblade/vim-gitgutter' " Show git diff of lines edited
Plug 'tpope/vim-fugitive' " :Gblame
Plug 'tpope/vim-rhubarb' " :GBrowse
Plug 'tpope/vim-endwise' " Autocomplete end after a do
Plug 'mileszs/ack.vim' " Use ack in Vim
Plug 'pangloss/vim-javascript' " JavaScript support
Plug 'leafgarland/typescript-vim' " TypeScript syntax
Plug 'maxmellon/vim-jsx-pretty' " JS and JSX syntax
Plug 'jparise/vim-graphql' " GraphQL syntax
Plug 'styled-components/vim-styled-components'
Plug 'vim-airline/vim-airline' " Vim powerline
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim' " Set up fzf and fzf.vim
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
Plug 'psliwka/vim-smoothie' " Smooth scrolling
" All of your Plugins must be added before the following line
call plug#end() " required
filetype plugin indent on " required
" Leader key is SPACE, I find it the best
let mapleader = " "
" Look and Feel settings
syntax enable
set background=dark
set wildmenu " when opening a file with e.g. :e ~/.vim<TAB> there is a graphical menu of all the matches
set ttyfast
set lazyredraw
set updatetime=300
set hidden " Open other files if current one is not saved
" Enable Mouse mode in all modes
set mouse=a
" Numbers
set number
set numberwidth=4
set ruler
" paste mode
nnoremap <F5> :set invpaste paste?<CR>
set pastetoggle=<F5>
set showmode
" Treat long lines as break lines
map j gj
map k gk
" Indentation
set autoindent
set cindent
set smartindent
" Folding
" Enable folding
set foldmethod=syntax
set foldlevel=99
" Enable folding with the z key
nmap z za
" Disable all bells and whistles
set noerrorbells visualbell t_vb=
" Ack tricks
let g:ackprg = 'rg --vimgrep --smart-case --hidden'
" Any empty ack search will search for the work the cursor is on
let g:ack_use_cword_for_empty_search = 1
nmap <leader>a :Ack!<Space>
nmap <leader>A :Ack! <cword><CR>
" Tab Options
set shiftwidth=2
set tabstop=2
set softtabstop=2 " Number of spaces a tab counts when editing
set expandtab
" Delete empty space from the end of lines on every save
autocmd BufWritePre * :%s/\s\+$//e
" Set default encoding to utf-8
set encoding=utf-8
set termencoding=utf-8
" Disable backups and swap files
set nobackup
set nowritebackup
set noswapfile
set ignorecase " Ignore case when searching
set smartcase " When searching try to be smart about cases
set nohlsearch " Don't highlight search term
set incsearch " Jumping search
" Always show the status line
set laststatus=2
" Allow copy and paste from system clipboard
set clipboard=unnamed
" Spellcheck for features and markdown
au BufRead,BufNewFile *.md setlocal spell
au BufRead,BufNewFile *.md.erb setlocal spell
au BufRead,BufNewFile *.feature setlocal spell
" Delete characters outside of insert area
set backspace=indent,eol,start
" +++ Shortcuts +++
" Open Buffer
nnoremap <silent><leader>l :Buffers<CR>
" Open test file for a current file
nnoremap <silent><leader>s :A<CR>
" Open test file for a current file in a vertical window
nnoremap <silent><leader>v :AV<CR>
" Vertically split screen
nnoremap <silent><leader>\ :vs<CR>
" Split screen
nnoremap <silent><leader>/ :split<CR>
" Faster saving and exiting
nnoremap <silent><leader>w :w!<CR>
nnoremap <silent><leader>q :q!<CR>
nnoremap <silent><leader>x :x<CR>
" Open Vim configuration file for editing
nnoremap <silent><leader>2 :e ~/.vimrc<CR>
" Source Vim configuration file and install plugins
nnoremap <silent><leader>1 :source ~/.vimrc \| :PlugInstall<CR>
" Toggle relative line numbers
nnoremap <leader>rn :set relativenumber!<cr>
" If fzf installed using git
set rtp+=~/.fzf
" Map fzf search to CTRL P
nnoremap <C-p> :GFiles<Cr>
" Map fzf + ag search to CTRL P
nnoremap <C-g> :Rg <Cr>
" vim-test shortcut for running tests
nnoremap <silent><leader>; :TestNearest<CR>
nnoremap <silent><leader>' :TestFile<CR>
" Extra <CR> is for disabling /"Press ENTER or type command to continue/"
nnoremap <silent><leader>e :Exp<CR><CR>
" Easier movement between split windows CTRL + {h, j, k, l}
nnoremap <c-h> <c-w>h
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-l> <c-w>l
" CoC extensions
let g:coc_global_extensions = ['coc-solargraph', 'coc-tsserver', 'coc-json']
" Add CoC Prettier if prettier is installed
if isdirectory('./node_modules') && isdirectory('./node_modules/prettier')
let g:coc_global_extensions += ['coc-prettier']
endif
" Add CoC ESLint if ESLint is installed
if isdirectory('./node_modules') && isdirectory('./node_modules/eslint')
let g:coc_global_extensions += ['coc-eslint']
endif
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>c <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Format
nmap <leader>f :CocCommand prettier.formatFile<CR>
" Fix some weird error with Fugitive
let g:fugitive_pty = 0
" Change cursor to solid vertical line
" There are problems with Vim's floating window setting cursor to a solid
" block. So these lines below are resetting it to a solid vertical line.
let &t_SI = "\e[6 q"
let &t_EI = "\e[6 q"
" Optionally reset the cursor on start:
augroup myCmds
au!
autocmd VimEnter * silent !echo -ne "\e[6 q"
augroup END
" Fix syntax highlight for Coc plugin floating errors
hi CocErrorFloat guifg=Magenta guibg=Magenta
" Use templates https://vimtricks.com/p/automated-file-templates/
autocmd BufNewFile *.test.tsx 0r ~/Documents/dotfiles/skeletons/react-typescript.test.tsx
autocmd BufNewFile *\(test\)\@<!.tsx 0r ~/Documents/dotfiles/skeletons/react-typescript.tsx
autocmd BufNewFile *content/blog*.md 0r ~/Documents/dotfiles/skeletons/blog-post.md
autocmd BufNewFile *.sh 0r ~/Documents/dotfiles/skeletons/script.sh
autocmd BufNewFile *.html 0r ~/Documents/dotfiles/skeletons/page.html