<commit_before>---
layout: post
title: "Vim"
tags: vim
permalink: vim
---
## Tips

Quick Ref

```sh
  vim -c "h quickref | only"
```

word - {letters, numbers, underscore}  
WORD - {non-blank characters}  

ZZ - save and quit  
ZQ - save without quit  

R - enter to Replace mode

g{motion} - work with display line  
  -ex gj down one line, g$ go to end of display line

% - jump between open/close parentheses  
< C-o > , < C-i > - toggle jump position  

v{motion} - visual mode select in line  
V{motion} - visual mode select line  
< C-v >{motion}{cIA} - change/insert/append in multiple lines 
< C-v >{motion}: - command with multiple lines

f{char} - move to next char  
t{char} - move to befoire next char  
; - repeat last seach  
, - repeat last seach backward  
* - hightlight word  

J - join the current line and next line together

cw - change word  
gu{motion}, gU{motion} - lower/upper letter

daw - delete a word  
das - delete a sentence  
dap - delete a paragraph  
dW - delete until space  
dG - delete until end of file  
d$ - delete until last of line  
dbw , < C-w > in insert mode - delete back one word  
d^ , < C-u > in insert mode - delete back to start of line  

< C-a >, < C-x > - addition and subtraction on numbers that also find next number automatically if current cursor not a number

< C-r >=55*10< Cr > in insert mode - calculate can print it

. - repeat last action (not include any move action)

#### Command
[range]  
    0 - above first line  
    1 - first line  
    . - mean to current line  
    % - all lines  
    $ - last line  
    {start},{end} - from start to end line  
    '<,' > - start selection to end selection  

:[range]print , :p - print line  
:[range]copy{target} , :t - copy line & paste  
:[range]move{target} , :m - move line  
:[range]normal {vimkey} - action vim key via command  
    ex. :%normal A; - put ';' in end line for each line  

@: - repeat last command   

:!< shell command > - run shell command in vim  
    % - mean to current file  

:shell - call shell in vim , 'exit' return to vim  
    use ctrl+z to call shell than 'fg' return to vim is better way  

:nohlsearch , :nohls ,<leader>hs in janus - mute highlight search  
:redraw - redraw screen (Ctrl + L)

#### Windows Split
< C-ws > - Split windows  
< C-wv > - Split windows verically  
< C-wq > - Quit windwos  
< C-ww > - switch between windows  

You split navigations with 

  ```sh
  nnoremap <C-J> <C-W><C-J>
  nnoremap <C-K> <C-W><C-K>
  nnoremap <C-L> <C-W><C-L>
  nnoremap <C-H> <C-W><C-H>
  ```
  
#### Tab
  * :tabe[dit] {filename} - open file in new tab  
        use gt, gT to move to next, previous tab  
  * :tabc[lose] - close all tabs  
  * :tabo[nly] - keep current tab and closing all others  

#### Vim spell
:set spell - enable spell checker  
[s, ]s - jump to miss spelling work  
z= - fix miss spelling word  
zg - add currect word into spell dictionary  
zw - remove current word from spell dictionary

#### Repositioning the screen   
zt - Move current line to top screen  
zz - Move current line to mid screen  
zb - Move current line to botoom screen  

#### Scroll Screen
< C-f > - scroll down one screen  
< C-b > - scroll up one screen  
< C-d > - scroll down half screen  
< C-u > - scroll up half screen  

### Ctags

    ```sh
    brew install ctags #install ctags
    ctags -R # generate tags
    ```
    
    < C-] > to jump to tag  
    < C-t > to back to original  
    
### Yank to clipboard 

```sh
# update vim version
$ brew install vim
$ brew install reattach-to-user-namespace
```

- :reg - check buffer register  
- "<buffer>p - pase buffer  
- "<buffer>yy - yank to buffer  
- "*yy  - yank to system clipboard  

#### [Janus](https://github.com/carlhuda/janus)

```sh
# update vim version to support all plugin in janus
$ brew install vim
```

