Skip to content
Michael Watts edited this page Nov 3, 2016 · 11 revisions

Links

http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim

http://stackoverflow.com/questions/1497958/how-to-use-vim-registers?rq=1

http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about?rq=1

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

http://stackoverflow.com/questions/1675688/make-vim-show-all-white-spaces-as-a-character

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 shiftenter 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

j 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>

Switching case of characters

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

Toggle case "HellO" to "hELLo" with g~ then a movement.

Uppercase "HellO" to "HELLO" with gU then a movement.

Lowercase "HellO" to "hello" with gu then a movement.

Alternatively, you can visually select text then press ~ to toggle case, or U to convert to uppercase, or u to convert to lowercase.

Copy all contents of file to clipboard

Use:

:%y+

to yank all lines.

Explanation:

  • % to refer the next command to work on all the lines
  • y to yank those lines
  • + to copy to the system clipboard

NB: In Windows, + and * are equivalent see this answer.

SSH

2 Best practices when logging in remotely to linux machine

WARGAMES

Clone this wiki locally