Get name of the current file in Vim

后端 未结 6 1450
清歌不尽
清歌不尽 2020-12-14 00:52

I\'m trying to find the name of the file I\'m editing inside of Vim. So I can use it to map F5 to compile this file. Would of course be great if I could recognize

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-14 01:38

    The other points are very useful. I would add that you probably want to use :p, to ensure that the file name is passed as a fully qualified path. Without it, Vim may pass it as a path that is relative to Vim's current path, which may or may not be the same path as the compiler uses. So one solution is:

    nnoremap   :!javac %:p
    

    If you want to detect the file type automatically you could use AutoCommand

    autocmd FileType java       nnoremap    :!javac %:p
    autocmd FileType cpp        nnoremap    :!gcc %:p
    

提交回复
热议问题