Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

Sunday, March 17, 2019

Install MySQL 5.7, Apache 2.4, PHP 7.1 on Ubuntu 16.04

Install MySQL 5.7, Apache 2.4, PHP 7.1 on Ubuntu 16.04

Install VMware tools:

VM > Guest > Install/Upgrade VMware Tools

# su -
# df -h
# cd /media/jun/VMware\ Tools/
# ls -la
# tar zxvf VMwareTools-9.4.0-1280544.tar.gz -C /tmp/
# cd /tmp
# ls
# cd vmware-tools-distrib/
# ls
# ./vmware-install.pl -d
# reboot

Note: For more info https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1022525

Move Ubuntu launcher to the bottom:

# gsettings set com.canonical.Unity.Launcher launcher-position Bottom

Update the package repository:

# apt-get update

Upgrades packages with auto-handling of dependencies:

# apt-get dist-upgrade

or

# apt full-upgrade

Install SSH server:

# apt-get install openssh-server
# systemctl status sshd.service
# systemctl restart sshd.service

Compile and install the latest Git 2.20.1 from source code:

# apt-get install make gcc dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext zlib1g-dev libssl-dev \
&& apt-get install curl \
&& cd /usr/local/src/ \
&& curl -L https://github.com/git/git/archive/v2.20.1.tar.gz -o git.tar.gz \
&& tar zxvf git.tar.gz \
&& cd git-2.20.1/ \
&& make configure \
&& ./configure --prefix=/usr \
&& make all \
&& make install

# git --version

git version 2.20.1

Install Git from ppa:

# add-apt-repository ppa:git-core/ppa
# apt-get update

# apt-cache policy git
# apt-cache madison git

# apt-get install git=1:2.11.0-2~ppa0~ubuntu16.04.1

# git --version

Compile and install the latest Vim 8:

# apt-get install libncurses5-dev python-dev python3-dev ruby-dev libperl-dev ruby-dev liblua5.3-dev exuberant-ctags cscope

// Fix liblua paths
# ln -s /usr/include/lua5.3 /usr/include/lua \
&& ln -s /usr/lib/x86_64-linux-gnu/liblua5.3.so /usr/local/lib/liblua.so

# cd /usr/local/src \
&& git clone https://github.com/vim/vim.git --depth 1 \
&& cd vim \
&& ./configure \
--prefix=/usr \
--with-features=huge \
--enable-multibyte \
--enable-pythoninterp \
--enable-python3interp \
--enable-rubyinterp \
--enable-perlinterp \
--enable-luainterp \
--enable-cscope \
&& make \
&& make install \
&& hash -r \
&& vim --version | head

Install MTA mail server:

# apt-get install postfix

Note: select "Internet site".

Note: If you need to reconfigure the postfix setting, run either one of the following:

# dpkg-reconfigure -plow postfix

or

# apt-get purge postfix

For other mail related packages:

# apt-get install mailutils

Install mail client:

# apt-get install bsd-mailx
# echo "test message" | mailx -s 'test subject' myemail@mydomain.com

For hexdump command:

# apt-get install bsdmainutils

# hexdump -c test.log

Install MySQL5.7:

# apt-cache policy mysql-server
# apt-cache search mysql-server
# apt-cache show mysql-server | less
# apt show mysql-server

# apt-get install mysql-server

# vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0

# vim ~/.my.cnf
[client]
host = localhost
port = 3306
user = root
password = MyPassword

# chmod 400 ~/.my.cnf

# mysql -e "SHOW variables WHERE variable_name REGEXP 'open_files_limit|table_open_cache|max_connections';"
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| max_connections            | 151   |
| open_files_limit           | 1024  |
| table_open_cache           | 431   |
| table_open_cache_instances | 16    |
+----------------------------+-------+

Note: You will see the following error message in the error.log file if you did not change the open files limit:
[Warning] Changed limits: max_open_files: 1024 (requested 5000)
[Warning] Changed limits: table_open_cache: 431 (requested 2000)

# mkdir /etc/systemd/system/mysql.service.d
# vim /etc/systemd/system/mysql.service.d/override.conf

[Service]
#LimitNOFILE=infinity
LimitNOFILE=5000

#LimitMEMLOCK=infinity

# systemctl daemon-reload
# systemctl restart mysql

# mysql -e "SHOW variables WHERE variable_name REGEXP 'open_files_limit|table_open_cache|max_connections';"
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| max_connections            | 151   |
| open_files_limit           | 5000  |
| table_open_cache           | 2000  |
| table_open_cache_instances | 16    |
+----------------------------+-------+

To check MySQL process's limit:

# cat /proc/$(pgrep mysqld$)/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             15614                15614                processes
Max open files            5000                 5000                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       15614                15614                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

Note: https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html

Note: https://stackoverflow.com/questions/30901041/can-not-increase-max-open-files-for-mysql-max-connections-in-ubuntu-15

Note: https://serverfault.com/questions/821695/mysqld-service-for-systemd-failed-to-parse-resource-value-ignoring-40000-l

To move a MySQL data directory to another directory:

# mysql -e "SELECT @@datadir;"
+-----------------+
| @@datadir       |
+-----------------+
| /var/lib/mysql/ |
+-----------------+

# systemctl stop mysql
# systemctl status mysql

# vim /etc/mysql/mysql.conf.d/mysqld.cnf
datadir         = /home/mysql

# vim /etc/apparmor.d/tunables/alias
alias /var/lib/mysql/ -> /home/mysql/,

Note: We need to tell AppArmor to let MySQL write to the new directory by creating an alias between the default directory and the new location.

Note: If you skipped the AppArmor configuration step, you would see the following error message:

Job for mysql.service failed because the control process 
exited with error code. See "systemctl status mysql.service" 
and "journalctl -xe" for details.

# systemctl restart apparmor
# systemctl restart mysql

To move the existing to MySQL directory to /home:

# rsync -av /var/lib/mysql /home

Or, you can run the following commands to initialize the MySQL data directory:

# mkdir /home/mysql \
&& chown mysql:mysql /home/mysql \
&& chmod 700 /home/mysql \
&& mysqld --initialize-insecure

Note: This option is used to initialize a MySQL installation by creating the data directory and populating the tables in the mysql system database.

