grimoire

personal wiki
git clone git://git.pyratebeard.net/grimoire.git
Log | Files | Refs

vim.md (2452B)


      1 # vim
      2 
      3 ## copy contents to/from files
      4 to copy the contents into a file
      5   ```
      6   :r <filename>
      7   ```
      8 or
      9   ```
     10   :"qY # yank out of first file
     11   :"qP # put into second file
     12   ```
     13 or read range of lines
     14   ```
     15   :r! sed -n <n>,<m>p /path/to/file.md
     16   ```
     17 
     18 to copy the contents to a new file
     19   ```
     20   :<n>,<m> w <filename>
     21   ```
     22   where `<n>` and `<m>` are numbers or symbols that designate range of lines
     23   
     24 
     25 ## text wrap
     26 (wrap to column)
     27 wrap current line
     28 ```
     29 gqq
     30 ```
     31 
     32 wrap entire file
     33 ```
     34 gqG
     35 ```
     36 
     37 wrap paragraph using visual selection
     38 ```
     39 V}gq
     40 ```
     41 
     42 also use visual or visual block with `gq`
     43 
     44 ## spell
     45 [using_spellcheck][]
     46 check spelling
     47 ```
     48 Spell
     49 ```
     50 
     51 move to word
     52 ```
     53 ]s [s
     54 ```
     55 
     56 and see results
     57 ```
     58 z=
     59 ```
     60 
     61 turn off highlighting
     62 ```
     63 set nospell
     64 ```
     65 
     66 ## buffers
     67 - buffer [faq][]
     68 - using [vanilla vim][]
     69 - [buffers over tabs][]
     70 - open buffer
     71     ```
     72     :e <filename>
     73     :new
     74     ```
     75 - view buffers
     76     ```
     77     :ls
     78     ```
     79 - switch buffers
     80     ```
     81     :buffer <num>
     82     ```
     83 - unload buffer
     84     ```
     85     :bd <num>
     86     ```
     87 
     88 ## incrementing numbers
     89 post on [reddit][]
     90 
     91 select several lines containing '0' and type `g<C-a>`
     92 
     93 ## split
     94 - movement
     95     ```
     96     <Ctrl>-w [h,j,k,l]
     97     <Ctrl>-w w
     98     ```
     99 - rotate
    100     ```
    101     <Ctrl>-w r
    102     ```
    103 - orientate
    104     ```
    105     <Ctrl>-w J
    106     <Ctrl>-w L
    107     ```
    108 - sizing
    109 	```
    110 	<Ctrl>-w -		# decrease height by 1 line
    111 	<Ctrl>-w +		# increase height by 1 line
    112 	<Ctrl>-w <		# change width by 1 line to the left
    113 	<Ctrl>-w >		# change width by 1 line to the right
    114 	<Ctrl>-w 10 -	# decrease height by 10 lines, etc...
    115 	```
    116 
    117 ## list recent doc
    118 ```
    119 :ol[dfiles]
    120 ```
    121 
    122 ## replace
    123 - change inner word
    124     ```
    125     ciw
    126     ```
    127 
    128 ## delete
    129 - until but not <char>
    130     ```
    131     dt <char>
    132     ```
    133 - until and <char>
    134     ```
    135     df <char>
    136     ```
    137 
    138 ## using the shell
    139 [vim and the shell][]
    140 
    141 - in script, highlight line and switch to command mode by pressing `:`
    142 ```bash
    143 :'<,'>w !bash -
    144 ```
    145 
    146 ```python
    147 :'<,'>w !python -
    148 ```
    149 
    150 [using_spellcheck]: https://www.linux.com/learn/using-spell-checking-vim
    151 [faq]: http://vim.wikia.com/wiki/Vim_buffer_FAQ
    152 [vanilla vim]: https://stackoverflow.com/questions/16082991/vim-switching-between-files-rapidly-using-vanilla-vim-no-plugins
    153 [buffers over tabs]: https://stackoverflow.com/questions/26708822/why-do-vim-experts-prefer-buffers-over-tabs
    154 [reddit]: https://www.reddit.com/r/vim/comments/a1lvb1/til_gca_for_creating_a_column_of_incrementing/
    155 [vim and the shell]: https://vimways.org/2019/vim-and-the-shell/