免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5544 | 回复: 8
打印 上一主题 下一主题

vim中如何获取当前编辑文件的文件名 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-21 16:28 |只看该作者 |倒序浏览
经常用到在编辑完一个文档或者程序时要用到latex ***.tex, g++ ***.cpp,有没有快捷键直接将文件名弄到vim的命令行上,我知道<C-R>+寄存器可以将复制的内容输出到命令行,怎么将文件名复制过来,因为经常用到,所以应该会有快捷键,希望高手来指导指导

论坛徽章:
0
2 [报告]
发表于 2011-05-21 17:47 |只看该作者
本帖最后由 xiaopan3322 于 2011-05-21 17:48 编辑

How about this:

Sometimes I need to use the name of the file that I'm editing in another application (compiler, e-mail attachment, reference in a document, etc).

These mappings are useful for copying the file name to the clipboard.

" Convert slashes to backslashes for Windows.
if has('win32')
  nmap ,cs :let @*=substitute(expand("%"), "/", "\\", "g")<CR>
  nmap ,cl :let @*=substitute(expand("%:p"), "/", "\\", "g")<CR>

  " This will copy the path in 8.3 short format, for DOS and Windows 9x
  nmap ,c8 :let @*=substitute(expand("%:p:8"), "/", "\\", "g")<CR>
else
  nmap ,cs :let @*=expand("%")<CR>
  nmap ,cl :let @*=expand("%:p")<CR>
endif

This maps the following keys:

    ,cs copies just the filename.
    ,cl copies the filename including it's full path.
    ,c8 copies the filename in 8.3 format for DOS and Windows 9x

You can then simply paste the name into another document using the regular paste command.

Copying to the Gnome Clipboard Edit Copying to the Gnome Clipboard sectionEdit

Under linux, the script above will copy the file path or filename to X Server clipboard (accessed by pressing the middle mouse button). To copy text to the Gnome Clipboard instead replace the following lines:

  nmap ,cs :let @*=expand("%")<CR>
  nmap ,cl :let @*=expand("%:p")<CR>


with

  nmap ,cs :let @+=expand("%")<CR>
  nmap ,cl :let @+=expand("%:p")<CR>


This uses the + register instead of the * register.


Note: this may work with KDE and XCFE as well, I simply haven't tested (yet).

论坛徽章:
0
3 [报告]
发表于 2011-05-21 17:52 |只看该作者
还是这个意思?
  1. :g/^/pu!%
  2. :g/^/j
复制代码

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2011-05-21 22:19 |只看该作者
这样行不行?
  1. :!echo %
复制代码

论坛徽章:
0
5 [报告]
发表于 2011-05-21 22:44 |只看该作者
回复 3# xiaopan3322


    谢谢:)

我要的是这个

  1. :!latex %
复制代码

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
6 [报告]
发表于 2011-05-21 23:35 |只看该作者
回复  xiaopan3322


    谢谢:)

我要的是这个
kingoftime3 发表于 2011-05-21 22:44
请问那是一个什么命令?怎么我的vim中没有这个命令?

论坛徽章:
0
7 [报告]
发表于 2011-05-22 00:22 |只看该作者
回复 6# L_kernel


   
LaTeX is an extremely powerful, intelligent typesetter. Vim-LaTeX aims at bringing together the best of both these worlds.


    Refer to: http://vim-latex.sourceforge.net ... al&title=Manual

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2011-05-22 00:32 |只看该作者
原来如此,没有看到他问题当中的latex。

论坛徽章:
0
9 [报告]
发表于 2011-05-22 20:05 |只看该作者
set statusline=[T=%Y]\ %<%F%m%r%h\ \ %=%-7.(line=%l,col=%c%V,SumL=%L%)\%=%-7(,BfN=%n%)
在你的vim配置文件里加一行这个
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP