Unix/Linux er的常规编辑器vi,emacs。楼猪比较习惯使用vi。
我对编辑器的要求比较少:
语法高亮;显示行号;对齐;文件头显示作者、时间等信息
显示本文件的函数,宏等; 可以在函数定义、函数调用之间切换
使用分三部分来说:
1.vi的常用命令
插入i【在前】,a【在后】
删除d dw单词, dd一行, D本行光标以后
删除多行 n, md 4,7d删除4到7行
移动 3,7mo10 3,到7行移动到10行下
快速跳转:
文件头 g
文件末尾G
% 匹配{} ,()
*
和 #
匹配光标当前所在的单词,移动光标到下一个(或上一个)匹配单词(*是下一个,#是上一个)
sp 水平(上下)分割窗口
vs 垂直(左右)分割窗口
2.vi的设置
set syntax=on
set filetype=c
set nu
########【详见http://linux-wiki.cn/wiki/zh-hans/Vim%E4%BB%A3%E7%A0%81%E7%BC%A9%E8%BF%9B%E8%AE%BE%E7%BD%AE】
######tabstop
set ts=4
#######shiftwidth每层缩进
set sw=4
set tags=tags;
set autochdir
set hlsearch //文件中搜索的单词高亮显示,nosearch取消高亮;原来vim默认设置,ubuntu没有很不习惯
set cc=80 //需要vim 7.2以上版本,红线限制每行的长度,要有美观撒
"programm info
"map <F4> :call TitleDet()<cr>'s //这个写法是错误滴,E20: Mark not set
"http://stackoverflow.com/questions/15554107/an-e20-mark-not-set-when-try-to-update-info-in-vim
"what is the 's at the end ?? do you have mark s?
map <F4> :call TitleDet()<cr>
function AddTitle()
call append(0, "/*===============================================================")
call append(1, "*")
call append(2, "* Author: clark")
call append(3, "*")
call append(4, "* E-mail: ")
call append(5, "*")
call append(6, "* company: myself")
call append(7, "*")
call append(8, "* Last modified: ".strftime("%Y-%m-%d %H:%M"))
call append(9, "*")
call append(10, "* Filename: ".expand("%:t"))
call append(11, "*")
call append(12, "* Description: ")
call append(13, "*")
call append(14, "===============================================================*/")
echohl WarningMsg | echo "Successful in adding the copyright." | echohl None
endfunction
function UpdateTitle()
normal m'
execute '/* *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/* *Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function TitleDet()
while n < 14
let line = getline(n)
if line =~ '^\*\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
3.ctags及taglist
ctags安装设置
$ tar -xzvf ctags-5.8.tar.gz
$ cd ctags-5.8
$ cd ctags-5.8
./configure --prefix=你的目录
$ make
$ make
make install
在.vimrc中添加
set tags=tags; //一定要有;否则报E257: cstag: tag not found
set autochdir
set autochdir
跳转到源文件目录
ctags -R
然后打开源文件就可
ctrl+] 跳转到定义;
ctrl+T跳转回调用了
PS: 网上有的说在vim上添加 :set tags=/home/username/vim71/tags;我的没有设置,可能是ctags版本比较高吧
TagList
http://www.vim.org/scripts/script.php?script_id=273
taglist_45.zip
在.vim下解压
unzip taglist_45.zip
在 .vimrc添加
let Tlist_Show_One_File=1 //只展示一个文件的Tlist,个人习惯
let Tlist_Exit_OnlyWindow=1
let Tlist_Exit_OnlyWindow=1
打开main.c, 输入Tlist就可以在左侧显示函数,宏了
vim,ctags正常
输入Tlist,
Error detected while processing function <SNR>8_Tlist_Window_Toggle..<SNR>8_Tlist_Window_Open..<SNR>8_Tlist_Window_Refresh_File..<SNR>8_Tlist_Process_File:
line 83:
E484: Can't open file /tmp/v855390/0
line 83:
E484: Can't open file /tmp/v855390/0
建议在vimrc中添加 set shell=/bin/sh
ctags: unrecognized option '--format=2'
root的ctags (GNU Emacs 24.3)
在自己用户下安装 Exuberant Ctags 5.8
Tlist一直报“ctags: unrecognized option '--format=2'”
在 .vimrc 设置tlist的 ctags路径
let Tlist_Ctags_Cmd = '/home/XXXX/.local/bin/ctags'
4.关于中文
代码的注释是中文GBK
PS:可能是在windows下写的注释或者字体设置是gbk
我的ubuntu 是zh_CN.UTF-8,我还是很喜欢UTF-8
在.vimrc加上
set termencoding=&encoding 【termencoding前不要&,会报错哟】
set fileencodings=utf-8,gbk,ucs-bom,cp936
set fileencodings=utf-8,gbk,ucs-bom,cp936
就OK了,具体以后再补充
出处 http://blog.csdn.net/wooin/article/details/1858917
出处 http://coolshell.cn/articles/5426.html
4. SCRT字体设置
1》建议采用Fixedsys,可以支持中文,而且是粗体,字体不会发虚。
2》
鼠标复制、粘贴的设置 Options => Global Options => Terminal => Mouse设置