linux下vim自動在c檔案插入檔案頭,linuxvim

來源:互聯網
上載者:User

linux下vim自動在c檔案插入檔案頭,linuxvim

"建立.c,.h,.sh,.java檔案,自動插入檔案頭 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" """定義函數SetTitle,自動插入檔案頭 func SetTitle() "如果檔案類型為.sh檔案 if &filetype == 'sh' call setline(1,"\#########################################################################") call append(line("."), "\# File Name: ".expand("%")) call append(line(".")+1, "\# Author: pengzhen") call append(line(".")+2, "\# mail: pz9042@163.com") call append(line(".")+3, "\#Created Time:".strftime("%c")) call append(line(".")+4, "\#########################################################################") call append(line(".")+5,"\#!/bin/bash") call append(line(".")+6,"") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: pengzhen") call append(line(".")+2, " > Mail: pz9042@163.com ") call append(line(".")+3, " > Created Time: ".strftime("%c")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endifif &filetype == 'cpp'call append(line(".")+6, "#include<iostream>")call append(line(".")+7, "using namespace std;")call append(line(".")+8, "") endifif &filetype == 'c' call append(line(".")+6, "#include<stdio.h>")call append(line(".")+7, "") endif"建立檔案後,自動定位到檔案末尾autocmd BufNewFile * normal Gendfunc

  


怎在linux下用vim編寫一個C程式

先在終端中輸入
vim test.c

斷行符號進入vim編輯器,再按一下a鍵,進入編輯狀態,然後輸入如下C語言語句:

#include<stdio.h>
int main() {
printf("hello world!\n");
}

到此,按esc鍵退出編輯狀態,再輸入一個冒號(shift + 冒號分號那個鍵),緊跟著輸入 wq ,即 輸入

:wq

按斷行符號,即推出vim編輯器回到終端命令視窗(類似xp的命令提示字元),

之後輸入

gcc test.c ,這步是編譯

./a.out , 這是執行,將會輸出 hello world!

到此結束,前提是你已經安裝gcc
 
linux中vim編輯器怎把一個整個檔案裡的資料複製到另一個檔案中,詳細的按鍵解答

有個辦法,應該可行的。你試試(做好相關備份!)

比如說你要吧a.txt的東西複製到b.txt

用vim開啟b.txt。將游標定位到要複製插入的位置,然後進入命令模式中輸入
:r!cat a.txt
接下來就是儲存啦,呵呵
:wq
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.