VIM: Difference between revisions
add emmet and adding comments to a block |
dump from oldwiki |
||
Line 1: | Line 1: | ||
= Adding comments to a block = | |||
Grab lines with visual block and then <code>:norm i#</code> to comment, and then <code>:norm x</code> or <code>:norm ^x</code> with indentation. | Grab lines with visual block and then <code>:norm i#</code> to comment, and then <code>:norm x</code> or <code>:norm ^x</code> with indentation. | ||
= Emmet = | |||
Also known as Zen Coding previously. | Also known as Zen Coding previously. | ||
Line 11: | Line 9: | ||
* [http://docs.emmet.io/cheat-sheet/ Emmet cheatsheet] | * [http://docs.emmet.io/cheat-sheet/ Emmet cheatsheet] | ||
= Miscellaneous = | |||
== Fixing an issue with Python version when using VIM with some packages == | |||
* ''Last tested on Ubuntu 16.04 LTS (xenial) | easy | less than five minutes'' | * ''Last tested on Ubuntu 16.04 LTS (xenial) | easy | less than five minutes'' | ||
Line 32: | Line 30: | ||
$ apt-get install vim-nox | $ apt-get install vim-nox | ||
</source> | </source> | ||
= Initial setup = | |||
Install [https://github.com/Shougo/neobundle.vim Shougo/neobundle.vim] from Github. It's a new package management tool for Vim that utilizes the Github repository. | |||
Here is my entire ~/.vimrc file. | |||
<source lang="vim" enclose="div"> | |||
set nocompatible | |||
set noexpandtab | |||
set tabstop=4 | |||
set shiftwidth=4 | |||
set softtabstop=4 | |||
set smartindent | |||
set autoindent | |||
set encoding=utf-8 | |||
set number | |||
set autowrite | |||
set ruler | |||
set foldmethod=indent | |||
set foldnestmax=15 | |||
set nofoldenable | |||
set foldlevel=1 | |||
set timeoutlen=500 | |||
set hidden | |||
set t_Co=256 | |||
set statusline=%F\ \%{fugitive#statusline()}\ \%=\ \%y\ -\ %l/%L | |||
set laststatus=2 | |||
set runtimepath+=~/.vim/bundle/neobundle.vim/ | |||
let g:phpcomplete_index_composer_command="composer" | |||
let g:Powerline_symbols = "fancy" | |||
let g:gitgutter_sign_added = '++' | |||
let g:gitgutter_sign_modified = 'MM' | |||
let g:gitgutter_sign_removed = '--' | |||
let g:gitgutter_sign_modified_removed = 'M-' | |||
call neobundle#rc(expand('~/.vim/bundle/')) | |||
NeoBundleFetch 'Shougo/neobundle.vim' | |||
filetype plugin indent on | |||
NeoBundle 'Shougo/vimproc', { | |||
\ 'build' : { | |||
\ 'windows' : 'make -f make_mingw32.mak', | |||
\ 'cygwin' : 'make -f make_cygwin.mak', | |||
\ 'mac' : 'make -f make_mac.mak', | |||
\ 'unix' : 'make -f make_unix.mak', | |||
\ }, | |||
\ } | |||
NeoBundle 'Shougo/unite.vim' | |||
NeoBundle 'Shougo/vimshell.vim' | |||
NeoBundle 'airblade/vim-gitgutter' | |||
NeoBundle 'Lokaltog/powerline',{'rtp': 'powerline/bindings/vim/'} | |||
NeoBundle 'tpope/vim-fugitive' | |||
NeoBundle 'kien/ctrlp.vim' | |||
NeoBundle 'vim-scripts/sudo.vim' | |||
NeoBundle 'm2mdas/phpcomplete-extended' | |||
NeoBundle 'm2mdas/phpcomplete-extended-laravel' | |||
NeoBundle 'chriskempson/vim-tomorrow-theme' | |||
NeoBundleCheck | |||
filetype plugin indent on | |||
colorscheme torte | |||
highlight LineNr ctermfg=darkgrey | |||
highlight SignColumn ctermbg=black | |||
highlight Folded ctermfg=11 ctermbg=23 | |||
autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP | |||
</source> | |||
<code>set nocompatible</code> - forget about making Vim behave like Vi. | |||
<code>set noexpandtab</code> - do not expand tabs into spaces; use the tab character | |||
<code>set tabstop=4</code> - uses 4 character spaces for a tab | |||
<code>set shiftwidth=4</code> - move 4 spaces for reindent operation (<< or >> shortcut keys) | |||
<code>set softtabstop=4</code> - number of spaces a tab uses in INSERT mode | |||
<code>set smartindent</code> - use smart indent mode -- i.e. entering after a opening bracket would automatically indent and in other similar situations | |||
<code>set autoindent</code> - use the same indentation as the last line | |||
<code>set encoding=utf-8</code> - set encoding | |||
<code>set number</code> - turn on line numbers (<code>set nonumber</code> to turn it off) | |||
<code>set autowrite</code> - automatically save when changing between buffers | |||
<code>set ruler</code> - information such as line number and current position in the file are displayed on the status line | |||
<code>set foldmethod=indent</code> - another foldmethod I use regularly is marker ({{{ & }}}) when documenting code, but indent is a good start for reading through long lines of code | |||
<code>set foldnestmax=15</code> - the nest level for the code folding | |||
<code>set nofoldenable</code> - you don't want Vim to fold your code by default on initial load of a file | |||
<code>set foldlevel=1</code> - when executing close command for code folding everything will be folded down to level 1, or the top level | |||
<code>set timeoutlen=500</code> - keycode delay to be used; default is 1000, but this reduces the polling time when you press on a Esc to change modes | |||
<code>set hidden</code> - allows loading of a buffer in a window that has a modified buffer | |||
<code>set t_Co=256</code> - allow Vim to understand that the terminal is using 256 colors | |||
<code>set statusline=%F\ \%{fugitive#statusline()}\ \%=\ \%y\ -\ %l/%L</code> - this is the default for the fugitive installation | |||
<code>set laststatus=2</code> - turn the status line on | |||
<code>set runtimepath+=~/.vim/bundle/neobundle.vim/</code> - required for neobundle installation | |||
<code>let g:phpcomplete_index_composer_command="composer"</code> - by default, it is "php composer.phar", so this is according to how you've customized your development environment | |||
<code>let g:Powerline_symbols="fancy"</code> - I haven't confirmed this yet, but this probably allows Lokaltog/powerline plugin to use Private Use Area of the Unicode of fonts specifically patched for Powerline characters | |||
<code>let g:gitgutter_sign_added = '++'</code> - I like my GitGutter to occupy two characters for better visibility | |||
... | |||
<code>call neobundle#rc(expand('~/.vim/bundle/'))</code> - I think this sets this directory as NeoBundle's target bundle directory; required by NeoBundle | |||
<code>NeoBundleFetch 'Shougo/neobundle.vim'</code> - as required by NeoBundle | |||
</code>filetype plugin indent on</code> - allow plugins to change the indent behavior (??) | |||
All those NeoBundle 'owner/package' lines are for installation of packages | |||
<code>NeoBundle 'Shougo/vimproc'...</code> - vimproc allows real-time update of certain components that uses this package | |||
<code>NeoBundle 'Shougo/unite.vim'</code> - similar to ctrlp, allows extensive searching features and UI | |||
<code>NeoBundle 'Shougo/vimshell.vim'</code> - allows bash shell like interface within vim | |||
<code>NeoBundle 'airblade/vim-gitgutter'</code> - Git diff marks are displayed somewhat realtime | |||
<code>NeoBundle 'Lokaltog/powerline',{'rtp': 'powerline/bindings/vim/'}</code> - one of the most popular status line plugins | |||
<code>NeoBundle 'tpope/vim-fugitive'</code> - run Git commands within Vim | |||
<code>NeoBundle 'kien/ctrlp.vim'</code> - extensive searching tool | |||
<code>NeoBundle 'vim-scripts/sudo.vim'</code> - installed to get rid of the annoying msg while running Vim as a sudo | |||
<code>NeoBundle 'm2mdas/phpcomplete-extended'</code> - command completion similar to ones found in many GUI IDEs | |||
<code>NeoBundle 'm2mdas/phpcomplete-extended-laravel'</code> - this is add-on allows completion for Laravel 4 | |||
<code>NeoBundle 'chriskempson/vim-tomorrow-theme'</code> - I sometimes use this theme | |||
<code>NeoBundleCheck</code> - NeoBundle requires this | |||
<code>colorscheme torte</code> - Use this color scheme -- a default one I like | |||
<code>highlight LineNr ctermfg=darkgrey</code> - color of the line numbers | |||
<code>highlight SignColumn ctermbg=black</code> - color of the gutter used by GitGutter | |||
<code>highlight Folded ctermfg=11 ctermbg=23</code> - the default folded code color is an eyesore, so replace it | |||
<code>autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP</code> - this completes the phpcomplete_extended plugin installation | |||
= Useful commands = | |||
;Turn number lines | |||
:<nowiki>:</nowiki>set number | |||
;Wordwrap off | |||
:<nowiki>:</nowiki>set nowrap | |||
;Syntax on | |||
:<nowiki>:</nowiki>syntax on | |||
= Possibly outdated by 2014 = | |||
== CTAG == | |||
;Rebuild a ctag file from a current project (assuming extensions are abc & def) | |||
:find . -type f -name \*.abc -o -name \*.def | xargs ctags --language-force=php | |||
:(to add more extensions) find . -type f -name \*.ghi | xargs ctags -a --language-force=;http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/ | |||
:ctags and taglist | |||
;http://runpaint.org/ | |||
:vim and other tech books |
Revision as of 20:59, 29 June 2016
Adding comments to a block
Grab lines with visual block and then :norm i#
to comment, and then :norm x
or :norm ^x
with indentation.
Emmet
Also known as Zen Coding previously.
Miscellaneous
Fixing an issue with Python version when using VIM with some packages
- Last tested on Ubuntu 16.04 LTS (xenial) | easy | less than five minutes
When running vim
with Powerline package on Ubuntu 16.04, I get this error message every time I execute it from the CLI.
$ vim
UltiSnips requires py >= 2.7 or py3
You need vim compiled with Python 2.6, 2.7 or 3.2 and later support
for Powerline to work. Please consult the documentation for more
details.
Press ENTER or type command to continue
I'm not sure what this does, but this seems to solve the problem. Thanks to Sergey Khaylov for the answer at Stackoverflow.
$ apt-get install vim-nox
Initial setup
Install Shougo/neobundle.vim from Github. It's a new package management tool for Vim that utilizes the Github repository.
Here is my entire ~/.vimrc file.
set nocompatible
set noexpandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smartindent
set autoindent
set encoding=utf-8
set number
set autowrite
set ruler
set foldmethod=indent
set foldnestmax=15
set nofoldenable
set foldlevel=1
set timeoutlen=500
set hidden
set t_Co=256
set statusline=%F\ \%{fugitive#statusline()}\ \%=\ \%y\ -\ %l/%L
set laststatus=2
set runtimepath+=~/.vim/bundle/neobundle.vim/
let g:phpcomplete_index_composer_command="composer"
let g:Powerline_symbols = "fancy"
let g:gitgutter_sign_added = '++'
let g:gitgutter_sign_modified = 'MM'
let g:gitgutter_sign_removed = '--'
let g:gitgutter_sign_modified_removed = 'M-'
call neobundle#rc(expand('~/.vim/bundle/'))
NeoBundleFetch 'Shougo/neobundle.vim'
filetype plugin indent on
NeoBundle 'Shougo/vimproc', {
\ 'build' : {
\ 'windows' : 'make -f make_mingw32.mak',
\ 'cygwin' : 'make -f make_cygwin.mak',
\ 'mac' : 'make -f make_mac.mak',
\ 'unix' : 'make -f make_unix.mak',
\ },
\ }
NeoBundle 'Shougo/unite.vim'
NeoBundle 'Shougo/vimshell.vim'
NeoBundle 'airblade/vim-gitgutter'
NeoBundle 'Lokaltog/powerline',{'rtp': 'powerline/bindings/vim/'}
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'kien/ctrlp.vim'
NeoBundle 'vim-scripts/sudo.vim'
NeoBundle 'm2mdas/phpcomplete-extended'
NeoBundle 'm2mdas/phpcomplete-extended-laravel'
NeoBundle 'chriskempson/vim-tomorrow-theme'
NeoBundleCheck
filetype plugin indent on
colorscheme torte
highlight LineNr ctermfg=darkgrey
highlight SignColumn ctermbg=black
highlight Folded ctermfg=11 ctermbg=23
autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP
set nocompatible
- forget about making Vim behave like Vi.
set noexpandtab
- do not expand tabs into spaces; use the tab character
set tabstop=4
- uses 4 character spaces for a tab
set shiftwidth=4
- move 4 spaces for reindent operation (<< or >> shortcut keys)
set softtabstop=4
- number of spaces a tab uses in INSERT mode
set smartindent
- use smart indent mode -- i.e. entering after a opening bracket would automatically indent and in other similar situations
set autoindent
- use the same indentation as the last line
set encoding=utf-8
- set encoding
set number
- turn on line numbers (set nonumber
to turn it off)
set autowrite
- automatically save when changing between buffers
set ruler
- information such as line number and current position in the file are displayed on the status line
set foldmethod=indent
- another foldmethod I use regularly is marker ({{{ & }}}) when documenting code, but indent is a good start for reading through long lines of code
set foldnestmax=15
- the nest level for the code folding
set nofoldenable
- you don't want Vim to fold your code by default on initial load of a file
set foldlevel=1
- when executing close command for code folding everything will be folded down to level 1, or the top level
set timeoutlen=500
- keycode delay to be used; default is 1000, but this reduces the polling time when you press on a Esc to change modes
set hidden
- allows loading of a buffer in a window that has a modified buffer
set t_Co=256
- allow Vim to understand that the terminal is using 256 colors
set statusline=%F\ \%{fugitive#statusline()}\ \%=\ \%y\ -\ %l/%L
- this is the default for the fugitive installation
set laststatus=2
- turn the status line on
set runtimepath+=~/.vim/bundle/neobundle.vim/
- required for neobundle installation
let g:phpcomplete_index_composer_command="composer"
- by default, it is "php composer.phar", so this is according to how you've customized your development environment
let g:Powerline_symbols="fancy"
- I haven't confirmed this yet, but this probably allows Lokaltog/powerline plugin to use Private Use Area of the Unicode of fonts specifically patched for Powerline characters
let g:gitgutter_sign_added = '++'
- I like my GitGutter to occupy two characters for better visibility
...
call neobundle#rc(expand('~/.vim/bundle/'))
- I think this sets this directory as NeoBundle's target bundle directory; required by NeoBundle
NeoBundleFetch 'Shougo/neobundle.vim'
- as required by NeoBundle
filetype plugin indent on - allow plugins to change the indent behavior (??)
All those NeoBundle 'owner/package' lines are for installation of packages
NeoBundle 'Shougo/vimproc'...
- vimproc allows real-time update of certain components that uses this package
NeoBundle 'Shougo/unite.vim'
- similar to ctrlp, allows extensive searching features and UI
NeoBundle 'Shougo/vimshell.vim'
- allows bash shell like interface within vim
NeoBundle 'airblade/vim-gitgutter'
- Git diff marks are displayed somewhat realtime
NeoBundle 'Lokaltog/powerline',{'rtp': 'powerline/bindings/vim/'}
- one of the most popular status line plugins
NeoBundle 'tpope/vim-fugitive'
- run Git commands within Vim
NeoBundle 'kien/ctrlp.vim'
- extensive searching tool
NeoBundle 'vim-scripts/sudo.vim'
- installed to get rid of the annoying msg while running Vim as a sudo
NeoBundle 'm2mdas/phpcomplete-extended'
- command completion similar to ones found in many GUI IDEs
NeoBundle 'm2mdas/phpcomplete-extended-laravel'
- this is add-on allows completion for Laravel 4
NeoBundle 'chriskempson/vim-tomorrow-theme'
- I sometimes use this theme
NeoBundleCheck
- NeoBundle requires this
colorscheme torte
- Use this color scheme -- a default one I like
highlight LineNr ctermfg=darkgrey
- color of the line numbers
highlight SignColumn ctermbg=black
- color of the gutter used by GitGutter
highlight Folded ctermfg=11 ctermbg=23
- the default folded code color is an eyesore, so replace it
autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP
- this completes the phpcomplete_extended plugin installation
Useful commands
- Turn number lines
- :set number
- Wordwrap off
- :set nowrap
- Syntax on
- :syntax on
Possibly outdated by 2014
CTAG
- Rebuild a ctag file from a current project (assuming extensions are abc & def)
- find . -type f -name \*.abc -o -name \*.def | xargs ctags --language-force=php
- (to add more extensions) find . -type f -name \*.ghi | xargs ctags -a --language-force=;http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/
- ctags and taglist
- http://runpaint.org/
- vim and other tech books