NeoVim Reference Flashcards
What ‘mode’ is vim in when you open it?
vim always opens in ‘normal mode’.
To edit a file press ‘i’ for insert mode.
To exit insert or any mode press ‘esc’ key which takes you back to normal mode.
To enter command mode use ‘:’
To open neovim use the app image currently in the home directory
How to open vim and exit nvim
To open vim use command
> ~/nvim.appimage my_file_name
- this will open the file specified in the editor
to exit
> :q
- will exit editor and return to the command prompt if no unsaved changes were made to the file.
> :q! exit without saving.
To save a file?
To save a new file
> :w my_new_file.txt
- write new file
save changes to a file that already exists
> :w
- write
save changes to a file that already exists and quit
> :wq
- save and quit
Remove saved file
> :!r my_file_name
What is a buffer?
A buffer is a holding area in memory for text. A buffer is not a file until it is saved.
How to add a new buffer?
To add a new buffer, from the current buffer switch to command mode:
> :e my_file_path
- opens a new buffer with specified file
switch between buffers
> :bp
- buffer previous
> :bn
-buffer next
to create a new empty buffer
> :enew
- empty buffer added. Note that the new buffer will be removed automatically if you switch to a another buffer without adding any content.
Add a new buffer in the background without switching to it. In command mode:
> :badd my_file_name.txt
to close a buffer
> :bd
- close the current buffer
Add the contents of one bufferv to another?
put the cursor where you want to insert the content and in command mode
> :r file_name
reads file and insert into current buffer.
Visual mode?
To enter visual mode; from normal mode press ‘v’. This will allow you to highlight text for different operations such as
- coping
in visual mode press ‘y’ for ‘yank’, you will exit visual mode back to normal mode you could perform a paste operation
-paste
Place cursor where you want to paste text, in normal mode and press ‘p’ to ‘put’ text in desired location.
- delete by pressing ‘d’
-sorting lines of text alphabetically
in visual mode highlight lines press “:” brings up a prompt
: ‘<, ‘>sort ui
Split view?
From a open file switch to command mode
> :split my_file_name
- will open file both files in a split horizontal view. To switch between files ‘ctrl ww’
for a vertical split.
> :vsplit my_file_name
- splits view vertically. Note that you can open the same file open twice in split view.
Since ‘ctrl ww’ will close the browser, in command mode use
> :wincmd w
- this will switch windows
Open vim within split-screen mode. From command line.
> vim -o my_file_name.txt my_other_file_name.py
- opens both files in horizontal view
- use -O for vertical split.
How line number to a file
From command mode:
> :set number
- will number each line of the current file.
To remove the numbers
> :set nonumber
Note these changes will not persist. To have your preferences remembered you must have a .vimrc flile in your home directory that will contain your configurations.
Open file at a specific line number?
At the command line
> vim +20 my_file_name.txt
What does ‘SHIFT a’ (A) do from normal mode?
This will append to the current line, note that nvim will also switch to insert mode.
What is a motion?
A motion is a navigation operation such as
w - move cursor to the start of the next word
e - move cursor to the end of the next word
$ - move the cursor end of the line
Motions with a count?
Prefixing a motion with a number performs that motion, that number of times.
3e will move the cursor to the end of the third word forward
0 moves to the start of the line
Delete motion
In normal mode ‘d’ plus a motion will perform a deletion.
dd- delete the entire line and add it to the paste buffer
2dd - delete two lines
dw - will delete a word
d$ - will delete from cursor to the line
d2w - will delete next two words
Undo, Redo
From normal mode:
‘u’ undos last change.
‘SHIFT u’ (U) undos all the changes on a line.
To perform a redo use ‘CTRL r’