-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
284 lines (238 loc) · 6.64 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
" If there is a master.vimrc file, load it
try
source $LOCAL_ADMIN_SCRIPTS/master.vimrc
catch
" No such file? No problem; just ignore it.
endtry
" #########################
" vim-plug
" #########################
call plug#begin('~/.vim/plugged')
" Nvim-R
Plug 'jalvesaq/Nvim-R'
Plug 'jalvesaq/cmp-nvim-r'
" nvim-cmp
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'onsails/lspkind.nvim'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" vim-airline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" gruvbox
Plug 'morhetz/gruvbox'
" commentary
Plug 'tpope/vim-commentary'
" surround
Plug 'tpope/vim-surround'
" languageserver
" Plug 'REditorSupport/languageserver'
" Plug 'autozimu/LanguageClient-neovim', {
" \ 'branch': 'next',
" \ 'do': 'bash install.sh',
" \ }
" bufferliine
Plug 'nvim-tree/nvim-web-devicons' " Recommended (for coloured icons)
Plug 'akinsho/bufferline.nvim', { 'tag': '*' }
" Tabular
Plug 'godlygeek/tabular'
" Git integration
Plug 'tpope/vim-fugitive'
call plug#end()
" #########################
" vim-airline
" #########################
" air-line
let g:airline_powerline_fonts = 1
let g:airline_theme='bubblegum'
" #########################
" Aesthetics
" #########################
colorscheme gruvbox
" gruvbox dark theme
set background=dark
set termguicolors
let g:gruvbox_contrast_dark = 'hard'
set t_Co=256
syntax enable
hi clear SpellBad
hi SpellBad cterm=underline,bold
" show line number
set number
" highlight the 80th column
set colorcolumn=80
" highlight search matches
set incsearch
" formatoptions to disable auto comment headers
au FileType * set fo-=c fo-=r fo-=o
" hidden to allow multiple unsaved buffers
set hidden
" backspace to allow using backspace button
set backspace=indent,eol,start
" #########################
" Mappings
" #########################
" mapping settings
let mapleader=","
let maplocalleader=";"
" remap comma key to back slash
nmap \ ,
" map jk to ESC in insert mode
imap jk <esc>
tmap jk <esc>
" Copy into the end of line
nmap Y y$
" Copy until the end of line into system clipboard
nmap <C-Y> "+y$
" Copy an entire line and paste before the current line
nmap _ ggY``P
" Copy to clipboard
vmap <C-c> "+y
" Map ctrl+Del to delete until the end of line in insert mode
imap <C-Del> <C-\><C-O>D
" Keep the visual block intact after indenting
vmap > >gv
vmap < <gv
" split pane settings
set splitbelow
set splitright
nmap <C-J> <C-W><C-J>
nmap <C-K> <C-W><C-K>
nmap <C-L> <C-W><C-L>
nmap <C-H> <C-W><C-H>
" invisible character mapping
nmap <leader>l :set list!<CR>
set listchars=tab:▸\ ,eol:¬
" edit mappings
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" #########################
" Tab/indentation
" #########################
" how many columns a tab counts for
set tabstop=2
" tab inserts spaces
set expandtab
" how many columns when Tab in insert mode
set softtabstop=2
" how many columns text is indented
set shiftwidth=2
" #########################
" Tab completion
" #########################
" enable a menu at the bottom
set wildmenu
" first tab = command will be completed to the longest common command
" second tab = show all completion matches
set wildmode=longest,list,full
" #########################
" nvim-r
" #########################
autocmd BufNewFile *.R 0r ~/.vim/skeletons/r-blank.R
" Execute command when a .R file is written
autocmd BufWritePre *.R,*.r,*.qmd,*.rmd,*.Qmd,*.Rmd :%s/%>%/|>/ge | write
let R_assign = 0
let R_quarto_preview_args = ', port = 8081, watch = FALSE'
nmap <silent> <LocalLeader>cn :call RAction("colnames")<CR>
nmap <silent> <LocalLeader>tl :call RAction("tally")<CR>
nmap <silent> <LocalLeader>sq :call RAction("show_query")<CR>
nmap <silent> <LocalLeader>do :call RAction("debugonce")<CR>
nmap <silent> <LocalLeader>ph :call RAction("print", ", n = 100")<CR>
vmap <Space> <Plug>RDSendSelection
nmap <Space> <Plug>RDSendLine
function! SendInvisibleV()
let Rsource = g:rplugin_tmpdir . "/Rsource-" . getpid()
call writefile(["invisible("] + getline("'<", "'>") + [")"], Rsource)
call g:SendCmdToR('source("' . Rsource . '")')
call cursor(line("'>"), 0)
call GoDown()
endfunction
vmap <silent> <LocalLeader>ri <Esc>:call SendInvisibleV()<CR>
lua <<EOF
local ok, lspkind = pcall(require, "lspkind")
if not ok then
return
end
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "vsnip" },
}, {
{ name = "path" },
{ name = "buffer", keyword_length = 5 },
}, {
{ name = 'cmp_nvim_r' },
}),
formatting = {
format = lspkind.cmp_format {
with_text = true,
menu = {
buffer = "[buf]",
nvim_lsp = "[LSP]",
path = "[path]",
vsnip = "[snip]",
cmp_nvim_r = "[NvimR]",
},
},
},
}
require("bufferline").setup{}
EOF
" #########################
" stripping trailing whitespaces
" #########################
function! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap <silent> <F5> :call <SID>StripTrailingWhitespaces()<CR>
" #########################
" others
" #########################
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "100 : will save up to 100 lines for each register
" :20 : up to 20 lines of command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
if !has('nvim')
set viminfo='10,\"100,:20,%,n~/.viminfo
endif
" Restore cursor position
:au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif
" #########################
" languageserver
" #########################
" let g:LanguageClient_serverCommands = {
" \ 'r': ['R', '--slave', '-e', 'languageserver::run()'],
" \ }