NeoVim Reference Flashcards

1
Q

What ‘mode’ is vim in when you open it?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to open vim and exit nvim

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

To save a file?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a buffer?

A

A buffer is a holding area in memory for text. A buffer is not a file until it is saved.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to add a new buffer?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Add the contents of one bufferv to another?

A

put the cursor where you want to insert the content and in command mode
> :r file_name
reads file and insert into current buffer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Visual mode?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Split view?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How line number to a file

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Open file at a specific line number?

A

At the command line
> vim +20 my_file_name.txt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does ‘SHIFT a’ (A) do from normal mode?

A

This will append to the current line, note that nvim will also switch to insert mode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a motion?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Motions with a count?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Delete motion

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Undo, Redo

A

From normal mode:
‘u’ undos last change.
‘SHIFT u’ (U) undos all the changes on a line.
To perform a redo use ‘CTRL r’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Put

A

In normal mode press ‘p’ to put what’s in the paste buffer after the cursor.

17
Q

Replace a character?

A

From normal mode: Place the cursor on the character to be replaced press ‘r’ followed by the character you wish to replace the selected character with.
‘rx’ - will replace selected character with ‘x’

‘c’ is the change operator and therefore can be used with motions to perform specific changes .
- To replace from a character to the end of the word use ‘ce’ , type replacement then hint ‘ESC’ to go back to normal mode.
- To change the rest of a line place the cursor where you wish to start and press ‘c$’
replace the line then hit ‘ESC’.

18
Q

Ctrl - g

A

From normal mode pressing ‘CTRL g’ will bring up info about the current file.
- ‘SHIFT g’ moves to the end of the file
- ‘gg’ moves to the start of the file
- line number + ‘SHIFT g’ will cursor to that line number

19
Q

File search

A

To search for a word in the file. from normal mode:
‘/word_you_are_searching_for’ + ‘Enter’
- to select each result forward ‘n’
- to select backwards ‘SHIFT n’
-to return to original location ‘CTRL o’ and ‘CTRL i’
Note you can use ‘/ ESC’ to clear the search

20
Q

Find matching brackets

A

In normal mode place cursor on bracket
press ‘SHIFT 5’ (%)

21
Q

Find and replace

A

Enter command mode
:s/old/new/
- replaces first occurrence in the line
:s/old/new/g
- replace all occurrence in the current line

:%s/old/new/g
- change every occurrence in the file

:%s/old/new/gc
- replace all occurrence in the file with but prompts for change conformation.

22
Q

How to execute an external command?

A

Enter command mode
‘:!shell_command’ then ENTER to execute command.

23
Q

Auto complete suggestions

A

Press ‘CTRL x TAB’
gives list of suggestions use ENTER to accept.