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

Monday, May 16, 2011

save a file in vim without root permission

it is easy:

:w !sudo tee %

that is it!

I don't know others. But when i use vim to edit a file, i alway forget that i may not have the needed permission to save it.

So quite often that after i did all my changes and found i can't save them, i have to exit vim and use 'sudo vim' to do it again.

This command really come in handy. But, what is tee?

tee is a command that displays or pipes the output of a command and copies it into a file or a variable. It is primarily used in conjunction with pipes and filters.

To know more about tee, check this:

Friday, March 18, 2011

VIM IDE for PHP

1. install the project plugin for VIM. Here is the link: http://www.vim.org/scripts/script.php?script_id=69

2.
sudo aptitude install exuberant-ctags
cd ~
wget http://rafal.zelazko.info/wp-content/uploads/ftp/vim-custom.tgz
tar -xvzf vim-custom.tgz -C ~

Link for step 2: The link: http://rafal.zelazko.info/2010/04/18/vim-php-symfony/

Friday, June 12, 2009

vim中大小写转化

vim中大小写转化的命令是
gu或者gU
形象一点的解释就是小u意味着转为小写;大U意味着转为大写.

剩下的就是对这两个命令的限定(限定操作的行,字母,单词)等等

1、整篇文章大写转化为小写
打开文件后,无须进入命令行模式。键入:ggguG

解释一下:ggguG分作三段gg gu G
gg=光标到文件第一个字符
gu=把选定范围全部小写
G=到文件结束
2、整篇文章小写转化为大写
打开文件后,无须进入命令行模式。键入:gggUG

解释一下:gggUG分作三段gg gU G
gg=光标到文件第一个字符
gU=把选定范围全部大写
G=到文件结束
3、只转化某个单词
guw 、gue
gUw、gUe
这样,光标后面的单词便会进行大小写转换
想转换5个单词的命令如下:
gu5w、gu5e
gU5w、gU5e
4、转换几行的大小写
将光标定位到想转换的行上,键入:1gU 从光标所在行 往下一行都进行小写到大写的转换
10gU,则进行11行小写到大写的转换
以此类推,就出现其他的大小写转换命令
gU0 :从光标所在位置到行首,都变为大写
gU$ :从光标所在位置到行尾,都变为大写
gUG :从光标所在位置到文章最后一个字符,都变为大写
gU1G :从光标所在位置到文章第一个字符,都变为大写