Difference between revisions of "VIM"
| (14 intermediate revisions by the same user not shown) | |||
| Line 36: | Line 36: | ||
@a | @a | ||
| + | == Copy & Paste == | ||
| + | To yank to a registered key | ||
| + | " + {key} + y | ||
| + | |||
| + | To paste from a registered key. | ||
| + | " + {key} + p | ||
== Windows == | == Windows == | ||
'''Switch''' between windows. The arrow key or direction key you want to go to. | '''Switch''' between windows. The arrow key or direction key you want to go to. | ||
ctrl+w {arrow key} or {h,j,k,l} | ctrl+w {arrow key} or {h,j,k,l} | ||
| + | |||
| + | Opens a new vertical split | ||
| + | CTRL+w, v | ||
| + | |||
| + | Opens a new horizontal split | ||
| + | CTRL+w, s | ||
| + | |||
| + | Closes a window but keeps the buffer | ||
| + | CTRL+w, c | ||
| + | |||
| + | Closes other windows, keeps the active window only | ||
| + | CTRL+w, o | ||
| + | |||
| + | Moves the current window to the right | ||
| + | CTRL+w, r | ||
| + | |||
| + | Makes all splits equal size | ||
| + | CTRL+w, = | ||
== Show Whitespace == | == Show Whitespace == | ||
| Line 72: | Line 96: | ||
This autocomplete tries to match word already in the document. | This autocomplete tries to match word already in the document. | ||
ctl+n or ctl+p | ctl+n or ctl+p | ||
| + | |||
| + | == Netrw == | ||
| + | Open as a left window. | ||
| + | :Lexplore or :Lex | ||
| + | |||
| + | Open as a new tab. | ||
| + | :tabe . | ||
| + | |||
| + | Open file in new tab when in Netrw. | ||
| + | t | ||
| + | |||
| + | Create new file. | ||
| + | % | ||
| + | |||
| + | Create new directory. | ||
| + | d | ||
| + | |||
| + | Delete file or directory. | ||
| + | D | ||
| + | |||
| + | == Terminal == | ||
| + | You can open a new terminal by typing. | ||
| + | :terminal | ||
| + | |||
| + | You can enter `normal` mode. | ||
| + | ctrl-\ ctrl-n | ||
| + | |||
| + | Exit terminal mode | ||
| + | ctrl-d | ||
| + | |||
| + | == Pipe in data from console == | ||
| + | To pipe in data from the command line use the following | ||
| + | :%!{command} | ||
| + | |||
| + | or | ||
| + | |||
| + | If you in the terminal and want the output to go into vim. | ||
| + | ls | vim - | ||
| + | |||
| + | == Column Editing == | ||
| + | Column editing is editing a bunch of lines at once. | ||
| + | |||
| + | ctrl-v - start highlight of columns. | ||
| + | h,j,k,l - to select the columns and/or rows | ||
| + | shift-i - to go to insert mode. | ||
| + | |||
| + | == Highlight blocks == | ||
| + | To quick highlight blocks of code with in { or [ | ||
| + | |||
| + | Move the curser inside the block, and type the following. | ||
| + | vi[ | ||
| + | or | ||
| + | vi{ | ||
| + | |||
| + | == Edit in VIM == | ||
| + | To bring a command line in to VIM for editing | ||
| + | ctrl+x ctrl+e | ||
| + | |||
| + | == Switch bash to use VIM == | ||
| + | This will allow the terminal to use vim keys. | ||
| + | set -o vi | ||
| + | |||
| + | == Diff == | ||
| + | The following key combinations will show the diff between two copied registries. | ||
| + | |||
| + | :tabnew // Create a new tab. | ||
| + | " -> a -> p // Paste the text from registry 'a' | ||
| + | leftabove vnew diff1. // create a side window called diff1 | ||
| + | |||
| + | ctr+w ->> // switch windows | ||
| + | |||
| + | " -> b -> p // paste the text from registry 'b' | ||
| + | ctr+w <<- // Switch windows again | ||
| + | :diffthis // diff the two windows | ||
| + | |||
| + | |||
| + | == Buffer == | ||
| + | List all buffers | ||
| + | :ls | ||
| + | |||
| + | Open a buffer | ||
| + | :buffer {number from above} | ||
| + | |||
| + | Open a buffer in a new tab | ||
| + | :tab sb {number from above} | ||
Latest revision as of 11:02, 25 February 2025
Contents
Syntax Highlighting
Inside VI type the command below.
:syntax on
Maybe
:syn on
Bottom Page
This goes to the bottom of the page.
G
Bookmarks
To bookmark a position press m and then a letter. Use capital letter for Global or multiple files.
ma
To go to the bookmark press ` and then letter marking you want to go to.
`a
To see all your bookmarks.
:marks
To to last edit location.
`.
Record
To record a set of keys press q and then a letter to record to.
qa
To play back the recording press @ and then letter marking you want to play back.
@a
Copy & Paste
To yank to a registered key
" + {key} + y
To paste from a registered key.
" + {key} + p
Windows
Switch between windows. The arrow key or direction key you want to go to.
ctrl+w {arrow key} or {h,j,k,l}
Opens a new vertical split
CTRL+w, v
Opens a new horizontal split
CTRL+w, s
Closes a window but keeps the buffer
CTRL+w, c
Closes other windows, keeps the active window only
CTRL+w, o
Moves the current window to the right
CTRL+w, r
Makes all splits equal size
CTRL+w, =
Show Whitespace
This will show all whitespace char
set list
You can also show only select char.
:set listchars=eol:$,tab:>-,trail:~
Spelling
To turn spell checker on.
:set spell spelllang=en_us
To turn spell checker off.
:set nospell
To move between misspelled words.
]s and [s
To get misspelled recommendations, move in misspelled word and press.
z=
To add word to dictionary.
zg
To mark a word as incorrect
zw
Autocomplete
This autocomplete tries to match word already in the document.
ctl+n or ctl+p
Netrw
Open as a left window.
:Lexplore or :Lex
Open as a new tab.
:tabe .
Open file in new tab when in Netrw.
t
Create new file.
%
Create new directory.
d
Delete file or directory.
D
Terminal
You can open a new terminal by typing.
:terminal
You can enter `normal` mode.
ctrl-\ ctrl-n
Exit terminal mode
ctrl-d
Pipe in data from console
To pipe in data from the command line use the following
:%!{command}
or
If you in the terminal and want the output to go into vim.
ls | vim -
Column Editing
Column editing is editing a bunch of lines at once.
ctrl-v - start highlight of columns. h,j,k,l - to select the columns and/or rows shift-i - to go to insert mode.
Highlight blocks
To quick highlight blocks of code with in { or [
Move the curser inside the block, and type the following.
vi[
or
vi{
Edit in VIM
To bring a command line in to VIM for editing
ctrl+x ctrl+e
Switch bash to use VIM
This will allow the terminal to use vim keys.
set -o vi
Diff
The following key combinations will show the diff between two copied registries.
:tabnew // Create a new tab. " -> a -> p // Paste the text from registry 'a' leftabove vnew diff1. // create a side window called diff1 ctr+w ->> // switch windows " -> b -> p // paste the text from registry 'b' ctr+w <<- // Switch windows again :diffthis // diff the two windows
Buffer
List all buffers
:ls
Open a buffer
:buffer {number from above}
Open a buffer in a new tab
:tab sb {number from above}