Vim
Usage⚑
Windows (split mode)⚑
Switch between windows⚑
Ctrl+w and the direction. Useful for vimdiff
.
(https://www.quora.com/How-do-I-switch-between-panes-in-split-mode-in-Vim)
Links⚑
Follow link⚑
Ctrl+]
(http://vim.wikia.com/wiki/Learn_to_use_help)
Spell checking⚑
- To move to a misspelled word, use ]s and [s.
- To show suggestions use z=.
- To add a word to the dictionary use zg.
To mark a correct word as misspelled, use zw.
(https://www.linux.com/learn/using-spell-checking-vim)
Set tabulation⚑
Execute set tabstop=2 shiftwidth=2 expandtab
and then, it's a good idea to execute :retab
.
(https://stackoverflow.com/questions/426963/replace-tab-with-spaces-in-vim)
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: (https://superuser.com/questions/102815/vim-cut-and-paste-history#102828)
Sort⚑
Vim has a very powerful (https://vim.fandom.com/wiki/Sort_lines), 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⚑
G
for example: 42G
.
(http://vim.wikia.com/wiki/Go_to_line)
Set filetype (useful for snippets)⚑
:set filetype=
Disabling line numbers⚑
Useful for copying.
:set norelativenumber
(http://vim.wikia.com/wiki/Display_line_numbers)
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
(http://vim.wikia.com/wiki/Remove_unwanted_spaces#Automatically_removing_all_trailing_whitespace)
Breaking long lines automatically⚑
set textwidth=79
(https://vi.stackexchange.com/questions/574/keeping-lines-to-less-than-80-characters)
Change filetype based on directory path⚑
autocmd BufRead,BufNewFile set syntax=html
(http://vim.wikia.com/wiki/Change_filetype_based_on_directory_path)
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⚑
(https://github.com/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 theos
module)
Syntastic⚑
Disable Syntastic⚑
:SyntasticToggleMode
(https://stackoverflow.com/questions/20030603/vim-syntastic-how-to-disable-the-checker)
CtrlP⚑
CtrlP changes working directory annoyingly⚑
Disable working path mode feature: let g:ctrlp_working_path_mode = '0'
(https://stackoverflow.com/questions/11873736/vim-ctrlp-plugin-manually-set-root-search-directory)
UltiSnips and YouCompleteMe⚑
Since by default they both use
```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 = "
Reference⚑
- (https://www.linux.com/learn/using-spell-checking-vim)
- (https://www.cs.oberlin.edu/~kuperman/help/vim/windows.html)
Registers⚑
- (https://stackoverflow.com/questions/1497958/how-do-i-use-vim-registers)
- (https://www.brianstorti.com/vim-registers/)
Plugins⚑
- (https://github.com/Townk/vim-autoclose): enable an auto-close chars feature.