> For the complete documentation index, see [llms.txt](https://lib.rjo.me/newlib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lib.rjo.me/newlib/tools/vim.md).

# Editors

## Cheatsheet to vim

### replace all empty lines

`:g/^$/d` [regards to here](https://alvinalexander.com/linux-unix/vi-vim-delete-blank-lines-empty-lines)\
`:<range>s/<pattern>/<replace>`

* `<range>` Range can be a linenumber `12` a range of linenumber `12,14` a range of marks `'a,'b` or the whole document `%`
* `<pattern>` The pattern to search for
* `<replace>` what to replace the pattern with\
  Example comment lines 15 to 25 `:15,25s/^/#`\
  [Vim RexEx Engine](https://learnbyexample.github.io/vim_reference/Regular-Expressions.html) change US Date format to European format, and vice-versa

```vim
" US (MM/DD/YYYY) → EU (DD.MM.YYYY)
<range>s/\(\d\+\)\/\(\d\+\)\/\(\d\+\)/\2.\1.\3/
<range>s/\(\d\+\)\/\(\d\+\)\//\2\.\1\./

" EU (DD.MM.YYYY) → US (MM/DD/YYYY)
<range>s/\(\d\+\)\.\(\d\+\)\.\(\d\+\)/\2\/\1\/\3/
<range>s/\(\d\+\).\(\d\+\)./\2\/\1\//
```

### insert file at current position

`:r <path/to/file>` insert lines *9* *19* from file `myfile` `:r! sed -n 9,19p /path/to/myfile`

### Ranges

Usefule Link [Ranges](https://vim.fandom.com/wiki/Ranges)\
`$` goes to end of Line.

### switch case

**upper case** press `gU<motion>` to change the letter under the cursor to **lower case** press `gu<motion>` to change the letter under the cursor to

### ranges

usefule link [ranges](https://vim.fandom.com/wiki/ranges)\
`$` goes to end of line.\
`0` goes to the beginning of line (`^` seems to do the same)

### Visual Mode operations

Remap visual mode to `\v` with `nnoremap <Leader>v <C-V>` in `.vimrc` to avoid conflict with Windows *Paste* operation on `Ctrl-v`

### Insert on multiple Lines

move to mark the needed lines (h,j,k,l) Hit `<Shift>-I` for insert mode, type text and hit `<Esc>`

### Increment numbers

mark the numbers to be icremented (there need to be integers, it does not fill whitespace. Use multiline insert first if needed.) then type `g` and `<Ctrl>-a` type `:h v_g` to see help entry

### regex

[regex](http://www.vimregex.com/)

## Plugins

### Vundle

I use vundle for managing plugins, [here](https://github.com/VundleVim/Vundle.vim)

```
 git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
```

### [Nerdtree](https://github.com/preservim/nerdtree)

nerdtree allows you to have a folder pane to navigate files/folders. `?` to see help menu `r` to refresh view, for example after deleting some file `I` to see hidden files and folders

### [youcompleteme](https://github.com/ycm-core/YouCompleteMe)

ycm offers autocomplete

### [SURROUND.VIM](https://vimawesome.com/plugin/surround-vim)

A plugin to change the brackets or other characters around text. Useful for html for example

### [Emmet](https://github.com/mattn/emmet-vim/)

A plugin for html autocompletion Open or create a New File:

`vim index.html` Type ("\_" is the cursor position):

`html:5_` Then type , (**Ctrl** then **y** then **,**) and you should see:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
</html>
```

## Styling

### Theme

Put new themes into `~/.vim/colors` and then pick them with `:colo <theme>` `elflord` theme looks nice Latitude 5520 Laptop in Windows Terminal