Note: If you use --initialize, the random initial password is stored at: tail -n 1 /var/log/mysql/error.log.

Note: You can also start mysqld with --skip-grant-tables to access the database and change the password.

# systemctl start mysql && systemctl status mysql

Login MySQL with the above commands if you initialized MySQL data directory with --initialize-insecure option.
# mysql -u root --skip-password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Check the current MySQL data directory:

# mysql -e "SELECT @@datadir;"
+--------------+
| @@datadir    |
+--------------+
| /home/mysql/ |
+--------------+

To change the root password if you did not know the current root password:

# vim /root/tmp/mysql-init.txt
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'YourPassWordHere' WITH GRANT OPTION;
GRANT SUPER ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;

# mysqld --init-file=/root/tmp/mysql-init.txt

Use RAM-DISK for tmpdir:

# mysql -e "SHOW GLOBAL STATUS LIKE 'Created_tmp%tables';"
# mysql -e "SHOW GLOBAL VARIABLES LIKE '%table_size';"

# mkdir -p /mnt/ramdisk
# mount -t tmpfs -o size=512M tmpfs /mnt/ramdisk
# chown mysql:mysql /mnt/ramdisk

# id mysql

uid=123(mysql) gid=130(mysql) groups=130(mysql)

# vim /etc/fstab

tmpfs           /mnt/ramdisk     tmpfs   rw,uid=123,gid=130,mode=1770,size=512M    0       0

Note: You need to change the uid and gid of MySQL.

# mysql -e "SHOW GLOBAL VARIABLES LIKE 'tmpdir';"

# vim /etc/apparmor.d/local/usr.sbin.mysqld

