Skip to content

Instantly share code, notes, and snippets.

@danielkec
Last active April 24, 2024 09:51
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save danielkec/4381b4c9af47a344b90263c41cac6e66 to your computer and use it in GitHub Desktop.
Save danielkec/4381b4c9af47a344b90263c41cac6e66 to your computer and use it in GitHub Desktop.
LazyVIM

Default shortcuts

Ctrl+h        select file tree
Ctrl+l        select file editor
Shift+h       left editor tab
Shift+l       right editor tab
Alt+j         move current line up
Alt+k         move current line down
double space  filename search(telescope) - `Ctrl+d` and `Ctrl+u` to scroll preview
gg=G          reindent - gg goes to the top of the file, = fixes the indentation and G to perform to the end
gc            comment selected(`gcgc` no select to uncomment block)
%             jump to other bracket of the current block
_             jump to the first non blank char on the line
$             jump to the last non blank char on the line
0             jump to the start of the line
\text         seach for text, `n` for next occurence, `N` for previous
f"            find first `"`, jump to it with right arrow
ci"           delete and start editing inside of the next string literal
vi"           select inside of the next string literal
viw           select current word
di"           delete inside of the next string literal
u             undo
Ctrl+r        redo
ma            set local mark `a`
mA            set global mark `A`
`             list marks
`a            go to mark `a`

Visual mode

Character mode - `v`
Line mode - `V`
Block mode - `Ctrl+v`

`u`- lowercase
`U`- uppercase
`d`- delete
`c`- change
`y`- yank
`>`- indent
`<`- dedent

Neo-tree

r           rename
m           move
o           order by
i           file details
v           available shortcuts 
Ctrl+rarrow  expand tree to right
Shift+h     Toggle show hidden files

Installation

sudo apt-get install neovim
git clone https://github.com/LazyVim/starter ~/.config/nvim
rm -rf ~/.config/nvim/.git

Nerd font JetBrains

wget -P ~/.local/share/fonts https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.2/JetBrainsMono.zip \
&& cd ~/.local/share/fonts && unzip JetBrainsMono.zip && rm JetBrainsMono.zip && fc-cache -fv

Tmux

Ctrl+b + %   vertical split
Ctrl+b + "   horizontal split
Ctrl+b + x   close current panel
Ctrl+b + q   show panel nums
Ctrl+b + q + 1 switch to panel 1

Tips & Tricks for Vim/NeoVim

Keyboard Shortcuts

Be aware the following shortcuts are only working, if you have the plugins installed mentioned below.

In Command Mode:

:w              Save file
:w filename     Save file under new filename
:q              Quit file
:<tab>          Show commands
i               Switch to INSERT mode
R               Switch to REPLACE mode to overwrite text
v               Switch to VISUAL mode
V               Switch to VISUAL LINE mode
<ctrl>v         Switch to VISUAL BLOCK mode
o               Insert a new line below the current line and go to INSERT mode
O               Insert a new line above the current line and go to INSERT mode
x               Delete character under the cursor
X               Delete character left of the cursor
dd              Delete current line
dw              Delete current word
D               Delete to the end of the line
<esc>           Leave current mode
/               Search for text
$               Go to the end of the line
gcc             Comment out a line
<ctrl>r         Redo last change
<ctrl>g         Show file info
<space>e        Toggle FileTree
<space>n        Toggle line numbers
<space>w        Toggle line wrap  
<space>c        Toggle colorscheme dark/light
<space>t        Open terminal (close with esc)
:PlugInstall    Install plugins which are added to the ~/.config/nvim/init.vim

Surround

Change Surround: cs(alt)(neu)
cs"'            Changes " to ' surrounding
cs"<p>          Changes " to <p></p>
cst"            Changes *t*ags like <p></p> to "

Delet Surround: ds(alt)
ds"             Deletes " surrounding
dst             Deletes *t*ag linke <p></p>

Text search:

/               Search forward
?               Search backward
n               Repeat last search
s{char}{char}   Sneak search forward
s<enter>        Repeat last sneak search
f{char}         Jump to the next {char} right
fffff           Jump to next found

Search pattern for / and ?:
^blabla         Matches start of line
blabla$         Matches end of line
bl.bla          Placeholder for 1 character

Move Cursor:

0               To first character in the line
$               To end of line
G               To end of file
gg              To start of file
w               Word forward
b               Word backwards
)               Sentence forward
(               Sentence backwards
}               Paragraph forward
{               Paragraph backwards

Sessions:

:SSave          Save a session
:SLoad          Load a session
:SDelete        Delete a session
:SClose         Close current session

Split window:

<ctrl><w>+s or :split   Split window horizontal
:vsplit                 Split window vertical
<ctrl><w>+n             Split window with new file
<ctrl><w>+q             Close current window
<ctrl><w>+w             Jump to upper/lower window
:sf filename            Open file in new window
:sf <tab>               Search file 

File Search:

<ctrl>p         Open fzf fuzzy search
<enter>         Open found file in current window
<ctrl>t         Open found file in tab split
<ctrl>s         Open found file in split  
<ctrl>v         Open found file in vsplit      

In INSERT mode

<esc>           Leave INSERT mode
<del>           Delete left
<fn><del>       Delete right
<ctrl>w         Delete word before cursor
<ctrl>u         Delete left until the end of line

In .html .xhtml .php files tags will be auto closed. If you want to format them to next line press > again after closing the tag.

VimWiki

<Leader>ww      Open default wiki index file.
<Leader>wt      Open default wiki index file in a new tab.
<Leader>ws      Select and open wiki index file.
<Leader>wd      Delete wiki file you are in.
<Leader>wr      Rename wiki file you are in.
<Enter>         Follow/Create wiki link on current text/selection.
<Shift-Enter>   Split and follow/create wiki link.
<Ctrl-Enter>    Vertical split and follow/create wiki link.
<Backspace>     Go back to parent(previous) wiki link.
<Tab>           Find next wiki link.
<Shift-Tab>     Find previous wiki link.

Plugins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment