π‘Neovim
https://neovim.io/
The Basics
Installation
https://github.com/neovim/neovim/wiki/Installing-Neovim
sudo nano ~/.bashrc
alias nvim=/home/ubuntu/nvim.appimageCommands
hjklRight, Up, Down, Left
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
Open files by typing
eExecute command
ls- you see all files
b 1- open file with1b file2.txt- open filecntr + 6- switch between buffers filessp- split files horizontalvs- split files vertical:close- close windowcntr + hjkl- run between windowstabnew- open new terminaltabp- open previous terminalwqa- write and quit allwa- write allqa- quit all
Motions, Commands, Text Objects
o$shift + ishift + a
cntr + g- see current directoryshift + g- jump to the last lineg + g- jump to the first line<numeric number> + g- jump to the numeric code%- matching parenthess search
w- move forward to the beginning of wordb- move back to the beginning of wordshift + w- move forward to the beginning of word only by spaceseorshift + b- move back to the beginning of word only by spaces0- 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- undocntr + r- redo
f + letter- go to the word starts fromlettert + letter- go to before where the word starts fromletter;- go to the next letter,- go to the previous letter.- repeat
/ + word- searchwordn- go to next wordshift + n- go to previous word:noh- clear*- search the word%- toggle between pairs
i- insert modea- insert mode aftero- insert mode below lineshift + o- insert mode above lineshift + i- insert to the beginning of lineshift + a- insert to the end of line
x- delete symbold + w- delete wordd + shift + w- delete with coma or specifies symbolsd + ^- delete all until the beginningd + $orshift + d- delete all until the endingd + t + ,- delete all until the comad + d- delete full line4 + d + d- delete for linesc + w- delete word and go to insert modec + t + ,- change until the comec + c- change entire lineshift + c- change until at the end of lineyw- copy word with spaceyy- copy the whole linep- pasteshift + p- paste above the current line5 + p- paste 5 times
Text Object
v + i + w- select whole word with spacev + a + w- select whole word without spaced + a + w- delete around wordd + i + w- delete inside wordv + i + )- select all until this parentheses in visual modev + 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 machinekitty +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 windowcntr + d- delete windowtmux 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
Git Integration
[ + h- up to git changes in file] + h- down to git changes in fileg + p- see previous changesg + 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 commitsO- to see changes in commit
:Gvdiffsplit!- solve merge conflict]cd2o- get changes from the left windowd3o- get changes from the right window
:Telescope git_commits- show all commits
Key Mapping
:set wrap- the line set limit by your screengkorgj- go to the next line in wrap<or>- in visual mode to 4 space on linemymark the point then go to any another line and`yyou will go back to mark;;- add ; to the end of the line in insert mode,,- add , to the end of the line in insert modeSpace + k- clean from searchSpace + x- open file in the browsershift + jk- transfer line up or down (do not work)
Simple Plugins
tpope/vim-surround
cs'"- change ' on "cs'<bold>- change ' on <bold>cstt<bold>- change html tag on bolddst- delete <bold> and </bold>
tpope/vim-repeat
.- can repeat plugins command (for example change <bold>)
vim-textobj-xmlattr
vix- surround html attributevax- surround html attribute including space
neoscroll.nvim
cntr + u- beautifull scrooll upcntr + d- beautifull scrooll down
bufdelete.nvim
Space + q- analog:Bdelete
floaterm
cntr + s- open terminal
File Navigation
telescope
:Telescope- open telescope all commandsSpace + f- search find filesSpace + F- search all filesSpace + b- search buffers filesSpace + g- search inside text filesSpace + h- search history filesSpace + s- search lsp filesrg 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 treea- create a new file or directory in nvim treem- move filer- rename fileSpace + n- toggle nvim treex- cut file/foldery- copy file/folderp- paste file/folderd- delete file/folderq- quitt- open tab newR- refreshi- show file details?- show helpshift + <- switch between Files, Buffer and GitShift + p- preview fileo- 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 + gthencntr + 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- changemax-w-7xlin finding files tomax-w-6xl
Tree seeter
https://github.com/nvim-treesitter/nvim-treesitter
vaa- select the first argument of function including commavia- select the first argumentvif- select all inside functionvaf- select full functiondaa- delete ...
Language Server Protocol (LSP)
:Lspinfo- get info about LSP in current filegd - go inside of function
cntr + o - jump back
cntr + i - go inside of function
K- see the information about method (pressKtwice go to inside buffer)Space + d- show the error message in buffer[ + d- jump between errors] + d- jump between errorsga
gi
gr
Space + l + r
Space + r + n
Formatting:
nvim autoformat by settings in lspconfig.lua file
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 numberCntr + x- decrement the number1899 + Cntr + a- change number to 1899g + 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[sor]s- go to wrong word (red line)zg- add word into dictionary
Refactoring
:Refactor- command for pluginSpace + r + e- :Refactor extractSpace + r + f- :Refactor extract_to_fileSpace + r + v- :Refactor extract_varSpace + r + i- :Refactor inline_varSpace + r + I- :Refactor inline_funcSpace + r + b- :Refactor extract_blockSpace + r + bf-:Refactor extract_block_to_file
Others:
Cntr + o- move back bufferShift + s- in nvim tree open filef "User.php"- find path of this file in console
Last updated
Comments (tpope/vim-commentary)
gcc- make a comment5gcc- comment 5 lines