Vim

Created Tuesday 03 December 2013
http://vimdoc.sourceforge.net/htmldoc/hebrew.html
http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html

  1. Site:
    1. http://www.vim.org/
  2. Show line numbers
  3. End of file
  4. Beginning of file
    • 1G
    • gg
  5. Vertical split
  6. File/Directory browser
  7. Search
    • /pattern - begin search forwards
    • ?pattern - begin search backwards
    • n - next the same direction
    • N - next the opposite direction
    • ggn - 1st match
    • GN - last match
    • http://vim.wikia.com/wiki/Searching
  8. Tabs
  9. Undo
    • :u
    • ctrl-R - redo
    • :U - reverse all changes in the last modified line - creates a new change thus unundoable
  10. Substitute + increment
  11. Yank (copy) to clipboard
  12. Highlight awk within bash
    • :h sh-awk
  13. Addons management
    1. http://www.openlogic.com/wazi/bid/262302/Three-tools-for-managing-Vim-plugins
      1. sudo apt-get install vim-addon-manager vim-scripts
      2. Install
        1. vim-addons -v install addon-name
      3. List
        1. vim-addons | less
      4. Remove
        1. vim-addons remove addon-name
      5. Disable
        1. vim-addons disable addon-name
      6. Enable
        1. vim-addons enable addon-name
    2. Pathogen
      1. https://github.com/tpope/vim-pathogen
        1. Install to:
          1. ~/.vim/autoload/pathogen.vim
        2. Add to .vimrc
execute pathogen#infect()
syntax on
filetype plugin indent on
        1. Installing a package:
          1. **cd ~/.vim/bundle && git clone git://github.com/tpope/vim-sensible.git**
      1. http://addisu.taddese.com/blog/using-github-and-pathogen-for-your-vim-config-files/
  1. Enable syntax highlighting for Twig
    1. http://aaronbonner.io/post/16914552864/enable-syntax-highlighting-for-twig-templates-in-vim
      1. http://www.vim.org/scripts/script.php?script_id=1856
      2. To .vimrc
        1. au BufRead,BufNewFile *.twig set filetype=htmljinja
  2. Enable omni completion (intellisense)
    1. http://vim.wikia.com/wiki/Omni_completion
      1. Add to .vimrc
filetype plugin on
set omnifunc=syntaxcomplete#Complete
      1. Usage
        1. C-x C-O - in insert mode
        2. C-N or C-P - navigate
  1. Yank (copy) to clipboard
    1. http://stackoverflow.com/questions/11489428/how-to-make-vim-paste-from-and-copy-to-systems-clipboard
      1. "+yy
  2. Yank (copy) all
    1. http://stackoverflow.com/questions/1620018/vi-editor-copy-all-the-lines-to-clipboard
      1. gg"+yG
  3. Check python version:
    1. http://stackoverflow.com/questions/10864042/how-to-check-python-version-that-vim-was-compiled-with
      1. :python import sys; print(sys.version)
  4. Check if optional feature is available
    1. http://stackoverflow.com/questions/6972021/checking-if-an-optional-vim-feature-is-available-using-vim-script
      1. :h has
      2. :h feature-list
      3. if has('float')
    2. http://learnvimscriptthehardway.stevelosh.com/chapters/28.html
      1. :exe "echom" has('signs')
  5. Reload buffer from file
    1. http://stevemorin.blogspot.co.il/2005/11/vim-vi-how-to-reload-file-your-editing.html
      1. :help edit
      2. :help edit!
      3. :help 'confirm'
  6. Using vimball (vba) with pathogen:
    1. http://stackoverflow.com/questions/3767046/vim-recommendations-for-vimball-plugins-in-pathogen
      1. vim something.vba
      2. :!mkdir ~/.vim/bundle/bundle-dir-name
      3. :UseVimball ~/.vim/bundle/bundle-dir-name
      4. :h :UseVimball
  7. Tabs to 4 spaces
    1. http://stackoverflow.com/questions/234564/tab-key-4-spaces-and-auto-indent-after-curly-braces-in-vim
      1. To .vimrc:
        1. set smartindent
        2. set tabstop=4
        3. set shiftwidth=4
        4. set expandtab
  8. Force syntax coloring
    1. http://vim.wikia.com/wiki/Forcing_Syntax_Coloring_for_files_with_odd_extensions
      1. :set syntax=perl
  9. Paste yanked text to command prompt
    1. http://stackoverflow.com/questions/906535/how-to-copy-yanked-text-to-vi-command-prompt
      1. <ctrl+r>"
  10. Save session
    1. http://stackoverflow.com/questions/1642611/how-to-save-a-session-in-vim
      1. :mksession ~/mysession.vim
      2. :source ~/mysession.vim
      3. vim -S ~/mysession.vim
  11. Create/copy file
    1. http://www.ehow.com/how_6012772_create-file-vi-editor.html
      1. :w copyOfTheCurrentFileName
      2. :e aBrandNewFile
      3. :sav copyOfTheCurrentFileAndSwitch
  12. Toggle between inserting tabs and spaces
    1. http://vim.wikia.com/wiki/Toggle_between_tabs_and_spaces