< leader >hs - toggle highlight search  
< leader >n - toggle [NERDTree](https://github.com/scrooloose/nerdtree)  
< leader >ci , < leader >/ - toogle comment # [NERDCommenter](http://github.com/ddollar/nerdcommenter)  
< leader >< leader >w - easy motion w # [EasyMotion](https://github.com/Lokaltog/vim-easymotion)  


#### Plug-in:
1. [surround](https://github.com/tpope/vim-surround)  
  v{motion}S{tag} - Visual Select then surround it with tag  
  cs{old}{new} - change old surround to new surround  
  ds{tag} - delete tag surround  
2. [Easymotion](https://github.com/Lokaltog/vim-easymotion) - [EasyMotion Doc](https://github.com/Lokaltog/vim-easymotion/blob/master/doc/easymotion.txt#L88)
3. ctags
4. [GoldenView.Vim](https://github.com/zhaocai/GoldenView.Vim)

## Reference:
1. [A vim Tutorial and Primer](http://www.danielmiessler.com/study/vim/)
2. [วิธีใช้ Vi และ Vim](http://www.joinstick.net/howto/vim.html)
3. [How to Use Vim's Spell checker](http://tips.webdesign10.com/vim/how-use-vims-spellchecker)
4. [Vim Essential Plugins](http://code.tutsplus.com/series/vim-essential-plugins--net-19224)
5. [Vi/Vim Cheat Sheet](http://www.worldtimzone.com/res/vi.html)
6. [Vim Cheat Sheet Graphical](https://cdn.shopify.com/s/files/1/0165/4168/files/preview.png)<commit_msg>clean it<commit_after>---
layout: post
title: "Vim"
tags: vim
permalink: vim
---
## Tips

Quick Ref

```sh
  vim -c "h quickref | only"
```

word - {letters, numbers, underscore}  
WORD - {non-blank characters}  

ZZ - save and quit  
ZQ - save without quit  

R - enter to Replace mode

g{motion} - work with display line  
  -ex gj down one line, g$ go to end of display line

% - jump between open/close parentheses  
< C-o > , < C-i > - toggle jump position  

v{motion} - visual mode select in line  
V{motion} - visual mode select line  
< C-v >{motion}{cIA} - change/insert/append in multiple lines 
< C-v >{motion}: - command with multiple lines

f{char} - move to next char  
t{char} - move to befoire next char  
; - repeat last seach  
, - repeat last seach backward  
* - hightlight word  

J - join the current line and next line together

cw - change word  
gu{motion}, gU{motion} - lower/upper letter

daw - delete a word  
das - delete a sentence  
dap - delete a paragraph  
dW - delete until space  
dG - delete until end of file  
d$ - delete until last of line  
dbw , < C-w > in insert mode - delete back one word  
d^ , < C-u > in insert mode - delete back to start of line  

< C-a >, < C-x > - addition and subtraction on numbers that also find next number automatically if current cursor not a number

< C-r >=55*10< Cr > in insert mode - calculate can print it

. - repeat last action (not include any move action)

#### Command
[range]  
    0 - above first line  
    1 - first line  
    . - mean to current line  
    % - all lines  
    $ - last line  
    {start},{end} - from start to end line  
    '<,' > - start selection to end selection  

:[range]print , :p - print line  
:[range]copy{target} , :t - copy line & paste  
:[range]move{target} , :m - move line  
:[range]normal {vimkey} - action vim key via command  
    ex. :%normal A; - put ';' in end line for each line  

@: - repeat last command   

:!< shell command > - run shell command in vim  
    % - mean to current file  

:shell - call shell in vim , 'exit' return to vim  
    use ctrl+z to call shell than 'fg' return to vim is better way  

:nohlsearch , :nohls ,< leader >hs in janus - mute highlight search  
:redraw - redraw screen (Ctrl + L)

#### Windows Split
< C-ws > - Split windows  
< C-wv > - Split windows verically  
< C-wq > - Quit windwos  
< C-ww > - switch between windows  

You split navigations with 

  ```sh
  nnoremap <C-J> <C-W><C-J>
  nnoremap <C-K> <C-W><C-K>
  nnoremap <C-L> <C-W><C-L>
  nnoremap <C-H> <C-W><C-H>
  ```
  
#### Tab
  * :tabe[dit] {filename} - open file in new tab  
        use gt, gT to move to next, previous tab  
  * :tabc[lose] - close all tabs  
  * :tabo[nly] - keep current tab and closing all others  

#### Vim spell
:set spell - enable spell checker  
[s, ]s - jump to miss spelling work  
z= - fix miss spelling word  
zg - add currect word into spell dictionary  
zw - remove current word from spell dictionary

#### Repositioning the screen   
zt - Move current line to top screen  
zz - Move current line to mid screen  
zb - Move current line to botoom screen  

#### Scroll Screen
< C-f > - scroll down one screen  
< C-b > - scroll up one screen  
< C-d > - scroll down half screen  
< C-u > - scroll up half screen  

### Ctags

```sh
$ brew install ctags
$ ctags -R # generate tags
```
    
< C-] > to jump to tag  
< C-t > to back to original  
    
### Yank to clipboard 

```sh
# update vim version
$ brew install vim
$ brew install reattach-to-user-namespace
```

- :reg - check buffer register  
- "< buffer >p - pase buffer  
- "< buffer >yy - yank to buffer  
- "*yy  - yank to system clipboard  

#### [Janus](https://github.com/carlhuda/janus)

```sh
# update vim version to support all plugin in janus
$ brew install vim
```

< leader >hs - toggle highlight search  
< leader >n - toggle [NERDTree](https://github.com/scrooloose/nerdtree)  
< leader >ci , < leader >/ - toogle comment # [NERDCommenter](http://github.com/ddollar/nerdcommenter)  
< leader >< leader >w - easy motion w # [EasyMotion](https://github.com/Lokaltog/vim-easymotion)  


#### Plug-in:
1. [surround](https://github.com/tpope/vim-surround)  
  v{motion}S{tag} - Visual Select then surround it with tag  
  cs{old}{new} - change old surround to new surround  
  ds{tag} - delete tag surround  
2. [Easymotion](https://github.com/Lokaltog/vim-easymotion) - [EasyMotion Doc](https://github.com/Lokaltog/vim-easymotion/blob/master/doc/easymotion.txt#L88)
3. ctags
4. [GoldenView.Vim](https://github.com/zhaocai/GoldenView.Vim)

## Reference:
1. [A vim Tutorial and Primer](http://www.danielmiessler.com/study/vim/)
2. [วิธีใช้ Vi และ Vim](http://www.joinstick.net/howto/vim.html)
3. [How to Use Vim's Spell checker](http://tips.webdesign10.com/vim/how-use-vims-spellchecker)
4. [Vim Essential Plugins](http://code.tutsplus.com/series/vim-essential-plugins--net-19224)
5. [Vi/Vim Cheat Sheet](http://www.worldtimzone.com/res/vi.html)
6. [Vim Cheat Sheet Graphical](https://cdn.shopify.com/s/files/1/0165/4168/files/preview.png)
{'fraction_non_alphanumeric': 0.12831337129393286, 'fraction_numerical': 0.006675829569998037, 'mean_word_length': 2.8068011958146486, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 89, 'https://': 16, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2231321', 'n_tokens_mistral': 3707, 'n_tokens_neox': 3565, 'n_words': 1209}