/mnt/ramdisk rw,
owner /mnt/ramdisk/** rwkl,

Note: The first line gives read and write access to the directory, the second line gives read, write, lock(k) and link(l) access to all the files and the directories inside the directory owned by the mysql user.

# vim /etc/mysql/mysql.conf.d/mysqld.cnf

[mysqld]
tmpdir      = /mnt/ramdisk

# systemctl restart apparmor.service
# systemctl restart mysql.service

Install PHP7.1:

# command -v add-apt-repository >/dev/null 2>&1 \
|| { echo >&2 "add-apt-repository is not installed. I will install it for you"; apt-get install python-software-properties; }

# add-apt-repository -y ppa:ondrej/php
# apt-get update

# apt-cache policy php7.1

# apt-get install php7.1-fpm
# apt-get install php7.1-xml php7.1-curl php7.1-zip php7.1-gd php7.1-bcmath php7.1-intl php7.1-mbstring php7.1-mcrypt php7.1-mysql
# apt-get install php7.1-json php7.1-opcache
# apt-get install php-xdebug

# php -v
PHP 7.1.10-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep 29 2017 17:04:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.10-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

# vim /etc/php/7.1/fpm/pool.d/www.conf

;listen = /run/php/php7.1-fpm.sock
listen = 127.0.0.1:9000

Note: You can choose to use either a Unix socket (for local access only) or TCP socket (for the other server on the network to access).

Set up xdebug:

# vim /etc/php/7.1/fpm/php.ini

[Xdebug]
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9009
xdebug.remote_log=/tmp/xdebug.log
xdebug.remote_connect_back=0
xdebug.remote_autostart=1
xdebug.remote_mode=req

xdebug.max_nesting_level=1000

xdebug.var_display_max_depth = 5
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = 1024

# systemctl restart php7.1-fpm.service && systemctl status php7.1-fpm.service

# ss -an | grep :9000
tcp    LISTEN     0      128    127.0.0.1:9000                  *:*

# vim /etc/php/7.1/fpm/php.ini

date.timezone = America/Vancouver
display_errors = On
display_startup_errors = On
error_reporting = E_ALL
error_log = /var/log/php_errors.log

List all the installed PHP packages:

# dpkg -l | grep php| awk '{print $2}' |tr "\n" " "

Show the available package version:

# apt-cache search php
# apt-cache policy php

Install the specific package version:

# apt-get install php7=7.0+35ubuntu6

Note: You can look up old versions of packages at their site http://www.debian.org/distrib/packages

Install older version of PHP (PHP5.6):

# add-apt-repository ppa:ondrej/php

# apt-get update

# apt-get install php5.6-fpm

# apt-get install php5.6-gd php5.6-intl php5.6-json php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-opcache php5.6-xml

# a2disconf php7.0-fpm.conf
# a2enconf php5.6-fpm.conf

# systemctl restart apache2.service

Install Apache2.4:

# command -v add-apt-repository >/dev/null 2>&1 \
|| { echo >&2 "add-apt-repository is not installed. I will install it for you"; apt-get install python-software-properties; }

# add-apt-repository -y ppa:ondrej/apache2
# apt-get update

# apt-cache policy apache2

# apt-get install apache2

Enable the following modules to talk to PHP:

# cat /etc/apache2/conf-available/php7.1-fpm.conf

# a2enmod proxy proxy_fcgi rewrite setenvif ssl
# a2enconf php7.1-fpm.conf

If your apache is talking to PHP through a TCP socket (127.0.0.1:9000) instead of a Unix socket (/run/php/php7.1-fpm.sock), you will need to modify the following line:

# vim /etc/apache2/conf-available/php7.1-fpm.conf
# Define a matching worker.
    # The part that is matched to the SetHandler is the part that
    # follows the pipe. If you need to distinguish, "localhost; can
    # be anything unique.
    <Proxy "fcgi://localhost/" enablereuse=on max=10>
    </Proxy>
    <FilesMatch ".+\.ph(ar|p|tml)$">
        #SetHandler "proxy:unix:/run/php/php7.1-fpm.sock|fcgi://localhost"
        SetHandler "proxy:fcgi://127.0.0.1:9000"
    </FilesMatch>

# apache2ctl configtest
# systemctl restart apache2 && systemctl status apache2

Install and enable the following Apache modules if you are connecting to PHP through a TCP socket (127.0.0.1:9000):

# apt-get install libapache2-mod-fastcgi
# a2enmod fastcgi rewrite setenvif


Edit apache2.conf:

# vim /etc/apache2/apache2.conf

AllowOverride All

Set up a virtual host:

# cd /etc/apache2/sites-available
# cp 000-default.conf mag2.local.conf
# vim mag2.local

Check the configuration:

# apache2ctl -V
# apache2ctl -t
# apache2ctl -M
# apache2ctl configtest

Enable the site:

# a2ensite mag2.local

Start MySQL, PHP, and Apache:

# systemctl restart mysql.service
# systemctl restart php7.0-fpm.service
# systemctl restart apache2.service

# ps auxww | grep -i mysql
# ps auxww | grep -i php-fpm
# ps auxww | grep -i apache2

Install PHPStorm:

# cd ~jun/Downloads/
# tar xf PhpStorm-*.tar.gz -C /opt/
# cd /opt/PhpStorm-163.10504.2/
# ./bin/phpstorm.sh

Generate a self-signed SSL certificate:

# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj "/C=CA/ST=British Columbia/L=Vancouver/O=My Company Name/CN=erp.local" -keyout /etc/ssl/private/test.local.key -out /etc/ssl/certs/test.local.crt

Install node:

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

$ command -v nvm

nvm

$ nvm ls-remote
$ nvm install 8.9.3
$ nvm use 8.9.3
$ node -v
$ nvm ls

$ echo '{}' > package.json
$ npm install webpack eslint js-beautify --save-dev

Reference:

https://wiki.apache.org/httpd/PHP-FPM

http://httpd.apache.org/docs/2.4/mod/mod_proxy_fcgi.html

https://www.digitalocean.com/community/tutorials/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04

http://www.fromdual.com/mysql-tmpdir-on-ram-disk

http://www.victordodon.com/changing-mysql-tmpdir-in-ubuntu/

https://blog.remirepo.net/post/2014/03/28/PHP-FPM-and-HTTPD-2.4-improvement

Saturday, February 23, 2019

Migrate to stamblerre/gocode in YouCompleteMe for Go module support

Migrate to stamblerre/gocode in YouCompleteMe for Go module support

apt install build-essential cmake python3-dev

git clone --depth 1 https://github.com/Valloric/YouCompleteMe.git

cd /home/jun/.vim/pack/plugins/start/YouCompleteMe
git submodule update --init --recursive

vim /home/jun/.vim/pack/plugins/start/YouCompleteMe/third_party/ycmd/ycmd/completers/go/go_completer.py

mdempsky/gocode
stamblerre/gocode

vim /home/jun/.vim/pack/plugins/start/YouCompleteMe/third_party/ycmd/.gitmodules

mdempsky/gocode
stamblerre/gocode

rm -rf third_party/ycmd/third_party/go/src/github.com/mdempsky/

vim ./third_party/ycmd/build.py

cd third_party/ycmd/third_party/go/src/github.com
mkdir stamblerre
cd stamblerre
git clone --depth 1 https://github.com/stamblerre/gocode.git

cd /home/jun/.vim/pack/plugins/start/YouCompleteMe

./install.py --go-completer

Reference:

https://github.com/Valloric/YouCompleteMe

https://github.com/stamblerre/gocode

Thursday, February 22, 2018

Ace Text Editor Bookmarklet

Ace is a standalone code editor written in JavaScript. Our goal is to create a browser based editor that matches and extends the features, usability and performance of existing native editors such as TextMate, Vim or Eclipse.

Ace Bookmarklet http://ajaxorg.github.io/ace/build/demo/bookmarklet/index.html

javascript:(function inject(options, callback) { var load = function(path, callback) { var head = document.getElementsByTagName('head')[0]; var s = document.createElement('script'); s.src = options.baseUrl + "/" + path; head.appendChild(s); s.onload = s.onreadystatechange = function(_, isAbort) { if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") { s = s.onload = s.onreadystatechange = null; if (!isAbort) callback(); } }; }; var pending = []; var transform = function(el) { pending.push(el) }; load("ace.js", function() { ace.config.loadModule("ace/ext/textarea", function(m) { transform = function(el) { if (!el.ace) el.ace = m.transformTextarea(el, options.ace); }; pending = pending.forEach(transform); callback && setTimeout(callback); }); }); if (options.target) return transform(options.target); window.addEventListener("click", function(e) { if (e.detail == 3 && e.target.localName == "textarea") transform(e.target); });})({"selectionStyle":"line","highlightActiveLine":true,"highlightSelectedWord":true,"readOnly":false,"copyWithEmptySelection":false,"cursorStyle":"ace","mergeUndoDeltas":true,"behavioursEnabled":true,"wrapBehavioursEnabled":true,"keyboardHandler":"ace/keyboard/vim","hScrollBarAlwaysVisible":false,"vScrollBarAlwaysVisible":false,"highlightGutterLine":true,"animatedScroll":false,"showInvisibles":false,"showPrintMargin":false,"printMarginColumn":80,"printMargin":false,"fadeFoldWidgets":false,"showFoldWidgets":true,"showLineNumbers":true,"showGutter":true,"displayIndentGuides":true,"fontSize":"12px","scrollPastEnd":0,"theme":"textmate","scrollSpeed":2,"dragDelay":0,"dragEnabled":true,"focusTimeout":0,"tooltipFollowsMouse":true,"firstLineNumber":1,"overwrite":false,"newLineMode":"auto","useWorker":true,"useSoftTabs":true,"navigateWithinSoftTabs":false,"tabSize":4,"wrap":"off","indentedSoftWrap":true,"foldStyle":"markbegin","mode":"javascript","enableMultiselect":true,"enableBlockSelect":true,"baseUrl":"https://ajaxorg.github.io/ace-builds/src-noconflict"})

Reference:

https://github.com/ajaxorg/ace/

Saturday, January 27, 2018

To increase the number in Vim

To increase the number in Vim


$arr = [
    'test 0' => 'test 0',
    'test 0' => 'test 0',
    'test 0' => 'test 0',
    'test 0' => 'test 0',
    'test 0' => 'test 0',
    'test 0' => 'test 0',
];

ctrl-v jjjjjj g ctrl-a a

In vim, how do I highlight TODO: and FIXME:?

In vim, how do I highlight TODO: and FIXME:?

$ ~/.vimrc

syntax on

augroup vimrc_jun_todo
        au!
        au Syntax * syn match JunTodo /\v<(FIXME|NOTE|TODO|OPTIMIZE):/ containedin=.*Comment,vimCommentTitle
augroup END
hi def link JunTodo Todo

Reference:

https://stackoverflow.com/questions/4097259/in-vim-how-do-i-highlight-todo-and-fixme

Tuesday, December 26, 2017

What's the simplest way to strip trailing whitespace from all lines in a file?

What's the simplest way to strip trailing whitespace from all lines in a file?

The "simplest" way is to just use :substitute:

:%s/\s\+$//e

:%s to run :substitute over the range %, which is the entire buffer.
\s t match all whitespace characters.
\+ to repeat them 1 or more times.
$ to anchor at the end of the line.
The e flag to not give an error if there is no match (i.e. the file is already without trailing whitespace).

However, this is probably not the "best" way as it causes two side-effects:

1. it moves the cursor to the last match;
2. it resets the last search term.

You can fix both items by turning this into a function:

fun! TrimWhitespace()
    let l:save = winsaveview()
    %s/\s\+$//e
    call winrestview(l:save)
endfun

And then use it like:

:call TrimWhitespace()

The winsaveview() will save the current "view", which includes the cursor position, folds, jumps, etc. The winrestview() at the end will restore this from the saved variable.
The last-used search term is automatically restored after leaving a function, so we don't have to do anything else for this.
Since this is somewhat annoying to type :call all the time, you can define a command:

command! TrimWhitespace call TrimWhitespace()

Which can be be used without the :call:

:TrimWitespace

And you can of course bind it to a key:

:noremap <Leader>w :call TrimWhitespace()<CR>

Some people like to automatically do this before they write a file to disk, like so:

autocmd BufWritePre * :call TrimWhitespace()

I don't like it, as some formats require trailing whitespace (such as Markdown), and on some other occasions you even want trailing whitespace in your code (such as formatting an email, and using the -- marker to indicate the start of a signature).

Reference:

https://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file?newreg=dfad440fc0e14ac1b0afde5ce4e41e27

Sunday, December 24, 2017

Vim restore opened files

Vim restore opened files

Add these in ~/.vimrc:

# vim ~/.vimrc

" Save the current vim sessions
noremap <F2> :mksession! ~/vim_session <cr>

" Load the saved vim sessions
noremap <F3> :source ~/vim_session <cr>

Reference:

https://stackoverflow.com/questions/1416572/vi-vim-restore-opened-files

Turning off auto indent when pasting text into vim

Method 1:

:set paste
:set nopaste

or in ~/.vimrc

set pastetoggle=

Method 2:

:r! cat

Then ctrl-insert to paste
Then enter
Then ctrl-d (twice) to end of file.

Friday, April 14, 2017

Save the selected lines to a file

To save the selected lines to a file, select a region using visual mode and then enter:

:w /tmp/filename

To insert/paste text from a file:

:r /tmp/filename

Tuesday, April 11, 2017

Compile the latest Vim 8.0 on CentOS 7

Compile the latest Vim 8.0 on CentOS 7

Remove the existing vim if you have already installed it:

# yum list installed | grep -i vim

vim-common.x86_64                    2:7.4.160-1.el7                @base
vim-enhanced.x86_64                  2:7.4.160-1.el7                @base
vim-filesystem.x86_64                2:7.4.160-1.el7                @base
vim-minimal.x86_64                   2:7.4.160-1.el7                @anaconda

# yum remove vim-enhanced vim-common vim-filesystem

Note: You do not need to remove vim-minimal because sudo depends on it.

For Red Hat/CentOS users:

# yum install gcc make ncurses ncurses-devel
# yum git
# yum install ruby ruby-devel lua lua-devel luajit \
luajit-devel ctags python python-devel \
python3 python3-devel tcl-devel \
perl perl-devel perl-ExtUtils-ParseXS \
perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \
perl-ExtUtils-Embed

or

# yum clean all
# yum grouplist
# yum groupinfo "Development Tools"
# yum groupinstall "Development tools"
# yum install ncurses ncurses-devel

For debian/Ubuntu users:

# apt-get remove vim vim-runtime vim-tiny vim-common

# apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \
python3-dev ruby-dev git

# apt-get install libncurses5-dev python-dev libperl-dev ruby-dev liblua5.2-dev

// Fix liblua paths
# ln -s /usr/include/lua5.2 /usr/include/lua
# ln -s /usr/lib/x86_64-linux-gnu/liblua5.2.so /usr/local/lib/liblua.so

If you want to install the optional packages With yum groupinstall command:

# vim /etc/yum.conf

group_package_types=default, mandatory, optional

Note: the default setting is default, mandatory.

Install ctags and cscope:

# yum install ctags cscope

Build vim:

# cd /usr/local/src

Download vim source (it is better to get it from GitHub because you can get all the latest patches from there):

# git clone https://github.com/vim/vim.git
# cd vim
or
# wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
# tar -xjf vim-7.4.tar.bz2
# cd vim74

Show the configuration options:

# ./configure --help

Configure:

# ./configure --prefix=/usr --with-features=huge --enable-multibyte --enable-rubyinterp --enable-pythoninterp --enable-perlinterp --enable-luainterp --enable-cscope

Build:

# make
or
# make VIMRUNTIMEDIR=/usr/share/vim/vim74

# make install

re-hash the environment:

# hash -r

Check vim version:

# vim --version | less

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 24 2016 14:27:26)
Included patches: 1-2102
...
+lua +multi_byte +perl +python +ruby

Check vim patches:

# vim

:echo has("patch-7.4-2102")

1

Reference:

https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source

https://gist.github.com/holguinj/11064609

http://www.fullybaked.co.uk/articles/installing-latest-vim-on-centos-from-source

http://www.vim.org/git.php

Saturday, January 9, 2016

Insert text is very slow in Vim

Read from the local file (super fast):

:read file

Try to set syntax off:

:set syntax=off

Vim tries to keep your work safe and doesn't assume you can type several thousand characters per second. Read :help swap-file for some details on the buffering. The solution to your problem is this:

Turn off vim's swapfile while you are pasting text:

:set noswapfile

Turning off swap is not safe for normal operations! Immediately after the paste:

:set swapfile

See :help swapfile for more details.

Folding could be the problem:

set foldenable              " can slow Vim down with some plugins
set foldlevelstart=99       " can slow Vim down with some plugins
set foldmethod=syntax       " can slow Vim down with some plugins

According to vim's help (:help foldmethod), the syntax setting caused vim to use syntax highlighting to determine how to automatically fold my code.

Other things to check/toggle are syntax, filetype, wrap and line length (some plugins can be slow with very long lines).

Running Vim without your current settings is a good starting point:

# vim -u NONE

Reference:

http://stackoverflow.com/questions/15086155/vim-insert-mode-is-very-slow-with-400-lines
http://superuser.com/questions/550669/my-copy-of-vim-is-running-extremely-slowly-when-i-edit-medium-to-large-eg-1000

Monday, April 27, 2015

To prevent vim from auto-wrapping at column 80, try:

:set tw=0
:set textwidth=0

or

:set wrapmargin=0

'textwidth' 'tw'        number  (default 0)
                        local to buffer
                        {not in Vi}
        Maximum width of text that is being inserted.  A longer line will be
        broken after white space to get this width.  A zero value disables
        this.  'textwidth' is set to 0 when the 'paste' option is set.  When
        'textwidth' is zero, 'wrapmargin' may be used.  See also
        'formatoptions' and |ins-textwidth|.
        When 'formatexpr' is set it will be used to break the line.
        NOTE: This option is set to 0 when 'compatible' is set.


'wrapmargin' 'wm'       number  (default 0) 
                        local to buffer
        Number of characters from the right window border where wrapping
        starts.  When typing text beyond this limit, an <EOL> will be inserted
        and inserting continues on the next line.
        Options that add a margin, such as 'number' and 'foldcolumn', cause
        the text width to be further reduced.  This is Vi compatible.
        When 'textwidth' is non-zero, this option is not used. 
        See also 'formatoptions' and |ins-textwidth|.  {Vi: works differently
        and less usefully}

Reference:

http://stackoverflow.com/questions/1290285/why-cant-i-stop-vim-from-wrapping-my-code
http://stackoverflow.com/questions/15724919/how-do-i-prevent-vim-from-auto-wrapping-at-column-80

Saturday, February 21, 2015

move cursor to the beginning of the selected text in visual mode

To the beginning of the selected text:

`<

To the end of the selected text:

`>

For example:

vmap ,s :call MyFunction()<CR>`<

To temporarily disable auto convert tab to spaces in Vim

: set noexpandtab

Thursday, February 12, 2015

Sort numeric and literal columns in Vim

Sort normally:

:'<,'>sort

Sort numerically:

:'<,'>sort n

Sort on second column:

:'<,'>sort -k 2
:'<,'>sort /.*\%2v/

Sort and remove duplicated lines:

:'<,'>sort u

Reference:

http://stackoverflow.com/questions/1355004/how-to-sort-numeric-and-literal-columns-in-vim

Saturday, March 8, 2014

disable resize automatically when splitting a window

" disable auto resize when splitting split a window.
set noequalalways

See equalalways in the Vim documentation:
http://vimdoc.sourceforge.net/htmldoc/options.html#%27equalalways%27

Friday, January 3, 2014

list all mapping key binding - Displaying the current Vim environment

list all mapping key binding - Displaying the current Vim environment

You can display the current Vim environment (settings, options, commands, maps, etc) using the following commands:

:abbreviate   - list abbreviations
:args         - argument list
:augroup      - augroups
:autocmd      - list auto-commands
:buffers      - list buffers
:breaklist    - list current breakpoints
:cabbrev      - list command mode abbreviations
:changes      - changes
:cmap         - list command mode maps
:command      - list commands
:compiler     - list compiler scripts
:digraphs     - digraphs
:file         - print filename, cursor position and status (like Ctrl-G)
:filetype     - on/off settings for filetype detect/plugins/indent
:function     - list user-defined functions (names and argument lists but not the full code)
:function Foo - user-defined function Foo() (full code list)
:highlight    - highlight groups
:history c    - command history
:history =    - expression history
:history s    - search history
:history      - your commands
:iabbrev      - list insert mode abbreviations
:imap         - list insert mode maps
:intro        - the Vim splash screen, with summary version info
:jumps        - your movements
:language     - current language settings
:let          - all variables
:let FooBar   - variable FooBar
:let g:       - global variables
:let v:       - Vim variables
:list         - buffer lines (many similar commands)
:lmap         - language mappings (set by keymap or by lmap)
:ls           - buffers
:ls!          - buffers, including "unlisted" buffers
:map!         - Insert and Command-line mode maps (imap, cmap)
:map          - Normal and Visual mode maps (nmap, vmap, xmap, smap, omap)
:map<buffer>  - buffer local Normal and Visual mode maps
:map!<buffer> - buffer local Insert and Command-line mode maps
:marks        - marks
:menu         - menu items
:messages     - message history
:nmap         - Normal-mode mappings only
:omap         - Operator-pending mode mappings only
:print        - display buffer lines (useful after :g or with a range)
:reg          - registers
:scriptnames  - all scripts sourced so far
:set all      - all options, including defaults
:setglobal    - global option values
:setlocal     - local option values
:set          - options with non-default value
:set termcap  - list terminal codes and terminal keys
:smap         - Select-mode mappings only
:spellinfo    - spellfiles used
:syntax       - syntax items
:syn sync     - current syntax sync mode
:tabs         - tab pages
:tags         - tag stack contents
:undolist     - leaves of the undo tree
:verbose      - show info about where a map or autocmd or function is defined
:version      - list version and build options
:vmap         - Visual and Select mode mappings only
:winpos       - Vim window position (gui)
:xmap         - visual mode maps only
Notes

Additional information is available to a Vim script. For example, :help tabpagebuflist() shows how to list all buffers in all tabs.

A script called bugreport.vim is provided with Vim. When run, the script produces a file with information about Vim's environment. To see the script, use the command :view $VIMRUNTIME/bugreport.vim in Vim.

Reference:
http://vim.wikia.com/wiki/Displaying_the_current_Vim_environment

Thursday, June 20, 2013

Using vim as an IDE all in one

Using vim as an IDE all in one
From Vim Tips Wiki
Jump to: navigation, search
Please review this tip:
This tip was imported from vim.org and needs general review.
You might clean up comments or merge similar tips.
Add suitable categories so people can find the tip.
Please avoid the discussion page (use the Comments section below for notes).
If the tip contains good advice for current Vim, remove the {{review}} line.
Tip 1439 Previous Next created December 12, 2006 · complexity basic · author Johnny · version n/a
I've read a lot of tips about how to make Vim as an IDE like editor. Most of them are really useful, and I want to sum up them in this tip, and then add some of my experiences.
Here are some useful tips to read:
VimTip64 Always set your working directory to the file you're editing Vim online
VimTip58 Switching back and forth between ViM and Visual Studio _NET Vim online
VimTip1119 How to use Vim like an IDE Vim online
Here are some scripts I recommend:
Project 1.1.4 Organize/navigate projects of files (like IDE/buffer explorer).
TagList 4.2 Source code browser (supports C/C++, Java, Perl, Python, TCL, SQL, PHP, etc).
MiniBufExpl 6.3.2 Elegant buffer explorer; takes very little screen space.
ShowMarks-2.2 Visually shows the location of marks.
OmniCppComplete-0.4 C/C++ omni-completion with ctags database.
CRefVim-1.0.4 A C-reference manual especially designed for Vim.
exUtility-4.1.0 Global search,symbol search,tag track...(Like IDE/Source Insight).
Here are some programs you may need to download:
http://gnuwin32.sourceforge.net/
diffutils-2.8.7-1.exe
gawk-3.1.3-2.exe
id-utils-4.0-2.exe
http://ctags.sourceforge.net/
ctags.exe
Here are some scripts for your vimrc: " --------------------
" ShowMarks
" --------------------
let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
let g:showmarks_enable = 1
" For marks a-z
highlight ShowMarksHLl gui=bold guibg=LightBlue guifg=Blue
" For marks A-Z
highlight ShowMarksHLu gui=bold guibg=LightRed guifg=DarkRed
" For all other marks
highlight ShowMarksHLo gui=bold guibg=LightYellow guifg=DarkYellow
" For multiple marks on the same line.
highlight ShowMarksHLm gui=bold guibg=LightGreen guifg=DarkGreen
" --------------------
" Project
" --------------------
map :Project
map :Project:redraw/
nmap ToggleProject
let g:proj_window_width = 30
let g:proj_window_increment = 50
" --------------------
" exTagSelect
" --------------------
nnoremap :ExtsToggle
nnoremap ts :ExtsSelectToggle
nnoremap tt :ExtsStackToggle
map ] :ExtsGoDirectly
map [ :PopTagStack
let g:exTS_backto_editbuf = 0
let g:exTS_close_when_selected = 1
" --------------------
" exGlobalSearch
" --------------------
nnoremap :ExgsToggle
nnoremap gs :ExgsSelectToggle
nnoremap gq :ExgsQuickViewToggle
nnoremap gt :ExgsStackToggle
map :GS
map :GSW
let g:exGS_backto_editbuf = 0
let g:exGS_close_when_selected = 0
" --------------------
" exSymbolTable
" --------------------
nnoremap ss :ExslSelectToggle
nnoremap sq :ExslQuickViewToggle
nnoremap :ExslToggle
nnoremap :ExslQuickSearch/^
nnoremap sg :ExslGoDirectly
let g:exSL_SymbolSelectCmd = 'TS'
" --------------------
" exEnvironmentSetting
" --------------------
function g:exES_UpdateEnvironment()
if exists( 'g:exES_PWD' )
silent exec 'cd ' . g:exES_PWD
endif
if exists( 'g:exES_Tag' )
let &tags = &tags . ',' . g:exES_Tag
endif
if exists( 'g:exES_Project' )
silent exec 'Project ' . g:exES_Project
endif
endfunction
" --------------------
" TagList
" --------------------
" F4: Switch on/off TagList
nnoremap :TlistToggle
" TagListTagName - Used for tag names
highlight MyTagListTagName gui=bold guifg=Black guibg=Orange
" TagListTagScope - Used for tag scope
highlight MyTagListTagScope gui=NONE guifg=Blue
" TagListTitle - Used for tag titles
highlight MyTagListTitle gui=bold guifg=DarkRed guibg=LightGray
" TagListComment - Used for comments
highlight MyTagListComment guifg=DarkGreen
" TagListFileName - Used for filenames
highlight MyTagListFileName gui=bold guifg=Black guibg=LightBlue
"let Tlist_Ctags_Cmd = $VIM.'/vimfiles/ctags.exe' " location of ctags tool
let Tlist_Show_One_File = 1 " Displaying tags for only one file~
let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill yourself
let Tlist_Use_Right_Window = 1 " split to the right side of the screen
let Tlist_Sort_Type = "order" " sort by order or name
let Tlist_Display_Prototype = 0 " do not show prototypes and not tags in the taglist window.
let Tlist_Compart_Format = 1 " Remove extra information and blank lines from the taglist window.
let Tlist_GainFocus_On_ToggleOpen = 1 " Jump to taglist window on open.
let Tlist_Display_Tag_Scope = 1 " Show tag scope next to the tag name.
let Tlist_Close_On_Select = 1 " Close the taglist window when a file or tag is selected.
let Tlist_Enable_Fold_Column = 0 " Don't Show the fold indicator column in the taglist window.
let Tlist_WinWidth = 40
" let Tlist_Ctags_Cmd = 'ctags --c++-kinds=+p --fields=+iaS --extra=+q --languages=c++'
" very slow, so I disable this
" let Tlist_Process_File_Always = 1 " To use the :TlistShowTag and the :TlistShowPrototype commands without the taglist window and the taglist menu, you should set this variable to 1.
":TlistShowPrototype [filename] [linenumber]
" --------------------
" MiniBufExpl
" --------------------
let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
let g:miniBufExplModSelTarget = 1 " If you use other explorers like TagList you can (As of 6.2.8) set it at 1:
let g:miniBufExplUseSingleClick = 1 " If you would like to single click on tabs rather than double clicking on them to goto the selected buffer.
let g:miniBufExplMaxSize = 1 " setting this to 0 will mean the window gets as big as needed to fit all your buffers.
"let g:miniBufExplForceSyntaxEnable = 1 " There is a Vim bug that can cause buffers to show up without their highlighting. The following setting will cause MBE to
"let g:miniBufExplorerMoreThanOne = 1 " Setting this to 0 will cause the MBE window to be loaded even
"let g:miniBufExplMapCTabSwitchBufs = 1
"let g:miniBufExplMapWindowNavArrows = 1
"for buffers that have NOT CHANGED and are NOT VISIBLE.
highlight MBENormal guibg=LightGray guifg=DarkGray
" for buffers that HAVE CHANGED and are NOT VISIBLE
highlight MBEChanged guibg=Red guifg=DarkRed
" buffers that have NOT CHANGED and are VISIBLE
highlight MBEVisibleNormal term=bold cterm=bold gui=bold guibg=Gray guifg=Black
" buffers that have CHANGED and are VISIBLE
highlight MBEVisibleChanged term=bold cterm=bold gui=bold guibg=DarkRed guifg=Black
" --------------------
" OmniCppComplete
" --------------------
" set Ctrl+j in insert mode, like VS.Net
imap
" :inoremap pumvisible() ? "\" : "\u\"
" set completeopt as don't show menu and preview
set completeopt=menuone
" Popup menu hightLight Group
highlight Pmenu ctermbg=13 guibg=LightGray
highlight PmenuSel ctermbg=7 guibg=DarkBlue guifg=White
highlight PmenuSbar ctermbg=7 guibg=DarkGray
highlight PmenuThumb guibg=Black
" use global scope search
let OmniCpp_GlobalScopeSearch = 1
" 0 = namespaces disabled
" 1 = search namespaces in the current buffer
" 2 = search namespaces in the current buffer and in included files
let OmniCpp_NamespaceSearch = 1
" 0 = auto
" 1 = always show all members
let OmniCpp_DisplayMode = 1
" 0 = don't show scope in abbreviation
" 1 = show scope in abbreviation and remove the last column
let OmniCpp_ShowScopeInAbbr = 0
" This option allows to display the prototype of a function in the abbreviation part of the popup menu.
" 0 = don't display prototype in abbreviation
" 1 = display prototype in abbreviation
let OmniCpp_ShowPrototypeInAbbr = 1
" This option allows to show/hide the access information ('+', '#', '-') in the popup menu.
" 0 = hide access
" 1 = show access
let OmniCpp_ShowAccess = 1
" This option can be use if you don't want to parse using namespace declarations in included files and want to add namespaces that are always used in your project.
let OmniCpp_DefaultNamespaces = ["std"]
" Complete Behaviour
let OmniCpp_MayCompleteDot = 0
let OmniCpp_MayCompleteArrow = 0
let OmniCpp_MayCompleteScope = 0
" When 'completeopt' does not contain "longest", Vim automatically select the first entry of the popup menu. You can change this behaviour with the OmniCpp_SelectFirstItem option.
let OmniCpp_SelectFirstItem = 0
After setting this, now you can really using Vim as an IDE-like editor.
I usually like to create project use exUtility, use "gvim project_name.vimenvironment"
You can browse project file by Project-plugin.
You can global search and edit them by exUtility-plugin.
You can jump tag and track code by exUtility-plugin.
You can analysis code by taglist-plugin.
You can choose buffer by minibuffer-plugin.
You can set clear mark by showmark-plugin.
edit Comments

I think cscope should also have been on this list, especially for people who are editing C files (as opposed to C++, which seems to be the main focus of this tip). It has a lot more features than ctags. A nice tutorial can be found at cscope.sourceforge.net.
For real-time source code analysis, this plugin might help as well: http://www.vim.org/scripts/script.php?script_id=2368

Friday, May 25, 2012

Use grep to search a string in files recursively and store the grep results in a quickfix window

Use grep to search a string in files recursively and store the grep results in a quickfix window
:grep -r 'pattern' . --include '*.c'

:copen             " open the quickfix window
:cw                " open the quickfix window if there are entries (so if your grep has no results, it won't appear).

<ENTER>            " Open the line of a file in a new buffer.
Ctrl-W <ENTER>     " Open the file/line in a new window.
:.cc               " Open the line of a file in a new buffer.

:cfile debug.txt   " read the content in debug.txt to a quickfix window.
                   " Note: follow this format: "filename:line number:error message"

:cgetfile debug.txt " Just like "cfile" but don't jump to the first entry.

:cclose            " close the quickfix window.
:quit              " close the quickfix window.

Edit ~/.vimrc:
" Find String Search String.
" Open quickfix window automatically after running grep command.
command! -nargs=+ Mygrep execute "silent grep! <args>" | copen

:Mygrep -r 'pattern' . --include '*.c'

Performing a customized grep search on the word under the cursor:
map <F4> :execute " grep -srnw --binary-files=without-match --exclude-dir=.git --exclude-from=exclude.list . -e " . expand("<cword>") . " " <bar> cwindow<CR>

:help grep
:help copen
:help quickfix

Reference
http://stackoverflow.com/questions/1234394/selecting-resulting-files-from-grep-in-vim
http://stackoverflow.com/questions/6373293/vim-how-to-store-the-grep-results-in-a-buffer
http://vim.wikia.com/wiki/Find_in_files_within_Vim

Wednesday, February 1, 2012

Using vim + xdebug to debug php On FreeBSD

Using vim + xdebug to debug php On FreeBSD

Here is the scenario: You have multiple developers logged into a Linux server which is running Apache and PHP using Vim to write PHP code. They’re using error_log and echo statements to debug their code. It takes forever, it’s tedious and can result in bugs from forgotten debug statements. You stare enviously at .NET programmers with fancy debuggers (while you snicker knowing that you edit 10x faster with Vim anyways). But still, you know there has to be a better way.

There is.

Here’s how it works. You’re coding away in vim. You hit F5; Vim waits for a connection from the PHP server. You refresh the PHP page you’re working on. It attempts to contact Vim — connection successful. You are launched into a debugging session right inside Vim. You can step into, over, and out of statements, eval statements, get all variables in context, get and set properties, remove and set breakpoints, all on the fly. Finally, some real programming tools.

Install VIM
# cd /usr/ports/editors/vim
# make WITH_PYTHON=yes install
# cp /usr/local/share/vim/vim72/vimrc_example.vim ~/.vimrc

Make sure your VIM supported Python:
# vim --version | grep -E 'python|sign'

If you see "+python" and "+sign" you are good to go.
If you see "-python" and "-sign", please reinstall your vim with WITH_PYTHON=yes option

Install Xdebug client
Now that vim is ready, download the DBGp client script. Extract the two files (debugger.vim and debugger.py) to your vim plugin directory or your .vim home directory

In Vim 7.2 compiled on FreeBSD, the default load-for-everyone plugin location is /usr/local/share/vim/vim72/plugin/, so you would put both files in that directory.

Pick one of clients from:
DBGp client script: http://www.vim.org/scripts/script.php?script_id=2508
DBGp client script: http://www.vim.org/scripts/script.php?script_id=1929

Copy debugger.vim and debugger.py to either one of following directories:
/usr/local/share/vim/vim72/plugin
or
~/.vim/plugin

Try to run vim — if you get no errors, everything should be good. If you get an error, double check :version to make sure +python and +signs are there. If they are, post a comment here with the vi error you get. If they aren’t, the vim compilation/installation didn’t work — go back and try it again.

Install xdebug (the server [engine])
# cd /usr/ports/devel/php-xdebug
# make install

# vim /usr/local/etc/php.ini
[Zend]
zend_extension = /usr/local/lib/php/20060613/xdebug.so

; This switch controls whether Xdebug should try to contact a debug client which is listening on the host and port as set with the settings xdebug.remote_host and xdebug.remote_port.
xdebug.remote_enable = 0
xdebug.remote_port = 9000
xdebug.remote_host = localhost

; When this setting is set to on, the tracing of function calls will be enabled just before the script is run. This makes it possible to trace code in the auto_prepend_file.
xdebug.auto_trace = 1
xdebug.trace_output_dir = "/tmp/xdebug/log"
xdebug.collect_params = 4

;xdebug.var_display_max_children = 128
;xdebug.var_display_max_data = 512
;xdebug.var_display_max_depth = 3

; Enables Xdebug's profiler which creates files in the profile output directory. Those files can be read by KCacheGrind to visualize your data.
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp/xdebug/log"

; Controls the protection mechanism for infinite recursion protection. The value of this setting is the maximum level of nested functions that are allowed before the script will be aborted.
xdebug.max_nesting_level = 100

; shows a human readable / computer readable trace file.
xdebug.trace_format = 0

; This setting tells Xdebug to gather information about which variables are used in a certain scope. This analysis can be quite slow as Xdebug has to reverse engineer PHP's opcode arrays. This setting will not record which values the different variables have, for that use xdebug.collect_params. This setting needs to be enabled only if you wish to use xdebug_get_declared_vars().
xdebug.collect_vars = 0

; When set to '1' the trace files will be appended to, instead of being overwritten in subsequent requests.
; Note: this option can be useful if you could not find your function calls anywhere.
xdebug.trace_options = 1

Make sure xdebug is loaded by PHP
<?php
echo phpinfo();
?>

Now, with your site being example.com, go to http://example.com/index.php?XDEBUG_SESSION_START=1 (Add XDEBUG_SESSION_START=1 after your script name). This will set a cookie in your browser which expires in 1 hour which tells the PHP XDebug module to try to make a connection every time a page loads to a debugging client which is listening on port 9000. The cool thing is that if it can’t make a connection, it just keeps loading the page, so there’s no issue just leaving the cookie on.

Now go back to vim and press F5. You should see a message like “waiting for a new connection on port 9000 for 5 seconds…” at the bottom of the screen. You have five seconds to now refresh the PHP page. This will create a connection between the debugger and client. Now you’re debugging. Follow the instructions in the Help window to step into, over and out of code. Press F5 to run the code until a breakpoint (which you can set using :Bp).

When I pressed F1, F2, or F3 keys, it toggles the character to either upper or lower case.

To solve this problem, I changed following line:
map <F2> :python debugger_command('step_into')<cr>

To:
map ^[[12~ :python debugger_command('step_into')<cr>

Note: press ctrl-v F2 to generate ^[[12~.




But what if I have multiple developers on the same machine?

No problem. Simply set g:debuggerPort in each developer’s .vimrc to get the client listening on a different port. So if you wanted one developer to connect on 9001 instead of the standard 9000, you would add this line to their .vimrc:

let g:debuggerPort = 9001

Getting the server to connect on a different port is a little trickier. You need to set a custom php.ini value (xdebug.remote_port) for each user. It works best if you’re using VirtualHost’s in Apache. Just add the following line to the VirtualHost section of your httpd.conf:

php_value xdebug.remote_port 9001

Now restart Apache and if you use that VirtualHost and that vi user, then they should connect successfully.
That’s about it

Please post any questions or suggestions you may have. I hope this helps a few of you out there who want debugging tools but don’t want to give up Vim editing. Also be sure to post any alternate methods, or any patches or improvements to the remote PHP debugger vim script, and I’ll be sure to incorporate them.

[Note: This is the first in a series of posts we'll be doing along the lines of tutorials, tools we've developed, tech commentary, and so on. Please feel free to subscribe, as well as leave any comments, thoughts or suggestions below so we can be sure to improve with each article! Thanks!]

use XDebugToolkit to convert the XDebug cachegrind (= “xdebug.log“) to a dot graph
http://code.google.com/p/xdebugtoolkit/

# svn co http://xdebugtoolkit.googlecode.com/svn/tags/0.1.3/xdebugtoolkit/ xdebugtoolkit
# ./cg2dot.py cachegrind.out.23328 > cachegrind.out.23328.dot

# cd /usr/ports/graphics/graphviz ; make install ; rehash
# dot -Tpng -otest.png

Combine to one command:
# ./cg2dot.py cachegrind.out.23328 | dot -Tpng -otest.png

this might be useful /usr/ports/graphics/py-pydot ??

Windows version of Graphviz is also available at:
http://www.graphviz.org/Download..php

[] XDot - Interactive viewer for Graphviz dot files

[] CacheGrind

[] WinCacheGrind (for Windows)

[] CacheGrindvisualizer

[] Graphviz - Graph Visualization Software

[] ZGRViewer - a GraphViz/DOT Viewer

[] Dot Language

[] Scalable Vector Graphics (SVG)

Reference:
How to Debug PHP with Vim and XDebug on Linux