💡Neovim

https://neovim.io/

The Basics

Installation

https://github.com/neovim/neovim/wiki/Installing-Neovim

sudo nano ~/.bashrc
alias nvim=/home/ubuntu/nvim.appimage

Commands

  • hjkl Right, Up, Down, Left

Visual mode
  • v for visual mode

  • shift + v for visual line mode

  • cntr + shift + v for visual block mode

Command mode
  • :w file.txt - Save file

  • :q - Quit

  • :qw - Quit and write the file

  • :q! - If you change file you can quit and ignore changes

  • :e file.txt - Open the file or create a new file with such name

  • :enew - Create empty environment

  • :e - Get back to the oldest saved changes

Buffer
  1. Open files by typing e

  2. Execute command ls - you see all files

  • b 1 - open file with 1

  • b file2.txt - open file

  • cntr + 6 - switch between buffers files

  • sp - split files horizontal

  • vs - split files vertical

  • :close - close window

  • cntr + hjkl - run between windows

  • tabnew - open new terminal

  • tabp - open previous terminal

  • wqa - write and quit all

  • wa - write all

  • qa - quit all

Motions, Commands, Text Objects
  • o

  • $

  • shift + i

  • shift + a


  • cntr + g - see current directory

  • shift + g - jump to the last line

  • g + g - jump to the first line

  • <numeric number> + g - jump to the numeric code

  • % - matching parenthess search


  • w - move forward to the beginning of word

  • b - move back to the beginning of word

  • shift + w - move forward to the beginning of word only by spaces

  • e or shift + b - move back to the beginning of word only by spaces

  • 0 - to come back to the beginning of editor

  • ^ - to come back to the beginning of editor except spaces

  • $ - to come back to the end of editor


  • u - undo

  • cntr + r - redo


  • f + letter - go to the word starts from letter

  • t + letter - go to before where the word starts from letter

  • ; - go to the next letter

  • , - go to the previous letter

  • . - repeat


  • / + word - search word

  • n - go to next word

  • shift + n - go to previous word

  • :noh - clear

  • * - search the word

  • % - toggle between pairs


  • i - insert mode

  • a - insert mode after

  • o - insert mode below line

  • shift + o - insert mode above line

  • shift + i - insert to the beginning of line

  • shift + a - insert to the end of line


  • x - delete symbol

  • d + w - delete word

  • d + shift + w - delete with coma or specifies symbols

  • d + ^ - delete all until the beginning

  • d + $ or shift + d - delete all until the ending

  • d + t + , - delete all until the coma

  • d + d - delete full line

  • 4 + d + d - delete for lines

  • c + w - delete word and go to insert mode

  • c + t + , - change until the come

  • c + c - change entire line

  • shift + c - change until at the end of line

  • yw - copy word with space

  • yy - copy the whole line

  • p - paste

  • shift + p - paste above the current line

  • 5 + p - paste 5 times


Text Object
  • v + i + w - select whole word with space

  • v + a + w - select whole word without space

  • d + a + w - delete around word

  • d + i + w - delete inside word

  • v + i + ) - select all until this parentheses in visual mode

  • v + a + ) - select all until these parentheses around in visual mode

  • :Tutor - It is tutorial to help you all functionality in neovim, type in command mode

Digging Deeper

Plugins

Kitty

All settings of kitty is in ./config/kitty

  • kitty list-fonts - get a list of all fonts in your machine

  • kitty +kitten themes - change your theme in kitty

Tmux
  • (cntr + b) + c - open new windows

  • (cntr + b) + 0 - switch to zero window

  • (cntr + b) + p - switch to previous window

  • (cntr + b) + n - switch to next window

  • (cntr + b) + % - split window

  • (cntr + b) + arrow key - switch between split window

  • (cntr + b) + : - open tmux command

  • :new-session -s laracasts - create new session with laracasts name

  • (cntr + b) + s - open a list of sessions

  • (cntr + b) + d - detach session (quit from tmux)

  • (cntr + b) + x - close the split window | delete window

  • cntr + d- delete window

  • tmux kill-server - kill all saved sessions

  • :kill-session - kill session

In .tmux.conf - all (cntr + b) changed to (cntr + space)

My custom commands:

  • (cntr + space) + space - switch between two recent windows

  • (cntr + space) + ^ - switch between two recent sessions

  • (cntr + space) + F - have to search and open projects

Lazy
  • :Lazy - open lazy

Git Integration
  • [ + h - up to git changes in file

  • ] + h - down to git changes in file

  • g + p - see previous changes

  • g + b - see who made a commit

  • :G blame - blame in right on every line. And we can press enter to pull into

  • :GBrowse - open a github page

  • :Gvdiffsplit - show changes of current file

  • :G difftool -y - see all diff changes

  • :tabo - quit from difftool

  • :G log - see git log and

    • ]] - jump between commits

    • O - to see changes in commit

  • :Gvdiffsplit! - solve merge conflict

    • ]c

    • d2o - get changes from the left window

    • d3o - get changes from the right window

  • :Telescope git_commits - show all commits

