Skip to content

Instantly share code, notes, and snippets.

@todgru
Last active January 22, 2019 01:23
Show Gist options
  • Save todgru/4497708 to your computer and use it in GitHub Desktop.
Save todgru/4497708 to your computer and use it in GitHub Desktop.
vim nerdtree copy paste search and replace

#vim

Editing

  • shift V select line, up or down select lines
  • shift > shift select block or line out
  • shift < shift select block or line in
  • d to delete highlighted text and copy to cliboard
  • D delete everything after cursor to end of line
  • y to copy (yank)
  • p to paste after cursor, P before
  • u undo last change
  • . repeat last command
  • $ vim +linenumber file.c open file and jump to that line number
  • gg go to first line, GG go to last
  • gt go to next tab
  • {i}gt go to tab number {i}
  • :tabm move current tab to last tab
  • :tabm {i} move current tab to position {i}
  • :tabs list all tabs including their displayed windows
  • :tabfirst go to first tab
  • :tablast go to last tab
  • U convert SELECTED text to uppercase (also gU)
  • u convert SELECTED text to lowercase (also gu)
  • ~ toggle SELECTED text to opposiste case (also g~)
  • control l to refresh vim when changes happen (like git pull)
  • Use * to go to the definition of the word under the cursor
  • In NERDTree, shift T opens select file in new tab behind current
  • In NERDTree, t opens selected file in new tab
  • :set syntax=php or :set syntax=yaml or :set syntax=perl etc.
  • :set nowrap turn off word wrap
  • :%s/$/',/ search the entire file %s, find end of line $ and replace with ',
  • s/' .*/'/ search the selection for ' if found, replace it and the rest of the line with '
  • %s/ ->\zs .*// keep the arrow, delete all after arrow
  • %s/ -> .*// delete the arrow and everything after
  • vim scp://url/path/remote_file edit remote file locally, saving to remote
  • Find this or that or blue this\|that\|blue
  • Sort selection alphabetically: sort, reverse sort!
  • Folding: in .vimrc add let php_folding = 1
  • Folding: za to toggle fold zA to toggle all
  • If command r and loose arrow-key, then ctrl z and type fg on the command line
  • d0 delete every thing before cursor in visual mode
  • ctrl u to delte every thing befor cursor in insert mode
  • e reload current file
  • :retab set all tabs in current file to current settings. Good for files that used tabs, not spaces.
  • :vertical resize 30 to resize the current window to exactly 30 characters wide.

Netrw

  • % create a new file
  • d create a new directory
  • R rename the file/directory under the cursor
  • D Delete the file/directory under the cursor

To select a column, or even a block: In normal mode (press ESC),

  1. control v
  2. select column
  3. shift I
  4. enter your comment syntax, like #
  5. press ESC

To delete a column:

  1. control i
  2. select column
  3. d will delete (and copy to clipboard, p to paste)

After copying (yanking) a block of text, can also select another block of text and paste over it. Similar to other editors gui's.

.vimrc

My basic .vimrc file:

syntax on
set bs=2
set expandtab
set tabstop=2
set shiftwidth=2
set number

" extra
" remove white spaces at end of line
:nnoremap <silent> <F4> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>

" Format visually selected JSON
:vnoremap <F8> :!python -m json.tool<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment