fox0430 / moe

A command line based editor inspired by Vim. Written in Nim.
https://editor.moe
GNU General Public License v3.0
659 stars 34 forks source link

Most useful vim keys #633

Open tobimensch opened 4 years ago

tobimensch commented 4 years ago

Hello @fox0430,

I follow this project religiously, because I want to use a Nim-focused vim-like editor that is written in Nim, and hopefully can be extended with Nim.

I made a cheatsheet for myself, of what I think the most useful vim key combinations are, and maybe you can use this list to close some feature gaps in moe, the list focuses on vim key combinations that are beyond what a total vim beginner needs to learn. (so no h,j,k,l)

For normal mode:

<C-c> - switch to normal mode (downsides: 1) doesn't take care of abbreviations 2) doesn't work like ESC in visual block mode)
<C-o> - switch to normal mode for one command, then back to insert mode
@:    - repeat last Ex command
<C-z> - go from normal mode to the shell that started nvim/vim. puts nvim/vim in the background. Use fg in the shell to get back.
!{motion} - switch to command mode and populate range with motion to run a filter on.
  i.e !G in normal mode becomes :.,$!
  and !aB becomes something like :.,.+26!
<C-^> - go to alternate buffer/file
:'<,'>normal @a - execute macro a on a range
c%    - change matching parenthesis/brackets/etc. including their content
g&    - repeat last substitution but on the whole file, like :%s//~/&
gi    - insert text in the same position as last time
K     - view man page for word under the cursor
<C-g> - view current buffer's filename in Ex command line
_     - jump to first non-whitespace character on line (more comfortable than ^)
g_    - jump to last non-whitespace character on line (unlike $ that jump to last character)_X
n|    - move cursor to the nth column
X     - delete character before cursor (x deletes character at cursor)
ga    - show character info

Replacing text objects with new text:

