/
fn_vim.Rmd
485 lines (376 loc) · 12.3 KB
/
fn_vim.Rmd
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
---
title: "Example and Tutorial for Vim Editor (Linux)"
output:
html_document:
number_sections: true
html_notebook:
number_sections: true
word_document:
number_sections: true
pdf_document:
df_print: paged
number_sections: true
urlcolor: blue
always_allow_html: yes
---
Go back to [fan](http://fanwangecon.github.io/)'s [Tex4Econ and Miscellaneous Repository](http://fanwangecon.github.io/Tex4Econ/).
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = FALSE)
```
# Vim Installations
Vim ships with Debian. Also install neo-vim:
```{bash}
vim
sudo apt-get install neovim
```
Just installing onedark, neovim seems to work better than vim. Vim has delete lag, and extra white space rows at the bottom of the screen that could take up very large screen segment. Neovim with onedark does not have this issue, could be due to some basic setting differences.
## Install Vim-Plug Plug-ins manager for Vim
Follow the [instructions here](https://github.com/junegunn/vim-plug/wiki/tutorial) for installations. Several steps:
1. generate ~/.vim and ~/.vimrc folders
2. curl plug.vim to ~/.vim/autoload
3. update ~/.vimrc file with instructions regarding which files to install.
4. open vim, type: *:PlugInstall* or *:PlugUpdate*, should start seeing updating packages.
5. type: *:scriptnames* to see loaded plugins
6. just comment out or delete plug lines for packages no longer needed.
7. how to install a particular package? See [vimawesome](https://vimawesome.com/plugin/onedark-vim)
```{bash}
# curl plug.vim
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# create vimrc file
cd $HOME
vim .vimrc
# paste into file the text below.
```
Example .vimrc file with only one package one dark atom visual for vim:
```{bash}
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
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')
" Declare the list of plugins.
Plug 'joshdick/onedark.vim'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""
" Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
colorscheme onedark
```
## Install Vim-Plug Plug-ins manager for Neovim
Follow the [instructions here](https://github.com/junegunn/vim-plug/wiki/tutorial) for installations. Very similar steps as above for Vim:
1. curl *plug.vim* to *.local/share/nvim*. Directory different than vim
2. create nvim folder under .config, vimrc contents should be in this file: *~/.config/nvim/init.vim*
3. enter nvim and *:PlugInstall*
```{bash}
# Neovim (~/.local/share/nvim/site/autoload)
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# create vimrc file
mkdir ~/.config/nvim
nvim ~/.config/nvim/init.vim
# paste into file the text below.
```
Vimrc file with atom styling:
```
" Plugins will be downloaded under the specified directory.
call plug#begin('~/.local/share/nvim/site/plugged')
" Declare the list of plugins.
Plug 'vim-airline/vim-airline'
" Visual Settings
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
" Color theme plugins
Plug 'joshdick/onedark.vim'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""
" Color Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
colorscheme onedark
"""""""""""""""""""""""""""""""""""""""""""""""""
" Visual Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
" For Goyo
let g:goyo_width=85
" For LimeLight
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240
" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'
" highlight line
let g:limelight_bop = '^.*$'
" let g:limelight_eop = '\n'
let g:limelight_paragraph_span = 0
"""""""""""""""""""""""""""""""""""""""""""""""""
" UI Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
" Keep cursor in the middle of the page, useful for editing text
set so=999
" Turn limelight on by default
" autocmd VimEnter * Limelight
" Turn Goyo on by default
autocmd VimEnter * Goyo
" autocmd VimEnter * AirlineToggle
" In Goyo, if airline is turned on, do nto show scratch area
" autocmd! User GoyoEnter nested set eventignore=FocusGained
" autocmd! User GoyoLeave nested set eventignore=
""""""""""""""""""""""""""""""""""""""""""""""""""
" Remap Keys
"""""""""""""""""""""""""""""""""""""""""""""""""
" esc in insert mode
" inoremap jj <esc>
```
## Install Neovim in Windows
Install and access neovim all from windows powershell. Type in *powershell* in regular command prompt for example.
### Install Neovim and Vim-Plug in Windows
```
# install scoop and use scoop
scoop install neovim
# follow vim-plug instructions
md ~\AppData\Local\nvim\autoload
$uri = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
(New-Object Net.WebClient).DownloadFile(
$uri,
$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
"~\AppData\Local\nvim\autoload\plug.vim"
)
)
```
### Set up init.vim File in Windows
Inside powershell, create init.vim file:
```
cd ~\AppData\Local\nvim\
nvim init.vim
```
paste these in *:set paste*:
```
" Plugins will be downloaded under the specified directory.
call plug#begin('~/AppData/Local/nvim/site/plugged')
" Declare the list of plugins.
Plug 'vim-airline/vim-airline'
" Markdown
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
" Rmd Syntax Highlighting, Nvim-R renders
Plug 'jalvesaq/Nvim-R'
Plug 'vim-pandoc/vim-rmarkdown'
Plug 'vim-pandoc/vim-pandoc-syntax'
" Visual Settings
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'reedes/vim-pencil'
" Color theme plugins
Plug 'joshdick/onedark.vim'
Plug 'morhetz/gruvbox'
Plug 'junegunn/seoul256.vim'
Plug 'jaredgorski/spacecamp'
Plug 'lifepillar/vim-solarized8'
Plug 'reedes/vim-colors-pencil'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""
" Color Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
" onedark:
colorscheme onedark
" seoul256:
" seoul256 (dark), 236 is darkest
" let g:seoul256_background = 236
" colorscheme seoul256
" spacecamp:
" colorscheme spacecamp
" vim-solarized8:
" set background=dark
" colorscheme solarized8
" vim-colors-pencil:
" let g:pencil_higher_contrast_ui = 0
" colorscheme pencil
" set background=dark
"""""""""""""""""""""""""""""""""""""""""""""""""
" Visual Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
" For Goyo
let g:goyo_width=85
" For LimeLight
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240
" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'
" if Limelight should highlight line rather than paragraph
let g:limelight_bop = '^.*$'
" let g:limelight_eop = '\n'
let g:limelight_paragraph_span = 0
"""""""""""""""""""""""""""""""""""""""""""""""""
" UI Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
" Keep cursor in the middle of the page, useful for editing text
set so=999
" Turn limelight on by default
" autocmd VimEnter * Limelight
" Turn Goyo on by default
autocmd VimEnter * Goyo
"""""""""""""""""""""""""""""""""""""""""""""""""
" Markdown **, * etc settings
"""""""""""""""""""""""""""""""""""""""""""""""""
" set concealcursor=n
" set conceallevel=3
" hi Asterisks NONE
" hi AsteriskBold cterm=bold gui=bold
" syn match Asterisks contained "**" conceal
" syn match AsteriskBold "\\\@<!\*\*[^"*|]\+\*\*" contains=Asterisks
" autocmd VimEnter * highlight Normal ctermbg=black
" ctermfg=grey
"""""""""""""""""""""""""""""""""""""""""""""""""
" Other Settings
"""""""""""""""""""""""""""""""""""""""""""""""""
set paste " to enable pasting in windows
set nofoldenable " avoid folding by default
"""""""""""""""""""""""""""""""""""""""""""""""""
" Remap Keys
"""""""""""""""""""""""""""""""""""""""""""""""""
" esc in insert mode
inoremap jj <Esc>
```
```
nvim "C:/Users/d674a/Tex4Econ/_other/equation/multilines.tex"
```
### Full Screen Vim Window in Windows
It is nice to have full screen, no distraction work experience. To set command prompt to full screen (to get rid of scrolling bar on the right in full screen), use windows command prompt which allows for full screen, right click on window top border, choose property, then choose layout, then set height and width of window size and buffer size to be the same. This will allow for full screen experience.
# Vim Basics
```{bash}
# to open vim
vim -v
# to exit vim
:q!
# open up file from google drive
vim "/mnt/chromeos/GoogleDrive/MyDrive/Reading Papers/Reading/Referee/pa_2019_oct_journal/jor_12345_comments.Rmd"
# start editing, type i to enter insert mode
i
# when editing is done, to exit and save, write and quit
# esc first
:wq
```
# Vim Cursor Movements
Move cursor to the beginning of a line? This should not be done in edit mode, esc, use movement commands, then back to insert mode. There are six most basic movements, *wbjk()0$*:
```{bash}
# forward one word
w
# back one word to begin
b
# back to word to end
e
# forward one line, achieved by also pressing downward arrow
j
# backward one line, achieved by pressing upward arrow
k
# left arrow
h
# right arrow
l
# Jump forward one Sentence
)
# Jump backward one Sentence
(
# Forward one page and back one page
# ctrl+f, ctrl+b
# Begin of line
0
# End of Line
$
# Begin of File
gg
# End of File
G
```
In combination, the basic commands can be used in combination
```{bash}
# move to the beginning of the next line
j0
# move to the end of the next line
j$
```
# Very Convinent Functions
Some functionalities take much more efforts to complete in many other editors, but are very easy in vim:
```{bash}
# combine lines: bunch of lines, with carriage break, one block of text, reflow/join
# 1. select block
Vjjjj
# 2. reflow/join
J
```
## Vim go to Spot in Text Quickly
```
# ESC
# Search for word
/abc
# esc
# next occurance of word
n
# last occurance
N
# first occurance overall
ggn
# last occurance overall
G
# clear search highlighting
:noh
```
back to previous point
```
~.
```
## Combo Operations
**Delete and Insert**:
- delete from now till end of sentence and insert mode: *C*
- delete whole sentence you are on and insert: *cc*
- delete until end of sentence and insert mode: *cis*
- delete current word and go into insert mode: *cw*
**Delete**:
- Delete current word: *dw*
- Delete from cursor until end of sentence: *dis*
- Delete from cursor to end of line: *d$* or *D*
- Delete until end of paragraph: *dip*
- Delete all text in file: *ggdG*
**Copying**: replace *d* by *y* for all oeprations.
- Copy current word: *yiw*; or *yw* which yanks word from current letter to end
- Copy from cursor to end of line (need to set this): *y$* or *Y*
- Copy until end of paragraph: *yip*
- Copy all text on page: *ggVGY*
**Insert to edit**:
- Insert after last character of document: *GA*
- Insert at the end of line: *A*
- Insert after cursor, *a*, insert before curosr *i*
**Copy and Replace**:
- copy current word: *yiw*, then move to the next word to replace: *viwp*
**Replace Text**:
Replace text between quotations by currently copied text:
1. move cursor inside quotes
2. vi"
3. shift + P
## Vim Statistics
- word count: *g, ctrl+g*
# Vim Errors
Vim seems frozen (hard for vim to freeze, it is not really frozen). This is likely due to pressing *ctrl + s*, then need to press *ctrl + q*.
vim error: "E297: Write error in swap file"
```
# Trying to save
:w
# E297 can not save, override changes elswhere, and force save what is on screen.
:e!
```
# Vim Set-Up Others
## Chromebook
pressing esc key is an issue, too far away. On chromebook, remap the search key which is in the spot of the caps lock key to esc. and remap the esc key to search key.
1. search for keyboard under settings
2. launcher to escape, and escape to launcher