" virtual tabstops using spaces
let my_tab=4
execute "set shiftwidth=".my_tab
execute "set softtabstop=".my_tab
set expandtab
" allow toggling between local and default mode
function! TabToggle()
if &expandtab
set shiftwidth=8
set softtabstop=0
set noexpandtab
else
execute "set shiftwidth=".g:my_tab
execute "set softtabstop=".g:my_tab
set expandtab
endif
endfunction
nmap <F9> mz:execute TabToggle()<CR>'z
OR
" virtual tabstops using spaces
set shiftwidth=4
set softtabstop=4
set expandtab
" allow toggling between local and default mode
function TabToggle()
if &expandtab
set shiftwidth=8
set softtabstop=0
set noexpandtab
else
set shiftwidth=4
set softtabstop=4
set expandtab
endif
endfunction
nmap <F9> mz:execute TabToggle()<CR>'z
  1. Spaces to tabs
    1. http://stackoverflow.com/questions/11598890/how-to-convert-leading-spaces-to-tabs
:set tabstop=4 "4 spaces for 1 tab
:set noexpandtab "stop inserting spaces
:retab!
  1. Set statusline and view BOM
    1. http://vim.wikia.com/wiki/Show_fileencoding_and_bomb_in_the_status_line
set laststatus=2

if has("statusline")
set statusline=%<%f\ %h%m%r%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P
endif

  1. Save file without BOM
http://vim.1045645.n5.nabble.com/How-to-display-and-remove-BOM-in-utf-8-encoded-file-td4681708.html
:set nobomb - before saving

  1. Convert from CRLF to LF
http://vim.wikia.com/wiki/File_format
:update
:e ++ff=dos
:setlocal ff=unix
:w
  1. Name of the current file
    1. http://vim.wikia.com/wiki/Get_the_name_of_the_current_file
    2. :echo @%
      1. dir/filename
    3. :echo expand('%:p')
      1. full path
  2. Incremental numbering via regular expression search and replace
    1. http://stackoverflow.com/questions/26681541/vim-incremental-numbering-via-regular-expression-search-and-replace/26682137#26682137
    2. :let i=1 | g/1(\,\)\@=/ s//\=i/ | let i+=1
  3. Sorting numeric and literal columns
    1. http://stackoverflow.com/questions/1355004/how-to-sort-numeric-and-literal-columns-in-vim
    2. :'<,'>!sort -n -k 2
      1. Sort by 2nd selected column
  4. Highlight search pattern
    1. http://vim.wikia.com/wiki/Highlight_all_search_pattern_matches
    2. :set hlsearch



Backlinks: