|
| 1 | +--- |
| 2 | +title: "Vim Commands" |
| 3 | +weight: 1000 |
| 4 | +description: List of supported vim commands in Vim Emulation |
| 5 | +--- |
| 6 | + |
| 7 | +### Vim Commands |
| 8 | + |
| 9 | +#### Supported Features |
| 10 | +------------------ |
| 11 | + |
| 12 | +Most of supported commands can be followed by motion command or executed in visual mode, work with registers or can be prefixed with number of repetitions. |
| 13 | + |
| 14 | +Here is list of emulated commands with description where it can diverge from Vim in functionality. |
| 15 | + |
| 16 | +#### Modes |
| 17 | + |
| 18 | +* normal |
| 19 | +* insert and replace |
| 20 | +* visual |
| 21 | +* command line (`:`) |
| 22 | + |
| 23 | +#### Normal and Visual Modes |
| 24 | + |
| 25 | +* basic movement -- `h`/`j`/`k`/`l`, `<C-U>`, `<C-D>`, `<C-F>`, `<C-B>`, `gg`, `G`, `0`, `^`, `$` etc. |
| 26 | +* word movement -- `w`, `e`, `b` etc. |
| 27 | +* "inner/a" movement -- `ciw`, `3daw`, `ya{` etc. |
| 28 | +* `f`, `t` movement |
| 29 | +* `[`, `]` movement |
| 30 | +* `{`, `}` -- paragraph movement |
| 31 | +* delete/change/yank/paste with register |
| 32 | +* undo/redo |
| 33 | +* `<C-A>`, `<C-X>` -- increase or decrease number in decimal/octal/hexadecimal format (e.g. `128<C-A>` on or before "0x0ff" changes it to "0x17f") |
| 34 | +* `.` -- repeat last change |
| 35 | +* `/search`, `?search`, `*`, `#`, `n`, `N` -- most of regular expression syntax used in Vim except `\<` and `\>` just is the same as `\b` in QRegExp |
| 36 | +* `@`, `q` (macro recording, execution) -- special keys are saved as `<S-Left>` |
| 37 | +* marks |
| 38 | +* `gv` -- last visual selection; can differ if text is edited around it |
| 39 | +* indentation -- `=`, `<<`, `>>` etc. with movement, count and in visual mode |
| 40 | +* "to upper/lower" -- `~`, `gU`, `gu` etc. |
| 41 | +* `i`, `a`, `o`, `I`, `A`, `O` -- enter insert mode |
| 42 | +* scroll window -- `zt`, `zb`, `zz` etc. |
| 43 | +* wrap line movement -- `gj`, `gk`, `g0`, `g^`, `g$` |
| 44 | + |
| 45 | +#### Command Line Mode |
| 46 | + |
| 47 | +* `:map`, `:unmap`, `:inoremap` etc. |
| 48 | +* `:source` -- very basic line-by-line sourcing of vimrc files |
| 49 | +* `:substitute` -- substitute expression in range |
| 50 | +* `:'<,'>!cmd` -- filter through an external command (e.g. sort lines in file with `:%!sort`) |
| 51 | +* `:.!cmd` -- insert standard output of an external command |
| 52 | +* `:read` |
| 53 | +* `:yank`, `:delete`, `:change` |
| 54 | +* `:move`, `:join` |
| 55 | +* `:20` -- go to address |
| 56 | +* `:history` |
| 57 | +* `:registers`, `:display` |
| 58 | +* `:nohlsearch` |
| 59 | +* `:undo`, `:redo` |
| 60 | +* `:normal` |
| 61 | +* `:<`, `:>` |
| 62 | + |
| 63 | +#### Insert Mode |
| 64 | + |
| 65 | +* `<C-O>` -- execute single command and return to insert mode |
| 66 | +* `<C-V>` -- insert raw character |
| 67 | +* `<insert>` -- toggle replace mode |
| 68 | + |
| 69 | +#### Options (:set ...) |
| 70 | + |
| 71 | +* `autoindent` |
| 72 | +* `clipboard` |
| 73 | +* `backspace` |
| 74 | +* `expandtab` |
| 75 | +* `hlsearch` |
| 76 | +* `ignorecase` |
| 77 | +* `incsearch` |
| 78 | +* `indent` |
| 79 | +* `iskeyword` |
| 80 | +* `scrolloff` |
| 81 | +* `shiftwidth` |
| 82 | +* `showcmd` |
| 83 | +* `smartcase` |
| 84 | +* `smartindent` |
| 85 | +* `smarttab` |
| 86 | +* `startofline` |
| 87 | +* `tabstop` |
| 88 | +* `tildeop` |
| 89 | +* `wrapscan` |
| 90 | + |
| 91 | +#### Example Vimrc |
| 92 | +------------- |
| 93 | +``` |
| 94 | + " highlight matched |
| 95 | + set hlsearch |
| 96 | + " case insensitive search |
| 97 | + set ignorecase |
| 98 | + set smartcase |
| 99 | + " search while typing |
| 100 | + set incsearch |
| 101 | + " wrap-around when searching |
| 102 | + set wrapscan |
| 103 | + " show pressed keys in lower right corner |
| 104 | + set showcmd |
| 105 | + " tab -> spaces |
| 106 | + set expandtab |
| 107 | + set tabstop=4 |
| 108 | + set shiftwidth=4 |
| 109 | + " keep a 5 line buffer for the cursor from top/bottom of window |
| 110 | + set scrolloff=5 |
| 111 | + " X11 clipboard |
| 112 | + set clipboard=unnamed |
| 113 | + " use ~ with movement |
| 114 | + set tildeop |
| 115 | +
|
| 116 | + " mappings |
| 117 | + nnoremap ; : |
| 118 | + inoremap jj <Esc> |
| 119 | +
|
| 120 | + " clear highlighted search term on space |
| 121 | + noremap <silent> <Space> :nohls<CR> |
| 122 | +
|
| 123 | + " reselect visual block after indent |
| 124 | + vnoremap < <gv |
| 125 | + vnoremap > >gv |
| 126 | +
|
| 127 | + " MOVE LINE/BLOCK |
| 128 | + nnoremap <C-S-J> :m+<CR>== |
| 129 | + nnoremap <C-S-K> :m-2<CR>== |
| 130 | + inoremap <C-S-J> <Esc>:m+<CR>==gi |
| 131 | + inoremap <C-S-K> <Esc>:m-2<CR>==gi |
| 132 | + vnoremap <C-S-J> :m'>+<CR>gv=gv |
| 133 | + vnoremap <C-S-K> :m-2<CR>gv=gv |
| 134 | +``` |
| 135 | + |
| 136 | +### Custom vim commands |
| 137 | + |
| 138 | +In this section we present a list of all custom vim commands that are supported to perform different operation in CP Editor. |
| 139 | + |
| 140 | +| Command | Shorthand | Description | Usage | |
| 141 | +| :----------: | :-------: | :-----------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------: | |
| 142 | +| `new` | `new` | Opens a new tab, if no langauge is specified, a tab in default editor langauge will open | `new cpp` or `new` | |
| 143 | +| `open` | `opn` | Opens a new file, Only C++/Java/Python files will be opened. The opened tab will use the language as per file extension. | `open /absolute/path/of/file.cpp` or `opn ~/cf/a.cpp` | |
| 144 | +| `compile` | `cmp` | Compiles the code, It is like clicking "Compile" button in a tab. | `compile` or `cmp` | |
| 145 | +| `crun` | `crn` | Compiles and run, It is like clicking "Compile and Run" button in a tab. | `crun` or `crn` | |
| 146 | +| `run` | `run` | Run, if no argument is provided all testcases are ran, otherwise nth testcase is ran. Counting includes hidden testcases. | `run` or `run 2` | |
| 147 | +| `drun` | `drn` | Detached run, It is same as clicking "Detached Run" in menu. | `drun` or `drn` | |
| 148 | +| `killall` | `kap` | Kill all process, It is same as clicking "Kill Process" in menu | `killall` or `kap` | |
| 149 | +| `format` | `fmt` | Format Code, It is same as clicking "Format Code" in menu | `format` or `fmt` | |
| 150 | +| `snippet` | `snp` | Open snippet dialog, It is same as clicking "Use Snippets" in menu | `snippet` or `snp` | |
| 151 | +| `vmode` | `vmd` | View mode, Changes the view mode. It can only toggle to "edit" and "split" mode | `vmode edit` or `vmd split` | |
| 152 | +| `preference` | `prf` | Preferences, It is same as clicking "Preference" in menu | `preference` or `prf` | |
| 153 | +| `lang` | `lng` | Language, It can be used to change the language of a tab. | `lang cpp` or `lng java` | |
| 154 | +| `clear` | `clr` | Clear Message logger text | `clear` or `clr` | |
| 155 | +| `exit` | `ext` | Exit, It is same as pressing "Quit" in menu. | `exit` or `ext` | |
0 commit comments