lefang的个人博客分享 http://blog.sciencenet.cn/u/lefang 湍流,计算流体力学

博文

几个vim模块和fortran环境的注释增强

已有 7695 次阅读 2010-6-15 16:08 |个人分类:GNU Linux|系统分类:科研笔记| vim

放在msn space总也找不着,又经常用,还是移到这里方便点。

python.vim: python相关增强
   ]t      -- 跳到模块开始
   ]e      -- 跳到模块结束
   ]v      -- 选取模块内容
   ]<      -- 模块左缩进
   ]>      -- 模块右缩进
   ]#      -- 注释所选部分
   ]u      -- 去掉所选部分的注释
   ]c      -- 选择当前类(包括定义)
   ]d      -- 选择当前模块(包括定义)
   ]<up>   -- 跳到当前缩进级别的上一句话
   ]<down> -- 跳到当前缩进级别的下一句话

vim spell: vim7.0以上自带的语法检查工具
在.vimrc里面设置键绑定:
:map <F8> :set spell<CR>
:map <C-F8> :set nospell<CR>
:map <F3> ]s
:setlocal spell spelllang=en_us
set nospell
以后要检查语法的时候按F8,检查完按Ctrl+F8。用F3到下一个语法有问题的词,用z=获得修改建议。

taglist: 可以列出程序的关键字并进行快速跳转
:map <F12> :TlistToggle<CR>
绑定到F12上
=========================================================================
python.vim里面的注释工具在fortran环境中的实现:
function! FortranCommentSelection()  range
  let commentString = "!"
  let cl = a:firstline
  let ind = 1000    " I hope nobody use so long lines! :)

  " Look for smallest indent
  while (cl <= a:lastline)
    if strlen(getline(cl))
      let cind = indent(cl)
      let ind = ((ind < cind) ? ind : cind)
    endif
    let cl = cl + 1
  endwhile
  if (ind == 1000)
    let ind = 1
  else
    let ind = ind + 1
  endif

  let cl = a:firstline
  execute ":".cl
  " Insert commentString in each non-empty line, in column ind
  while (cl <= a:lastline)
    if strlen(getline(cl))
      execute "normal ".ind."|i".commentString
    endif
    execute "normal <Down>"
    let cl = cl + 1
  endwhile
endfunction

function! FortranUncommentSelection()  range
  " commentString could be different than the one from CommentSelection()
  " For example, this could be "# \="
  let commentString = "!"
  let commentString1 = "C"
  let commentString2 = "c"
  let cl = a:firstline
  while (cl <= a:lastline)
    let ul = substitute(getline(cl),
             "\(\s*\)".commentString."\(.*\)$", "\1\2", "")
    let ul1 = substitute(getline(cl),
             "^".commentString1."\(.*\)$", "\1", "")
    let ul2 = substitute(getline(cl1),
             "^".commentString2."\(.*\)$", "\1", "")
    call setline(cl, ul2)
    let cl = cl + 1
  endwhile
endfunction

map  ]C   :call FortranCommentSelection()<CR>
vmap ]C   :call FortranCommentSelection()<CR>
map  ]U   :call FortranUncommentSelection()<CR>
vmap ]U   :call FortranUncommentSelection()<CR>

这样,按]C给选择的行增加注释,按]U给选择的行去掉注释
==========================================================================
后来又发现其实用NERD_commenter更好。只需要在.vimrc里面设置
filetype plugin on
filetype plugin indent on
之后,按,cc设置注释,按,cu取消注释


https://wap.sciencenet.cn/blog-423882-335674.html

上一篇:按段进行grep检索
下一篇:几个公开可下载的湍流数据库
收藏 IP: .*| 热度|

0

发表评论 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-25 21:47

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部