Skip to content

Vim

Usage

Windows (split mode)

Switch between windows

Ctrl+w and the direction. Useful for vimdiff.

quora

Ctrl+]

wikia

Spell checking

  1. To move to a misspelled word, use ]s and [s.
  2. To show suggestions use z=.
  3. To add a word to the dictionary use zg.

To mark a correct word as misspelled, use zw.

linux

Set tabulation

Execute set tabstop=2 shiftwidth=2 expandtab and then, it's a good idea to execute :retab.

stackoverflow

Registers

Vim saves the "clipboard" history as registers. You can check the saved ones with :reg.

If you want to paste the content of one of them use "3p for example.

Reference: superuser

Sort

Vim has a very powerful built-in sort utility, or it can interface with an external one. In order to keep only unique lines and sort,

:{range}sort u

You can make a selection (with v or V for example) and then

:'<,'>sort u

Tips

Go to th nth line

[n]G for example: 42G.

wikia

Set filetype (useful for snippets)

:set filetype=[filetype]

Disabling line numbers

Useful for copying.

:set norelativenumber

wikia

Deleting trailing whitespaces automatically

Add the following line to your .vimrc to automatically delete the trailing whitespaces when saving the file if it's one of the specific file types:

autocmd FileType c,cpp,java,php autocmd BufWritePre <buffer> %s/\s\+$//e

wikia

Breaking long lines automatically

set textwidth=79

stackexchange

Change filetype based on directory path

autocmd BufRead,BufNewFile [path regex] set syntax=html

wikia

Autoindent with tab as 4 spaces

Set in .vimrc the following lines:

syntax enable
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

If you are working on a file and you want to indent it automatically from the beginning to the end use gg=G.

Plugins

Jedi

davidhalter/jedi-vim uses the jedi Python autocompletion library for VIM.

Shortcuts

  • Completion <C-Space>
  • Goto assignment <leader>g (typical goto function)
  • Goto definition <leader>d (follow identifier as far as possible, includes imports and statements)
  • Goto (typing) stub <leader>s
  • Show Documentation/Pydoc K (shows a popup with assignments)
  • Renaming <leader>r
  • Usages <leader>n (shows all the usages of a name)
  • Open module, e.g. :Pyimport os (opens the os module)

Syntastic

Disable Syntastic

:SyntasticToggleMode

stackoverflow

CtrlP

CtrlP changes working directory annoyingly

Disable working path mode feature: let g:ctrlp_working_path_mode = '0'

stackoverflow

UltiSnips and YouCompleteMe

Since by default they both use as a expand tab, we must do something about it. Using the SuperTab plugin:

```vimrc " make YCM compatible with UltiSnips (using supertab) let g:ycm_key_list_select_completion = ['', ''] let g:ycm_key_list_previous_completion = ['', ''] let g:SuperTabDefaultCompletionType = ''

" better key bindings for UltiSnipsExpandTrigger let g:UltiSnipsExpandTrigger = "" let g:UltiSnipsJumpForwardTrigger = "" let g:UltiSnipsJumpBackwardTrigger = "" ````

Reference

Registers

Plugins