-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
355 lines (300 loc) · 10.5 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
" An example for a vimrc file.
"
" Author: from Bram Moolenaar and modified by Thomas Girke
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
if $DISPLAY != ""
let R_openpdf = 1
endif
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set t_Co=256
"set autoindent " always set autoindenting on
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set showcmd " display incomplete commands
set incsearch " do incremental searching
set nowrap " turns off text wrapping
set nospell " turns on spell check for all files
autocmd BufNewFile,BufRead NEWS,NEWS.md,README.md set spell "turns on spell check only for specified files
set paste " turns on traditional pasting of text
set number " turns line numbering on
set ruler " show the cursor position all the time
colorscheme default " sets color scheme
" colorscheme jellybeans " sets color scheme
set laststatus=2
" default (black bkgr), torte (black bgr), murphy (black bkgr),
" elflord (black bkgr), blue (blue bkgr), morning (white bkgr), shine (white bkgr)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" sample settings for vim-r-plugin and screen.vim
" Installation
" - Place plugin file under ~/.vim/
" - To activate help, type in vim :helptags ~/.vim/doc
" - Place the following vim conf lines in .vimrc
" Usage
" - Read intro/help in vim with :h vim-r-plugin or :h screen.txt
" - To initialize vim/R session, start screen/tmux, open some *.R file in vim and then hit F2 key
" - Object/omni completion command CTRL-X CTRL-O
" - To update object list for omni completion, run :RUpdateObjList
" My favorite Vim/R window arrangement
" tmux attach
" Open *.R file in Vim and hit F2 to open R
" Go to R pane and create another pane with C-a %
" Open second R session in new pane
" Go to vim pane and open a new viewport with :split *.R
" Useful tmux commands
" tmux new -s <myname> start new session with a specific name
" tmux ls (C-a-s) list tmux session
" tmux attach -t <id> attach to specific session
" tmux kill-session -t <id> kill specific session
" C-a-: kill-session kill a session
" C-a % split pane vertically
" C-a " split pane horizontally
" C-a-o jump cursor to next pane
" C-a C-o swap panes
" C-a-: resize-pane -L 10 resizes pane by 10 to left (L R U D)
" Corresponding Vim commands
" :split or :vsplit split viewport
" C-w-w jump cursor to next pane-
" C-w-r swap viewports
" C-w C-++ resize viewports to equal split
" C-w 10+ increase size of current pane by value
" To open R in terminal rather than RGui (only necessary on OS X)
" let vimrplugin_applescript = 0
" let vimrplugin_screenplugin = 0
let usrhome = $HOME
" For tmux support
" let R_external_term = 1
" let R_term_cmd = 'tilix -a session-add-right -e'
" let R_tmux_title = 'Nvim-R'
let R_nvimpager = "tabnew"
let R_rconsole_width = 80
let R_min_editor_width = 18
let R_external_term = 0
let R_esc_term = 1
let R_cmdchunk = 1
let g:ScreenShellInitialFocus = 'shell'
let g:netrw_liststyle=3 " For nerdtree style explorer
" instruct to use your own .screenrc file
let g:vimrplugin_noscreenrc = 1
" For integration of r-plugin with screen.vim
let g:vimrplugin_screenplugin = 1
" Don't use conque shell if installed
let vimrplugin_conqueplugin = 0
" map the letter 'r' to send visually selected lines to R
let g:vimrplugin_map_r = 1
" see R documentation in a Vim buffer
let vimrplugin_vimpager = "no"
set expandtab
set shiftwidth=4
set tabstop=4
set softtabstop=4
" allow mouse in all modes
set mouse=a
if &term =~ '^screen'
" tmux knows the extended mouse mode
set ttymouse=xterm2
endif
" start R with F2 key
map <F2> <Plug>RStart
imap <F2> <Plug>RStart
vmap <F2> <Plug>RStart
" send selection to R with space bar
vmap <Space> <Plug>RDSendSelection
" send line to R with space bar
nmap <Space> <Plug>RDSendLine
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set folding scheme; more on this see:
" http://www.dgp.toronto.edu/~mjmcguff/learn/vim/folding.txt
" http://vim.dindinx.net/orig/usr_28.txt
" set foldcolumn=0 " if set to > 1 together with 'set number',
" then the copy&paste of screen will include the line numbers
" highlight Folded ctermfg=yellow ctermbg=blue
" highlight works only when colorscheme is uncommented
" set foldmethod=indent
" hi FoldColumn ctermbg=NONE
" For Latex work: open *.pdf files in evince/xpdf upon opening of *.tex files in vim
" more on this on this page: http://ubuntuforums.org/showthread.php?p=5351607
au BufRead *.tex silent !xpdf %<.pdf 2>/dev/null &
au BufRead *.Rnw silent !xpdf %<.pdf 2>/dev/null &
" Don't use Ex mode, use Q for formatting
map Q gq
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣
set hlsearch
endif
" Syntax highlighting based on <set listchars>
" set list
" set nolist
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif " has("autocmd")
" Sort function from Gerald Lai at http://www.vim.org/tips/tip.php?tip_id=923 (use last
" script on page, not first!!!!!).
" paste in vimrc file - tested with GVim 6.3
"** use visual block <Ctrl-V> to select lines to sort and hit <F3> **
vmap <F3> :call Sort(Prompt("0","1"),Prompt("1","f"),"Strcmp")<CR>
"sort lines function
function Sort(wnum, order, cmp) range
normal `<
execute "let startcol = col(\".\")"
normal `>
execute "let endcol = col(\".\")"
if startcol <= endcol
let firstcol = startcol
let lastcol = endcol
else
let firstcol = endcol
let lastcol = startcol
endif
call SortR(a:firstline, a:lastline, firstcol, lastcol, a:wnum, a:order, a:cmp)
normal gv
endfunction
"sort lines recursively
function SortR(start, end, first, last, wnum, order, cmp)
if a:start >= a:end
return
endif
let partition = a:start - 1
let middle = partition
let partstr2 = Words2(getline((a:start + a:end) / 2), a:first, a:last, a:wnum)
let i = a:start
while i <= a:end
let str = getline(i)
let partstr = Words2(str, a:first, a:last, a:wnum)
if a:order == "r"
execute "let result = ".a:cmp."(partstr2, partstr)"
else
execute "let result = ".a:cmp."(partstr, partstr2)"
endif
if result <= 0
"swap i before partition
let partition = partition + 1
if result == 0
let middle = partition
endif
if i != partition
let str2 = getline(partition)
call setline(i, str2)
call setline(partition, str)
endif
endif
let i = i + 1
endwhile
"make sure middle element at end of partition
if middle != partition
let str = getline(middle)
let str2 = getline(partition)
call setline(middle, str2)
call setline(partition, str)
endif
call SortR(a:start, partition - 1, a:first, a:last, a:wnum, a:order, a:cmp)
call SortR(partition + 1, a:end, a:first, a:last, a:wnum, a:order, a:cmp)
endfunction
"determine compare strings
function Words2(line, first, last, wnum)
if a:wnum == "v"
return strpart(a:line, a:first - 1, a:last - a:first + 1)
elseif a:wnum > 1
return strpart(a:line, matchend(a:line, "\\s*\\(\\S*\\s*\\)\\{".(a:wnum - 1)."}"))
elseif a:wnum == 1
return strpart(a:line, matchend(a:line, "\\s*"))
elseif a:wnum < 0
return matchstr(a:line, "\\(\\S*\\s*\\)\\{".(-a:wnum)."}$")
else
return a:line
endif
endfunction
"compare two strings
function Strcmp(str1, str2)
if a:str1 < a:str2
return -1
elseif a:str1 > a:str2
return 1
else
return 0
endif
endfunction
"prompt user for settings
function Prompt(str, ...)
let default = a:0 ? a:1 : ""
if a:str == "0"
let str = "Sort by which word [(0)whole line (<0)count from right (v)isual]? "
elseif a:str == "1"
let str = "Order [(f)orward (r)everse]? "
endif
execute "let ret = input(\"".str."\", \"".default."\")"
return ret
endfunction
" Use pathogen vim plugin
execute pathogen#infect()
" Remap capslock key to escape inside vim
au VimEnter * !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
au VimLeave * !xmodmap -e 'clear Lock' -e 'keycode 0x42 = Caps_Lock'
" Use this as your backup directory for swp files (create first)
set backupdir=~/.vim/backup
set directory=~/.vim/backup
let maplocalleader = '/'
let R_args = ['--no-save', '--no-restore']
" set RLOC outside of vimrc
let R_path=$RLOC
let R_LIBS_USER=$R_LIBS_USER
" let R_path = usrhome."/src/svn/r-devel/R/bin"
" let $R_LIBS_USER= usrhome."/R/bioc-devel"
" For jalvesaq/vimcmdline
" let cmdline_app = {}
" let cmdline_app['sh'] = '/bin/bash'
" let cmdline_in_buffer = 0
if exists('+colorcolumn')
set colorcolumn=80
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
let &colorcolumn=join(range(81,999),",")
highlight ColorColumn ctermbg=235 guibg=#2c2d27
" remove trailing whitespace on save (R files)
autocmd BufWritePre *.R,*md,*.txt :%s/\s\+$//e
" Emulate Tmux ^az
function ZoomWindow()
let cpos = getpos(".")
tabnew %
redraw
call cursor(cpos[1], cpos[2])
normal! zz
endfunction
nmap az :call ZoomWindow()<CR>