Key Mapping
  • :set wrap - the line set limit by your screen

  • gk or gj - go to the next line in wrap

  • < or > - in visual mode to 4 space on line

  • my mark the point then go to any another line and `y you will go back to mark

  • ;; - add ; to the end of the line in insert mode

  • ,, - add , to the end of the line in insert mode

  • Space + k - clean from search

  • Space + x - open file in the browser

  • shift + jk - transfer line up or down (do not work)

Comments (tpope/vim-commentary)
  • gcc - make a comment

  • 5gcc - comment 5 lines

Simple Plugins

tpope/vim-surround

  • cs'" - change ' on "

  • cs'<bold> - change ' on <bold>

  • cstt<bold> - change html tag on bold

  • dst - delete <bold> and </bold>

tpope/vim-repeat

  • . - can repeat plugins command (for example change <bold>)

vim-textobj-xmlattr

  • vix - surround html attribute

  • vax - surround html attribute including space

neoscroll.nvim

  • cntr + u - beautifull scrooll up

  • cntr + d - beautifull scrooll down

bufdelete.nvim

  • Space + q - analog :Bdelete

floaterm

  • cntr + s - open terminal

File Navigation

telescope

  • :Telescope - open telescope all commands

  • Space + f - search find files

  • Space + F - search all files

  • Space + b - search buffers files

  • Space + g - search inside text files

  • Space + h - search history files

  • Space + s - search lsp files

  • rg telescope . - find all telescope word in current directory (in console)

  • cntr + k - type the word in search and execute this hotkeys, wrap the word into " (in grep search)

  • cntr + k - type the word in search and execute this hotkeys, wrap the word into " and add --iglob (in grep search)

  • "telescope" - tlua - show telescope in .lua files (in search)

  • "telescope" - tlua nvim/lua - show telescope in .lua files in nvim/lua direcory (in search)

nvim-tree (https://github.com/nvim-neo-tree/neo-tree.nvim)

Full example from doc

  • :NvimTreeOpen - open nvim tree

  • a - create a new file or directory in nvim tree

  • m - move file

  • r - rename file

  • Space + n - toggle nvim tree

  • x - cut file/folder

  • y - copy file/folder

  • p - paste file/folder

  • d - delete file/folder

  • q - quit

  • t - open tab new

  • R - refresh

  • i - show file details

  • ? - show help

  • shift + < - switch between Files, Buffer and Git

  • Shift + p - preview file

  • o - order by ...

neo tree

  • :h neo-tree-git-status - get status by git icons

Find and Replacement
  • %s/gray/slate/g - change all gray to slate in the file

  • %s//font-medium/g - change all searching string to font-medium in the file

  • %s/text-sm/text-lg/gc - change all text-sm to text-lg in the file with confirmation on all finding string

  • + v - (without %) in visual mode you can do all previous commands in select by visual mode

  • Space + g then cntr + q - you can see a list of finds in files

  • [ + q - jump to the previous

  • ] + q - jump to the next

  • :cdo - do changes

  • :cfdo - do changes globally

  • :ccl - close

  • :cnext - next analog jump to the next

  • :cdo s/max-w-7xl/max-w-6xl - change max-w-7xl in finding files to max-w-6xl

Tree seeter

https://github.com/nvim-treesitter/nvim-treesitter

  • vaa - select the first argument of function including comma

  • via - select the first argument

  • vif - select all inside function

  • vaf - select full function

  • daa - delete ...

Language Server Protocol (LSP)
  • :Lspinfo - get info about LSP in current file

  • gd - go inside of function

  • cntr + o - jump back

  • cntr + i - go inside of function

  • K - see the information about method (press K twice go to inside buffer)

  • Space + d - show the error message in buffer

  • [ + d - jump between errors

  • ] + d - jump between errors

  • ga

  • gi

  • gr

  • Space + l + r

  • Space + r + n

Formatting:

nvim autoformat by settings in lspconfig.lua file

Phpactor

Doc

Refcators

  • Space + p + m - cursor on class and get a lot of options

  • Space + p + n - create an empty class, use it combination and choose template

Class has many commands such :PhpactorClassNew

Snippets

Snippets is in nvim/snippets/php.snippets

Press Tab when write snippets

Projection List
  • :A - In controller will create Unit test

  • :Emigration - find the migration

  • :Econtroller - find the controller

  • :Econtroller SomeContoller - find or create the controller

  • :Start - start php artisan serve in new buffer

  • :Console - start php tinker

Vim-test
  • Space + t + n - run the nearest test

  • Space + t + f - run the test in entire file

  • Space + t + s - run all tests

  • Space + t + l -

  • Space + t + v -

Automating Repetitive Changes
  • Cntr + a - increment the number

  • Cntr + x - decrement the number

  • 1899 + Cntr + a - change number to 1899

  • g + Cntr + a - in visual mode increase every number by 1 after previous

Spell
  • z= - type word and type command and you will get a list of suggestions

  • [s or ]s - go to wrong word (red line)

  • zg - add word into dictionary

Refactoring

Github

  • :Refactor - command for plugin

  • Space + r + e - :Refactor extract

  • Space + r + f - :Refactor extract_to_file

  • Space + r + v - :Refactor extract_var

  • Space + r + i - :Refactor inline_var

  • Space + r + I - :Refactor inline_func

  • Space + r + b - :Refactor extract_block

  • Space + r + bf -:Refactor extract_block_to_file

Others:

  • Cntr + o - move back buffer

  • Shift + s - in nvim tree open file

  • f "User.php" - find path of this file in console

Last updated