Skip to content

docs(Fakevim): Add Vim docs and tips #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Code Edit"
title: "Code Editing"
weight: 10
---

Expand Down Expand Up @@ -41,3 +41,15 @@ You can choose the parentheses to jump out by Tab in the [Parentheses](../langua
When you insert an indent, insert spaces instead of a tab character. The number of spaces is equal to the [Tab Width](#tab-width).

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).

### Highlight Current line

If enabled, the current line number will be highlighted from the rest of the lines. In vim mode current line is never highlighted.

### Enable Vim emulation

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](../general/_index.md#custom-vim-commands) is a list of all supported custom vim commands.

### Vim configuration

The configuration to use in vim mode. The list of all supported vim commands are listed [here](../general/_index.md#vim-commands)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Code Edit"
title: "Code Editing"
weight: 10
---

Expand Down
149 changes: 149 additions & 0 deletions content/docs/preferences/general/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,152 @@ The [regular expression](https://en.wikipedia.org/wiki/Regular_expression) is us
You can find many online regex cources, for example: <https://regexone.com/>.

In CP Editor, you can use `\1`, `\2`, etc. for the content of the first/second capture group in the replacement patterns.

### Vim Commands

#### Supported Features

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.

Here is list of emulated commands with description where it can diverge from Vim in functionality.

#### Modes

- normal
- insert and replace
- visual
- command line (`:`)

#### Normal and Visual Modes

- basic movement -- `h`/`j`/`k`/`l`, `<C-U>`, `<C-D>`, `<C-F>`, `<C-B>`, `gg`, `G`, `0`, `^`, `$` etc.
- word movement -- `w`, `e`, `b` etc.
- "inner/a" movement -- `ciw`, `3daw`, `ya{` etc.
- `f`, `t` movement
- `[`, `]` movement
- `{`, `}` -- paragraph movement
- delete/change/yank/paste with register
- undo/redo
- `<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")
- `.` -- repeat last change
- `/search`, `?search`, `*`, `#`, `n`, `N` -- most of regular expression syntax used in Vim except `\<` and `\>` just is the same as `\b` in QRegExp
- `@`, `q` (macro recording, execution) -- special keys are saved as `<S-Left>`
- marks
- `gv` -- last visual selection; can differ if text is edited around it
- indentation -- `=`, `<<`, `>>` etc. with movement, count and in visual mode
- "to upper/lower" -- `~`, `gU`, `gu` etc.
- `i`, `a`, `o`, `I`, `A`, `O` -- enter insert mode
- scroll window -- `zt`, `zb`, `zz` etc.
- wrap line movement -- `gj`, `gk`, `g0`, `g^`, `g$`

#### Command Line Mode

- `:map`, `:unmap`, `:inoremap` etc.
- `:source` -- very basic line-by-line sourcing of vimrc files
- `:substitute` -- substitute expression in range
- `:'<,'>!cmd` -- filter through an external command (e.g. sort lines in file with `:%!sort`)
- `:.!cmd` -- insert standard output of an external command
- `:read`
- `:yank`, `:delete`, `:change`
- `:move`, `:join`
- `:20` -- go to address
- `:history`
- `:registers`, `:display`
- `:nohlsearch`
- `:undo`, `:redo`
- `:normal`
- `:<`, `:>`

#### Insert Mode

- `<C-O>` -- execute single command and return to insert mode
- `<C-V>` -- insert raw character
- `<insert>` -- toggle replace mode

#### Options (:set ...)

- `autoindent`
- `clipboard`
- `backspace`
- `expandtab`
- `hlsearch`
- `ignorecase`
- `incsearch`
- `indent`
- `iskeyword`
- `scrolloff`
- `shiftwidth`
- `showcmd`
- `smartcase`
- `smartindent`
- `smarttab`
- `startofline`
- `tabstop`
- `tildeop`
- `wrapscan`

#### Example Vimrc

```vimrc
" highlight matched
set hlsearch
" case insensitive search
set ignorecase
set smartcase
" search while typing
set incsearch
" wrap-around when searching
set wrapscan
" show pressed keys in lower right corner
set showcmd
" tab -> spaces
set expandtab
set tabstop=4
set shiftwidth=4
" keep a 5 line buffer for the cursor from top/bottom of window
set scrolloff=5
" X11 clipboard
set clipboard=unnamed
" use ~ with movement
set tildeop

" mappings
nnoremap ; :
inoremap jj <Esc>

" clear highlighted search term on space
noremap <silent> <Space> :nohls<CR>

" reselect visual block after indent
vnoremap < <gv
vnoremap > >gv

" MOVE LINE/BLOCK
nnoremap <C-S-J> :m+<CR>==
nnoremap <C-S-K> :m-2<CR>==
inoremap <C-S-J> <Esc>:m+<CR>==gi
inoremap <C-S-K> <Esc>:m-2<CR>==gi
vnoremap <C-S-J> :m'>+<CR>gv=gv
vnoremap <C-S-K> :m-2<CR>gv=gv
```

### Custom Vim commands

In this section we present a list of all custom vim commands that are supported to perform different operation in CP Editor.

| Command | Shorthand | Description | Usage |
| :----------: | :-------: | :-----------------------------------------------------------------------------------------------------------------------: | :-------------------------: |
| `new` | `new` | Opens a new tab, if no langauge is specified, a tab in default editor langauge will open | `new cpp` or `new` |
| `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` |
| `compile` | `cmp` | Compiles the code, It is like clicking "Compile" button in a tab. | `compile` or `cmp` |
| `crun` | `crn` | Compiles and run, It is like clicking "Compile and Run" button in a tab. | `crun` or `crn` |
| `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` |
| `drun` | `drn` | Detached run, It is same as clicking "Detached Run" in menu. | `drun` or `drn` |
| `killall` | `kap` | Kill all process, It is same as clicking "Kill Process" in menu | `killall` or `kap` |
| `format` | `fmt` | Format Code, It is same as clicking "Format Code" in menu | `format` or `fmt` |
| `snippet` | `snp` | Open snippet dialog, It is same as clicking "Use Snippets" in menu | `snippet` or `snp` |
| `vmode` | `vmd` | View mode, Changes the view mode. It can only toggle to "edit" and "split" mode | `vmode edit` or `vmd split` |
| `preference` | `prf` | Preferences, It is same as clicking "Preference" in menu | `preference` or `prf` |
| `chlang` | `chl` | Language, It can be used to change the language of a tab. | `chlang cpp` or `chl java` |
| `clear` | `clr` | Clear Message logger text | `clear` or `clr` |
| `exit` | `ext` | Exit, It is same as pressing "Quit" in menu. | `exit` or `ext` |
8 changes: 4 additions & 4 deletions content/docs/preferences/language/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ When choosing a snippet, you can enter the first few characters of the snippet n

You can set the parentheses settings for each language and each parenthesis.

Each setting has three states: enable, disable and default. If it's default, it uses the settings in the [Code Edit](../code-edit/_index.md) page. Otherwise, it overwrites the settings in the [Code Edit](../code-edit/_index.md) page.
Each setting has three states: enable, disable and default. If it's default, it uses the settings in the [Code Editing](../code-editing/_index.md) page. Otherwise, it overwrites the settings in the [Code Editing](../code-editing/_index.md) page.

### Auto Complete

See [Code Edit/Auto Complete Parentheses](../code-edit/_index.md#auto-complete-parentheses).
See [Code Editing/Auto Complete Parentheses](../code-editing/_index.md#auto-complete-parentheses).

### Auto Remove

See [Code Edit/Auto Remove Parentheses](../code-edit/_index.md#auto-remove-parentheses).
See [Code Editing/Auto Remove Parentheses](../code-editing/_index.md#auto-remove-parentheses).

### Tab Jump Out

See [Code Edit/Jump out of a parenthesis by pressing Tab](../code-edit/_index.md#jump-out-of-a-parenthesis-by-pressing-tab).
See [Code Editing/Jump out of a parenthesis by pressing Tab](../code-editing/_index.md#jump-out-of-a-parenthesis-by-pressing-tab).
8 changes: 4 additions & 4 deletions content/docs/preferences/language/_index.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ When choosing a snippet, you can enter the first few characters of the snippet n

You can set the parentheses settings for each language and each parenthesis.

Each setting has three states: enable, disable and default. If it's default, it uses the settings in the [Code Edit](../code-edit/_index.ru.md) page. Otherwise, it overwrites the settings in the [Code Edit](../code-edit/_index.ru.md) page.
Each setting has three states: enable, disable and default. If it's default, it uses the settings in the [Code Editing](../code-editing/_index.ru.md) page. Otherwise, it overwrites the settings in the [Code Editing](../code-editing/_index.ru.md) page.

### Auto Complete

See [Code Edit/Auto Complete Parentheses](../code-edit/_index.ru.md#auto-complete-parentheses).
See [Code Editing/Auto Complete Parentheses](../code-editing/_index.ru.md#auto-complete-parentheses).

### Auto Remove

See [Code Edit/Auto Remove Parentheses](../code-edit/_index.ru.md#auto-remove-parentheses).
See [Code Editing/Auto Remove Parentheses](../code-editing/_index.ru.md#auto-remove-parentheses).

### Tab Jump Out

See [Code Edit/Jump out of a parenthesis by pressing Tab](../code-edit/_index.ru.md#jump-out-of-a-parenthesis-by-pressing-tab).
See [Code Editing/Jump out of a parenthesis by pressing Tab](../code-editing/_index.ru.md#jump-out-of-a-parenthesis-by-pressing-tab).
8 changes: 4 additions & 4 deletions content/docs/preferences/language/_index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ int main()

你可以为各编程语言设置相应的括号补全选项。

每个设置有三种状态:开启,关闭或默认。如果处于默认状态,将应用 [代码编辑](../code-edit/_index.zh.md) 中的设置,否则将会使用这里的设置。
每个设置有三种状态:开启,关闭或默认。如果处于默认状态,将应用 [代码编辑](../code-editing/_index.zh.md) 中的设置,否则将会使用这里的设置。

### 自动补全

详见 [代码编辑/自动补全括号](../code-edit/_index.zh.md#自动补全括号)。
详见 [代码编辑/自动补全括号](../code-editing/_index.zh.md#自动补全括号)。

### 自动删除

详见 [代码编辑/自动删除括号](../code-edit/_index.zh.md#自动删除括号)。
详见 [代码编辑/自动删除括号](../code-editing/_index.zh.md#自动删除括号)。

### 按 Tab 键跳出

详见 [代码编辑/在按下 Tab 键时跳出括号](../code-edit/_index.zh.md#在按下-tab-键时跳出括号)。
详见 [代码编辑/在按下 Tab 键时跳出括号](../code-editing/_index.zh.md#在按下-tab-键时跳出括号)。
6 changes: 6 additions & 0 deletions content/docs/tips/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ You can use <kbd>Ctlr+Tab</kbd> and <kbd>Ctlr+Shift+Tab</kbd> to go through the

Besides the shortcuts in the menu, you can use the [Read-only Key Bindings](https://doc.qt.io/qt-5/qtextedit.html#read-only-key-bindings) and the [Editing Key Bindings](https://doc.qt.io/qt-5/qtextedit.html#editing-key-bindings). There are also some hidden shortcuts: <kbd>Tab</kbd> (when there's a selection) and <kbd>Shift+Tab</kbd> for indent and unindent, <kbd>Ctrl+Enter</kbd> and <kbd>Ctrl+Shift+Enter</kbd> for inserting line after and before, <kbd>Shift+Delete</kbd> for deleting the current line.

## Vim Emulation

You can enable vim emulation in code editor. Most [basic vim commands](../preferences/general/_index.md#vim-commands) and some [custom vim commands](../preferences/general/_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).

You can switch to next or previous tab using `tabn` and `tabp` respectively.

## Drag and Drop

You can drag files and drop them into the main editor or the input/expected part of test cases.
Expand Down