Skip to content
Michael Watts edited this page Jul 20, 2015 · 11 revisions

Run a terminal command within vim

Typing :!<command> will open a console window

Pause vim to go to terminal and then resume vim

Pause Vim with Ctrl+z, play in the terminal, then return to Vim with the command fg.

Fix formatting

Select a block of text and press = to fix formatting

Marks

Set your marks

ma set a mark called referenced with a

mz set a mark referenced with z

Jump to your marks

`a jump to mark a

`z jump to mark z

Jump to start of line of your marks

'a jump to start of line for mark a

'z jump to start of line for mark z

Insert text on multiple lines

Hit Ctrl+v to select a column then shift+I to enter the text. Press Esc shows inserted text.

Copying and pasting

Copy word (when cursor is anywhere within word) with yiw

Paste text and replace word with viwp

Insert linebreak without going into insert mode

By adding the following lines to the .vimrc file

nmap <S-Enter> O<Esc>
nmap <CR> o<Esc>

We can hit shift+enter whilst in normal mode.

Deleting stuff between brackets, single-quotes, double-quotes, etc

di( or di{ or di[ or di' or di"

NERDTree

Toggle and Focus

space and space space

Delete all lines containing a pattern

http://vim.wikia.com/wiki/Delete_all_lines_containing_a_pattern

For example, to delete all lines containing "profile" (remove the /d to show the lines that the command will delete):

:g/profile/d

How to add text to end of a bunch of lines

http://stackoverflow.com/questions/594448/how-can-i-add-a-string-to-the-end-of-each-line-in-vim

ctrl + v to enter column highlight mode

jj... to select the columns

$ to select each end of line

A to start 'appending'

<your text> add your text

esc to escape, et voilà!

OR

Select your lines. Press : which will pre-fill with <,'> you can then add norm A<your text> so it would like :<,'>norm A<your text>

SSH

2 Best practices when logging in remotely to linux machine

WARGAMES

Clone this wiki locally