Vim - kamialie/knowledge_corner GitHub Wiki

Abbreviation:
- <> tags refer to user input:
-
<number>- insert number consisting [0-9] -
<symbol>- alphanumber symbol
-
- [argument | argument] - or, choose one of the options enclosed in square brackets
-
[:w]- save file -
[:q!]- quit without saving changes -
[:w] <file_name>- save current buffer as file_name -
[:e]- edit specified buffer (can not switch to those with:nand:N) -
[:b] <file_name>- opens specified buffer, auto-completion works as well (can use buffer number instead of file name as well) -
[:bn]- go to next buffer -
[:bp]- go to previous buffer -
[:bd] <file_name>- delete buffer -
[:ls]- list buffers -
[:vs]- open new buffer vertically -
[:sp]- open new buffer horizontally -
[Ctrl][w] [arrows | [hjkl] | w]- move to another buffer -
[Ctrl][w] [Shift] [hjkl]- move current buffer elsewhere -
[Ctrl][w] <number> [+ | -]- increase/decrease the size of the current buffer -
[:tabe] <file>- open file in another tab (to open multiple files in tabs add -p flag)-
[gt]- go to the next tab -
[gT]- go to previous tab -
<i>[gt]- go to ith tab
-
-
[:tabm] <number>- move current tab elsewhere -
[:tabs]- list all files in tabs -
[:tabo]- close all tabs except current -
[:tabc]- close current tab-
<i>- close ith tab
-
-
[qa]- close all buffers/tabs -
[:mks] <session_name>- save a session with tabs for next login- vim -S session_name - open session
- vim -p file1 file2 file3 - open 3 files at ones in tabs
-
[:mks!] <session_name>- save changes to session (if you added/deleted tabs) -
[:ls]- list current buffers -
[:buffers]- same as previous -
[:buffer] <n>- jump to nth buffer -
[:b]- go to the next buffer-
<substring>- unique filename substring will make it jump to that buffer
-
-
[ZZ]- save current file and exit (HACK!)
Open multiple file as follows:
$ vim file1 file2 file3Then navigate with :n and :N commands, to go to the next/previous respectivly
Open file at particular line (plust actually executes any vim command):
$ vim file +<i>Press while in normal mode:
-
[i]- under cursor -
[I]- at the beginning of line -
[a]- after cursor -
[A]- at the end of line -
[o]- new line under cursor -
[O]- new line above cursor -
[s]- delete character and insert -
[S]- delete line and insert
Press while in normal mode:
-
[w]- go to the beginning of next word -
[b]- go to the beginning of previous word -
[e]- go to the end of current(next) word -
[gg]- go to start of file -
[G]- go to end of file -
[Ctrl][e]- scroll down -
[Ctrl][y]-scroll up -
[Ctrl][d]- jump down half screen -
[Ctrl][u]- jump up half screen -
[Ctrl][f]- jump down full screen -
[Ctrl][b]- jump up full screen -
<number> [[gg] | [G]]- go to the specified line -
[-]- go the previous line (beginning) -
[+]- go to the next line (beginning) -
[0]- go to beginning of line -
[$]- go to end of line -
[^]- go to the first non blank character on the line -
[%]- go to matching bracket, quotes -
[f]<symbol>- go to specified symbol in the current line; then use[;]or[,]to more the next or previous one respectively -
[F]<symbol>- same as f, but backwards -
[t]<symbol>- same as f, but go to one symbol before specified -
[T]<symbol>- same as t, but backwards -
[H]- go to the top of the screen -
[M]- go to the middle of file -
[L]- go to the last line -
[z]-
[z]- center current line -
[t]- make current line the top most -
[b]- same as above but bottom most
-
-
[Ctrl][o]- go to the previous jump (be careful with what is considered to be a jump in vim - hjkl are not jumps) -
[Ctrl][i]- go to the next jump -
[K]- find a reference to the function under cursor
Jump history
-
[:jumps]- view history -
[Ctrl][i]- go to next jump -
[Ctrl][o]- go to previous jump
-
[r] <letter>- replace letter under cursor -
[R]- enter replace mode, every typed character deletes existing one -
[v]- enter visual mode -
[Shift][v]- enter visual line mode -
[Ctrl][v]- enter visual block mode -
[C]- erase from cursor till end of line and enter insert mode -
[cc]- erase current line and enter insert mode -
[ce]- delete current word and go to insert mode -
[d]- delete operator-
[w]- until next word, excluding first character -
[e]- until next word, including first character -
[i]- inside; for exampledi“- delete everything inside quotes; works the same with[c]-
[p]- paragraph -
[t]- tags -
["]- quotes
-
-
-
[[yy] | [Y]]- copy current line -
[[dd] | [D]]- cut current line -
[[y] | [d]]- copy or cut-
[[j] | [arrow down]]- current and line below -
[[k] | [arrow up]]- current and line above
-
-
[:]<start>[,]<end>[[y] | [d]]- copy or cut line between lines start and end (included); you can also copy/cut till label - just create a label somewhere, then use[y][']<label> -
[p]- paste line under cursor -
[Shift][p]- paste line before cursor ([g][Shift][p]- paste before cursor and move to the next line) -
[x]- cut character under cursor -
[“]<letter>[command]- specify the buffer for the command-
[\_]- underscore, empty buffer
-
-
<number>[operation]- do operation number of times -
[.]- repeat last operation in a whole -
[:read] <filename>- yank and paste everything from specified file into current buffer; can prefix command with line number (including-1, previous line) to specify where to paste the content - While in insert mode:
-
[Ctrl][r]<register>- insert text from specified register (register is any lowercase letter) -
[Ctrl][r][a]- insert text from dot register (dot register holds last modification you made in insert mode
-
-
[J]- append line below to the current (physically move it)
Use of registers - ["][any lower or upper case letter][command] will copy to
or paste from that register
-
[*]- go to next occurence of the word under cursor; also highlights all occureneces -
[/]<text>- got to the first character of first occurence of text in file starting from cursor location-
[\c]- turn on ignore case search for just one search -
[n]- go to next occurence -
[N]- go to previous occurrence
-
-
[?]<text>- same as previous, but backwards -
[:][s][/]<old>[/]<new>- substitute first occurrence ofoldbynew(type[%]beforesfor entire file)-
[/]- additional options, concatinate to command command (above); options below can be used separetely or together-
[g]- all in current line -
[c]- confirm before doing -
:s/i/o/gc- substitute all occurences ofibyoin the current line and ask confirmation before doing each substitution
-
-
-
[:]<number>[,]<number>- apply next operation in between lines specified -
[:noh]- turn off highlighting
Abbreviation
-
[:abb] <abbreviation> <exp>- create anabbreviationwhich will be expanded toexp
Type abbreviation, press space and it will be automatically expanded. Press
Ctrl-v and then space to avoid expansion.
-
[u]- undo last command -
[U]- return current line to its original form -
[Ctrl][r]- undo undos
Highlight region in vim, then [[:][fold] | [zf]] - fold lines
fo - is short for fold
-
<number>[,]<number>[fo]- same as previous, folder in between lines specified (toggle is same) -
[,][+]<number>[fo]- fold current line and lines passed relative to it (below it) - [mb][%][zf’b] - fold lines !dont try this, needs checking!
-
[za]- open/close toggle -
[zo]- open folding -
[zc]- close folding -
[zd]- delete folding -
[m][any_lowercase_character]- create local mark -
[m][any_uppercase_letter]- create global mark -
['][label]- go to the mark created before (single quote or backtick);.(dot) is an automatic mark, which is last place where a change was made-
['][']- go to last jump
-
-
[q]<letter>[command sequence][q]- record macros-
[@]<letter>- apply to the current cursor location -
[@@]- rerun last macros
-
-
[[Ctrl][N] | [Ctrl][P]]- autocomplete -
[Ctrl][X] [Ctrl][N]- autocomplete only in current file -
[Ctrl][X] [Ctrl][F]- autocomplete for filenames
-
[[Operation]<count>[motion]]- for example, [d2w] - deletes next two words -
[:!][shell_command]- run shell command within vim -
[:make]- trigger make within your vim! -
[Ctrl][R][=][expression]- calculator in vim!!! Use it in insert mode - result will be printed in file -
anything preceded with
+in command line will be interpeted as a vim command; example removing first two lines in a file:$ vim +1,2d +wq file.txt
-
vim -d file1 file2- open two files with vim in diff mode;do- diff obtain,dp- diff put; from within vim[:diffsplit] <filename>or[:vert] [diffsplit] <filename>;[:set] [diffopt]- check diff options;[:set] dip+=vertical- make vertical split the default -
[g][f]- open file while on the filename in vim; can even do on URLs! (if you have wget or curl installed) -
[g][Shift][f]- open file on the specified column and row (if it is in the following format -hello.txt:10:22, fe, complier error) -
[r] [!][ls]- insert output of command into current buffer -
[%][!] [jq][.]- runjqon current file (THIS IS CRAZY)
-
[:help] [user]- open endless manual -
[Ctrl][]]- jump into topic -
[Ctrl][o]- go back
-
]s[s- move to misspelled word -
z=- open suggestions list -
zg- add word to vim's dictionary -
zw- mark word as incorrect
-
[:set]- view all current settings -
[:help] option-summary- all available options -
[:set] [clipboard=unnamedplus]- connect system and vim clipboards
Steps to get started
-
:packadd termdebug- load the plugin -
:Termdebug- start debugging -
(gdb) file a.out- load the program (alternatively pass a.out to the command above)
(gdb) quit - quit debugger
-
(gdb) next,:Over- execute current line and stop at the next line -
(gdb) step,:Step- execute current line and stop at the next statement, entering functions -
(gdb) finish,:Finish- execute until leaving the current function -
(gdb) where,:Break- show the stack -
(gdb) frame <N>- go to Nth stack frame -
(gdb) continue,:Continue- continue execution -
CTRL-C,:Stop- interrupt the program -
(gdb) print,:Evaluate:Ev- evaluate expression under cursor
-
:Gdb- jump to gdb window -
:Program- jump to program window -
:Source- jump to source code window or create one -
:Break- set a breakpoint at the current line -
:Clear- delete a breakpoint at the current line
Create your own shortcuts that will work in any window using TermDebugSendCommand() function, which takes gdb command as argument:
map ,w :call TermDebugSendCommand('where')<CR>- https://medium.freecodecamp.org/learn-linux-vim-basic-features-19134461ab85
- http://vim.wikia.com/wiki/Mapping_keys_in_Vim\_-\_Tutorial\_(Part_2)
- http://learnvimscriptthehardway.stevelosh.com/chapters/07.html
- https://hashrocket.com/blog/posts/8-great-vim-mappings
- https://www.shortcutfoo.com/blog/top-50-vim-configuration-options/
- https://dougblack.io/words/a-good-vimrc.html
- https://stackoverflow.com/questions/736701/class-function-names-highlighting-in-vim
- https://stackoverflow.com/questions/29192124/how-to-color-function-call-in-vim-syntax-highlighting
- https://stackoverflow.com/questions/736701/class-function-names-highlighting-in-vim
- https://stackoverflow.com/questions/37777417/how-to-use-vim-key-bindings-with-visual-studio-code-vim-extension - exit key mapping in vscode for vim extension:
- http://vimdoc.sourceforge.net/htmldoc/options.html#'statusline', http://vimdoc.sourceforge.net/htmldoc/windows.html#status-line - status line