Skip to content

Commit 90a9200

Browse files
committed
docs: Add documentation for vim mode
1 parent 8ff8d55 commit 90a9200

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ tech-doc-hugo
66
dist/
77
tmp/
88
*.lock
9+
.DS_Store

content/docs/preferences/code-edit/_index.md

+153
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,156 @@ You can choose the parentheses to jump out by Tab in the [Parentheses](../langua
4545
When you insert an indent, insert spaces instead of a tab character. The number of spaces is equal to the [Tab Width](#tab-width).
4646

4747
Note that this won't replace the existing tab characters. In [Auto Indent](#auto-indent), the tab characters in the old line will remain in the new line (however, the new indent inserted after `{` will be spaces).
48+
49+
### Enable Vim emulation
50+
51+
If enabled, code editor will emulate vim behaviour. In vim emulation, Control Key such as <kbd>Ctrl+N</kbd> will not be intercepted by CP Editor but by Code Editor. We provide some custom commands that can perform various tasks like opening new tab, running testcases etc. [Here](#custom-vim-commands) is a list of all supported custom vim commands.
52+
53+
### Vim configuration
54+
55+
The configuration to use in vim mode. The list of all supported vim commands are listed [here](../general/_index.md#vim-commands)
56+
57+
### Vim Commands
58+
59+
#### Supported Features
60+
61+
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.
62+
63+
Here is list of emulated commands with description where it can diverge from Vim in functionality.
64+
65+
#### Modes
66+
67+
- normal
68+
- insert and replace
69+
- visual
70+
- command line (`:`)
71+
72+
#### Normal and Visual Modes
73+
74+
- basic movement -- `h`/`j`/`k`/`l`, `<C-U>`, `<C-D>`, `<C-F>`, `<C-B>`, `gg`, `G`, `0`, `^`, `$` etc.
75+
- word movement -- `w`, `e`, `b` etc.
76+
- "inner/a" movement -- `ciw`, `3daw`, `ya{` etc.
77+
- `f`, `t` movement
78+
- `[`, `]` movement
79+
- `{`, `}` -- paragraph movement
80+
- delete/change/yank/paste with register
81+
- undo/redo
82+
- `<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")
83+
- `.` -- repeat last change
84+
- `/search`, `?search`, `*`, `#`, `n`, `N` -- most of regular expression syntax used in Vim except `\<` and `\>` just is the same as `\b` in QRegExp
85+
- `@`, `q` (macro recording, execution) -- special keys are saved as `<S-Left>`
86+
- marks
87+
- `gv` -- last visual selection; can differ if text is edited around it
88+
- indentation -- `=`, `<<`, `>>` etc. with movement, count and in visual mode
89+
- "to upper/lower" -- `~`, `gU`, `gu` etc.
90+
- `i`, `a`, `o`, `I`, `A`, `O` -- enter insert mode
91+
- scroll window -- `zt`, `zb`, `zz` etc.
92+
- wrap line movement -- `gj`, `gk`, `g0`, `g^`, `g$`
93+
94+
#### Command Line Mode
95+
96+
- `:map`, `:unmap`, `:inoremap` etc.
97+
- `:source` -- very basic line-by-line sourcing of vimrc files
98+
- `:substitute` -- substitute expression in range
99+
- `:'<,'>!cmd` -- filter through an external command (e.g. sort lines in file with `:%!sort`)
100+
- `:.!cmd` -- insert standard output of an external command
101+
- `:read`
102+
- `:yank`, `:delete`, `:change`
103+
- `:move`, `:join`
104+
- `:20` -- go to address
105+
- `:history`
106+
- `:registers`, `:display`
107+
- `:nohlsearch`
108+
- `:undo`, `:redo`
109+
- `:normal`
110+
- `:<`, `:>`
111+
112+
#### Insert Mode
113+
114+
- `<C-O>` -- execute single command and return to insert mode
115+
- `<C-V>` -- insert raw character
116+
- `<insert>` -- toggle replace mode
117+
118+
#### Options (:set ...)
119+
120+
- `autoindent`
121+
- `clipboard`
122+
- `backspace`
123+
- `expandtab`
124+
- `hlsearch`
125+
- `ignorecase`
126+
- `incsearch`
127+
- `indent`
128+
- `iskeyword`
129+
- `scrolloff`
130+
- `shiftwidth`
131+
- `showcmd`
132+
- `smartcase`
133+
- `smartindent`
134+
- `smarttab`
135+
- `startofline`
136+
- `tabstop`
137+
- `tildeop`
138+
- `wrapscan`
139+
140+
#### Example Vimrc
141+
142+
```vimrc
143+
" highlight matched
144+
set hlsearch
145+
" case insensitive search
146+
set ignorecase
147+
set smartcase
148+
" search while typing
149+
set incsearch
150+
" wrap-around when searching
151+
set wrapscan
152+
" show pressed keys in lower right corner
153+
set showcmd
154+
" tab -> spaces
155+
set expandtab
156+
set tabstop=4
157+
set shiftwidth=4
158+
" keep a 5 line buffer for the cursor from top/bottom of window
159+
set scrolloff=5
160+
" X11 clipboard
161+
set clipboard=unnamed
162+
" use ~ with movement
163+
set tildeop
164+
" mappings
165+
nnoremap ; :
166+
inoremap jj <Esc>
167+
" clear highlighted search term on space
168+
noremap <silent> <Space> :nohls<CR>
169+
" reselect visual block after indent
170+
vnoremap < <gv
171+
vnoremap > >gv
172+
" MOVE LINE/BLOCK
173+
nnoremap <C-S-J> :m+<CR>==
174+
nnoremap <C-S-K> :m-2<CR>==
175+
inoremap <C-S-J> <Esc>:m+<CR>==gi
176+
inoremap <C-S-K> <Esc>:m-2<CR>==gi
177+
vnoremap <C-S-J> :m'>+<CR>gv=gv
178+
vnoremap <C-S-K> :m-2<CR>gv=gv
179+
```
180+
181+
### Custom Vim commands
182+
183+
In this section we present a list of all custom vim commands that are supported to perform different operation in CP Editor.
184+
185+
| Command | Shorthand | Description | Usage |
186+
| :----------: | :-------: | :-----------------------------------------------------------------------------------------------------------------------: | :-------------------------: |
187+
| `new` | `new` | Opens a new tab, if no langauge is specified, a tab in default editor langauge will open | `new cpp` or `new` |
188+
| `open` | `opn` | Opens a new file, Only C++/Java/Python files will be opened. Without arguments it is same as open in Action menu. | `open` or `opn ~/cf/a.cpp` |
189+
| `compile` | `cmp` | Compiles the code, It is like clicking "Compile" button in a tab. | `compile` or `cmp` |
190+
| `crun` | `crn` | Compiles and run, It is like clicking "Compile and Run" button in a tab. | `crun` or `crn` |
191+
| `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` |
192+
| `drun` | `drn` | Detached run, It is same as clicking "Detached Run" in menu. | `drun` or `drn` |
193+
| `killall` | `kap` | Kill all process, It is same as clicking "Kill Process" in menu | `killall` or `kap` |
194+
| `format` | `fmt` | Format Code, It is same as clicking "Format Code" in menu | `format` or `fmt` |
195+
| `snippet` | `snp` | Open snippet dialog, It is same as clicking "Use Snippets" in menu | `snippet` or `snp` |
196+
| `vmode` | `vmd` | View mode, Changes the view mode. It can only toggle to "edit" and "split" mode | `vmode edit` or `vmd split` |
197+
| `preference` | `prf` | Preferences, It is same as clicking "Preference" in menu | `preference` or `prf` |
198+
| `chlang` | `chl` | Language, It can be used to change the language of a tab. | `chlang cpp` or `chl java` |
199+
| `clear` | `clr` | Clear Message logger text | `clear` or `clr` |
200+
| `exit` | `ext` | Exit, It is same as pressing "Quit" in menu. | `exit` or `ext` |

content/docs/tips/_index.md

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ You can use <kbd>Ctlr+Tab</kbd> and <kbd>Ctlr+Shift+Tab</kbd> to go through the
7070

7171
You can set a hotkey for switching view modes in [Preferences](../preferences/key-bindings/\_index.md).
7272

73+
## Vim Emulation
74+
75+
You can enable vim emulation in code editor. Most [basic vim commands](../preferences/code-edit/_index.md#vim-commands) and some [custom vim commands](../preferences/code-edit/_index.md#custom-vim-commands) to perform various actions are supported. Many code editor settings like Tab width, Indentation, Current Line Highlight etc are disabled when using vim mode, you have to customize them from [Vim Configuration](../preferences/code-editing/_index.md#vim-configuration).
76+
77+
You can switch to next or previous tab using `tabn` and `tabp` respectively.
78+
7379
## Launch CP Editor in the command line
7480

7581
CP Editor supports some command-line options, run `cpeditor --help` for more information.

0 commit comments

Comments
 (0)