ci                - change in(side) textobject
cis               - change inside sentence
cib or ci) or ci( - change inside parenthesis
ciB or ci} or ci{ - change inside {} brackets
cit               - change inside tags
ci] or ci[        - change inside [] brackets
ciw               - change inside word

Replacing text objects including surrounding delimiters:

ca                - change textobject including surrounding delimiters
cas               - change sentence including surrounding delimiters
cab or ca) or ca( - change parenthesis including surrounding delimiters
caB or ca} or ca{ - change {} brackets including surrounding delimiters
cat               - change tags including surrounding delimiters
ca] or ca[        - change [] brackets including surrounding delimiters
caw               - change words including surrounding delimiters

Deleting / Cutting text objects:

di                - del/cut in(side) textobject
dis               - delete inside sentence
dib or di) or di( - delete inside parenthesis
diB or di} or di{ - delete inside {} brackets
dit               - delete inside tags
di] or di[        - delete inside [] brackets
diw               - delete inside word

Del/cut textobject including surrounding delimiters:

da                - del/cut textobject including surrounding delimiters
das               - delete sentence including surrounding delimiters
dab or da) or da( - delete parenthesis including surrounding delimiters
daB or da} or da{ - delete {} brackets including surrounding delimiters
dat               - delete tags including surrounding delimiters
da] or da[        - delete [] brackets including surrounding delimiters
daw               - delete word including surrounding delimiters

Jumping around:

g;    - jump to previous change location in buffer
g,    - jump to next change location in buffer
<C-i> - jump to next jump location in buffer
<C-o> - jump to previous jump location in buffer
''    - jump between two latest jump locations

Inserting:

gP - like P, however cursor gets positioned at the end
gp - like p, however cursor gets positioned at the end

Indention:

== - auto indent current line

Reverting changes:

u             - normal undo
U             - undo all changes on current line
<C-r>         - redo
:ea           - go to earlier buffer state <example>:ea  5m<example>:ea  10s<example>:ea  2h<example>:ea  1d
:lat          - go to later buffer state <example>:lat 5m<example>:lat 10s<example>:lat 2h<example>:lat 1d
:changes      - view history of changes
:undolist
:e! or :edit! - revert back to saved/written file state - in other words: reloads buffer from disk discarding changes
g;            - jump to previous change location in buffer
g,            - jump to next change location in buffer
:MundoToggle  - shows tree of changes - requires mundo plugin

Finding and replacing:

gn   - go to next find position and select it visually
gN   - go to previous find position and select it visually
dgn  - go to next find position and delete it
dgN  - go to previous find position and delete it
cgn  - go to next find position and change it
cgN  - go to previous find position and change it
*    - find word under the cursor forwards
#    - find word under the cursor backwards
:noh - disable last search highlighting
/    - repeat last search forward
?    - repeat last search backward
\V   - verbatim
\c   - case insensitive

Managing windows:

<C-w> c, :q, ZZ  - close
:on              - keep only this window, close others
<C-w> h, j, k, l - move focus to window in direction
<C-w> H, J, K, L - move window into direction
<C-w> _          - increase current window size to maximum possible
<C-w> -, +, <, > - decrease/increase current window size
<C-w> =          - equalize window size
<C-w> n          - open new window with empty buffer
:windo           - do action on all windows

Managing buffers:

:bn             - go to next buffer
:bp             - go to previous buffer
:b {int}        - go to buffer by number
:b {string}     - go to buffer by part of the filename/path
:bd             - delete buffer
:bd {int}       - delete buffer by number
:bd {string}    - delete buffer by part of the filename/path
:bufdo          - do action on all buffers
:ls or :buffers - list buffers
:ene            - create new empty buffer
:new            - new empty buffer in split window

File explorer:

:ex or :e. - open
:sp.       - open in horizontal split window
:vs.       - open in vertical split window
%          - create file

Visual mode and going there:

gv         - reselect last visual selection, in visual mode this jumps between the current selection and the previous one
<C-v>      - Go into visual block mode
p          - replace with current paste
S{",',...} - put current selection in quotes or other surrounding
U          - uppercasing
u          - lowercasing
~          - toggle case
r          - replace every character with same character
<C-g>      -  go from visual to visual select mode, it still looks like visual mode, but it takes different commands, resembling the selection mode in Microsoft Windows

In normal visual mode:

S<SP><SP> - put spaces before and after current selection

Visual block mode:

I - insert text before visual block and repeat it on all lines
A - insert text after visual block and repeat it on all lines

Insert mode:

<C-c>                  - back to normal mode
<C-e>                  - copy character on line below
<C-y>                  - copy character on line above
<C-w>                  - delete current word
<C-u>                  - delete current line up to indent
<C-h> or <BS>          - delete character before the cursor
<C-t>                  - insert one shiftwidth of indent
<C-d>                  - delete one shiftwidth of indent
<C-i> or <Tab>         - insert tab
<C-r>                  - insert the content of a register
<C-r> =                - use and insert expression register
<C-a>                  - insert previously inserted text
<C-@>                  - insert previously inserted text and go back to normal mode
<C-j> or <NL> or Enter - new line

Replace mode - insert mode keys work here too:

r, R, gr, gR, <INS> - enter mode, gr and gR are virtual replace modes, meaning that tabs and the like get treated like multiple characters

Registers:

"0 - the last yank - is only set by y command, not by d, c or others
"" - the unnamed register - default register - is set by all of the above
": - command
"/ - search
". - the last insert (can be inserted with <C-a> or <C-@>(this one returns to normal mode) in insert mode)

Search patterns / vim's regex:

/v - very magic search -> it's more like perl/python, you don't need to escape ({ and other magic characters
/V - very not magic -> verbatim. Here you need to escape everything that's supposed to be magic.
default - you need to escape ( and {, but not [
/zs - positive lookaround expressions for begin. Set the beg/end boundaries of a match.
/ze - positive lookaround expressions for end. Set the beg/end boundaries of a match.

Repeating:

.  - repeat last edit - n times
@: - repeat last Ex command - n times
@@ - repeat last macro - n times
/  - repeat last search forward
?  - repeat last search backward
n  - repeat last search in search direction
N  - repeat last search backward in search direction
gn - repeat last search and select match in visual mode, forward
gN - repeat last search and select match in visual mode, backward

Folding:

:set foldmethod=syntax
:se fdm=syntax
zM - fold everything
zn - open all folds
zx - open fold under the cursor, fold everything else
za - toggle fold under the cursor
zA - toggles recursively, good to open fold and subfolds
zO - open folds recursively

Tags:

<C-]> or gd - go to definition
<C-t>       - jump back the tags list (reverse of <C-]>)

Session management:

:mksession[!] [file], :mks - make a new session - file defaults to Session.vim ! allows to overwrite file
:source file               - restore session
vim -S file                - load session from file

Command line mode:

gQ                    - go into Ex mode and stay there until you type "visual"
q:                    - go into command line mode and edit using normal mode - history of Ex commands
q/                    - go into command line mode and edit using normal mode - history of searches
<C-f>                 - edit using normal mode
<C-d>                 - get list of suggestions
<Tab>                 - complete/cycle suggestions
<C-r><C-w>            - get word under the cursor
:g/pattern/command    - do action on all lines containing pattern
:!{cmd}               - execute cmd in the shell
:read !{cmd}          - read output of shell cmd into buffer
:write !{cmd}         - use buffer as input for shell cmd
:[range]!{filter/cmd} - use [range] as input for shell command and replace range with the cmd's output
:source script.vim    - execute vim script
:e path               - edit file
:e dir                - view dir in file explorer
:E                    - file explorer
:SExplorer            - open file explorer in horizontal window
:VExplorer            - open file explorer in vertical window
:find or :fin         - find files in directories set in path. Add directories to path with set path+=path/to/dir
:find **/source.ext   - find in all subdirectories
:echo or :e           - echo <example>:ec &path - shows contents of path variable
:cfdo                 - execute normal mode command on all buffers in quickfix list
:argdo                - same as cfdo, but on buffers in argslist
:bufdo                - on all buffers
:update               - save file, but only if there was a change
:put =execute(cmd)    - put Ex command output <example>:put =execute('map') - put map Ex command into buffer

Settings:

:set relativenumbers
:set numbers
:set showtabline or :set stal=0 - buffer as tabs in SpaceVim/nvim, =0 hides tabline always
:set laststatus=0               - disable status line of bottom windows

Settings autocomplete:

:let g:asyncomplete_auto_popup=0 - disable automatic popup menus when typing

A few of these may be related to plugins, whose functionality I like such as mundo, but I'd not expect you to imitate its features 1 to 1. I think the vast majority I listed work in vim/nvim without plugins.

fox0430 commented 4 years ago

@tobimensch

Thank you for the requests ! I would like to add those features to moe as much as possible.

tobimensch commented 4 years ago

@fox0430 Very nice to hear, thank you!

I've reformated the list to be easier to read.