1. 程式人生 > >Vim學習筆記——定製你的Vim

Vim學習筆記——定製你的Vim

6.1 vimrc檔案

    如果你厭倦了手工鍵入常用的命令,或者要使你喜好的選項和對映一次性準備好,這時可以統統寫入到vimrc(vim run command)的檔案裡,Vim在啟動時會讀取這個檔案.

    vimrc位置:

    Unix and OS/2:  ~/.vimrc

    Windows      :  $VIM\_vimrc

6.2 vimrc示例檔案

" An example for a vimrc file.

    " Maintainer:       DaiDai

    " Last change:      2017年6月29日

    " When started as "evim", evim.vim will already have done these settings.

    if v:progname =~? "evim"

      finish

    endif

    " Use Vim settings, rather than Vi settings (much better!).

    " This must be first, because it changes other options as a side effect.

    set nocompatible

    " allow backspacing over everything in insert mode

    set backspace=indent,eol,start

    if has("vms")

      set nobackup              " do not keep a backup file, use versions instead

    else

      set backup                " keep a backup file (restore to previous version)

      set undofile              " keep an undo file (undo changes after closing)

    endif

    set history=50              " keep 50 lines of command line history

    set ruler           " show the cursor position all the time

    set showcmd         " display incomplete commands

    set incsearch               " do incremental searching

    " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries

    " let &guioptions = substitute(&guioptions, "t", "", "g")

    " Don't use Ex mode, use Q for formatting

    map Q gq

    " CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,

    " so that you can undo CTRL-U after inserting a line break.

    inoremap <C-U> <C-G>u<C-U>

    " In many terminal emulators the mouse works just fine, thus enable it.

    if has('mouse')

      set mouse=a

    endif

    " Switch syntax highlighting on, when the terminal has colors

    " Also switch on highlighting the last used search pattern.

    if &t_Co > 2 || has("gui_running")

      syntax on

    " 開啟語法高亮

      set hlsearch

    endif

    " Only do this part when compiled with support for autocommands.

    if has("autocmd")

      " Enable file type detection.

      " 'cindent' is on in C files, etc.

      " Also load indent files, to automatically do language-dependent indenting.

      " Put these in an autocmd group, so that we can delete them easily.

      augroup vimrcEx

      au!

     " For all text files set 'textwidth' to 78 characters.

      autocmd FileType text setlocal textwidth=78

      " When editing a file, always jump to the last known cursor position.

      " Don't do it when the position is invalid or when inside an event handler

      " (happens when dropping a file on gvim).

      autocmd BufReadPost *

        \ if line("'\"") >= 1 && line("'\"") <= line("$") |

        \   exe "normal! g`\"" |

        \ endif

      augroup END

    else

      set autoindent            " always set autoindenting on

    endif " has("autocmd")

    " Convenient command to see the difference between the current buffer and the

    " file it was loaded from, thus the changes you made.

    " Only define it when not defined already.

    if !exists(":DiffOrig")

      command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis

                      \ | wincmd p | diffthis

    endif

    if has('langmap') && exists('+langnoremap')

      " Prevent that the langmap option applies to characters that result from a

      " mapping.  If unset (default), this may break plugins (but it's backward

      " compatible).

      set langnoremap

    endif

    " Add optional packages.

    "

    " The matchit plugin makes the % command work better, but it is not backwards

    " compatible.

    packadd matchit

6.3 簡單的對映

    一個對映可以把一連串Vim命令用一個按鍵來表示.

    如:用一個功能鍵或字串,將某個word單詞,變成{word},可以使用:map命令.

    :map <F5> i{<Esc>ea}<Esc>

    :map \abc i{<Esc>ea}<Esc>

    {amount}

6.4 選項視窗

    :options命令:在幫助主題中尋找或設定相應的選項.

    " Each "set" line shows the current value of an option (on the left).

    " Hit <CR> on a "set" line to execute it.

    "            A boolean option will be toggled.

    "            For other options you can edit the value before hitting <CR>.

    " Hit <CR> on a help line to open a help window on this option.

    " Hit <CR> on an index line to jump there.

    " Hit <Space> on a "set" line to refresh it.

    :set all命令:檢視所有的設定選項.

6.5 常用選項

    :help 'wrap':檢視某個選項的幫助.

    :set shiftwidth&:shiftwidth修改為預設值8.

    set nowrap:不要折行.

    set sidescroll=10:自動左右滾動10個字元.

    set whichwrap=b,s :跨行移動命令

    set whichwrap=b,s,<,> :跨行移動命令 智慧上上下下

    set whichwrap=b,s,<,>,[,] :跨行移動命令 智慧上上下下 Insert模式下,也能如此.

    set list  :show <Tab> as ^I and end-of-line as $ 顯示特殊字元如Tab或換行符

    set listchars=tab:>-,trail:-,eol:$$  :修改樣式

    set [email protected],48-57,_,192-255      :關鍵字預設字元要求 @:代表所有的字母;48-57 ASCII從48>到57 即0到9;192-225 可以列印的字元;

    set iskeyword+=-  :增加連詞符

    set iskeyword-=-  :去掉連詞符

        fdafd-fdasfdasfs

    set cmdheight=3 :number of lines used for the command-line 命令列高度.

6.6 使用高亮

    :syntax enable:開啟語法支援

    :set filetype=c     :改變當前檔案所屬型別.

    :set filetype=java  :int boolean

    :set filetype=vim

    :syntax clear  關閉當前高亮.

    :colorscheme evening:開啟不同的顏色主題.

相關推薦

Vim學習筆記——定製Vim

6.1 vimrc檔案     如果你厭倦了手工鍵入常用的命令,或者要使你喜好的選項和對映一次性準備好,這時可以統統寫入到vimrc(vim run command)的檔案裡,Vim在啟動時會讀取這個檔案.     vimrc位置:     Unix and OS/2:

vim 學習筆記 (轉載)

vim簡單使用教程 vim的學習曲線相當的大(參看各種文字編輯器的學習曲線),所以,如果你一開始看到的是一大堆VIM的命令分類,你一定會對這個編輯器失去興趣的。下面的文章翻譯自《Learn Vim Progressively》,我覺得這是給新手最好的VIM的升級

Vim學習筆記

vim 學習筆記 Notes: ":x":表示在普通模式下輸入:x,所有命令均區分大小寫 vim 初步 使用vim 在命令列鍵入命令即可使用 vim: vim file.txt 以波紋線 (~) 開頭的行表示該行在檔案中不存在。換句話說,如果 Vim 開啟的

[Vim]vim學習筆記--多個檔案開啟,切換,關閉

一種情況是在shell中用vim開啟多個檔案,另一種是在vim編輯器中開啟多個檔案 同時開啟多個檔案 vim file1 file2  開啟檔案並水平視窗顯示 vim -o file1 f

vim 學習筆記系列(前言)

今天上午的時候,看到大神在用vim程式設計,畫面直觀,速度很快,操作只需要用命令符就可以實施。 所以可以推斷vim的命令符是複雜的,那麼學習過程中記憶會很漫長,很痛苦,但是如果記住了這些命令符,並可

linux vim學習筆記

在命令列輸入vimtutor可以進入教程學習介面,可以邊操作邊學習.教程包括以下知識點: (所有字母表示鍵盤按鍵,連在一起的字母表示按順序按,使用+連線的字母表示一起按,字母大小寫有的含義不同) 1.1 h 向左(同鍵盤←), l 向右(同鍵盤→), j 向下(同鍵盤↓),

vim學習筆記-問題與技巧彙總

1.問題 1.1. 亂碼 local與檔案編碼不同導致,編輯~/.vimrc或者C:/Program Files/Vim/_vimrc,加入如下設定:set fencs=utf-8,gbk set fileencoding=gb18030 set fileencodings=

vim學習筆記--程式碼摺疊

對於很長的程式碼段,摺疊可以讓我們更快的瀏覽到我們想要瀏覽的內容,幫助手冊裡面內容很多,寫一些覺得目前對自己有用的。 一些摺疊命令 zfap 使用這個命令時就會建立一段文字摺疊

vim學習筆記(1)——vim操作

僅記錄一些自己最常用的vim操作,隨時更新 文字操作 d 剪下,雙擊剪下一行 y 複製,雙擊複製一行 p 貼上 x 刪除當前游標下字元 r 替換當前游標字元,後面接替換的字元 :s/old/new/g 全域性替換old為new

Linux學習筆記(七)----使用vim編輯器

vim編輯器在記憶體緩衝區中處理資料vim   filenamevim 三個模式在指令列模式下,有以下命令用於離開或者儲存檔案。命令作用:w寫入磁碟:w!當檔案為只讀時,強制寫入磁碟。到底能不能寫入,與使用者對該檔案的許可權有關:q離開:q!強制離開不儲存:wq寫入磁碟後離開

VIM學習筆記 縮排 (Indent)

手動縮排 在Normal Mode下,命令>>將對當前行增加縮排,而命令<<則將對當前行減少縮排。我們可以在命令前使用數字,來指定命令作用的範圍。例如以下命令,將減少5行的縮排: 5<< 在Insert/Repl

Hive學習筆記想知道的Hive

one 什麽 pac 語句 工具 center 版本 推薦 serve 1、 什麽是Hive(蜂巢)?   Hive是基於Hadoop的一個數據倉庫工具,可以將結構化的數據文件映射為一張數據庫表,並提供類SQL查詢功能。Hive是基於HDFS之上的數據倉庫,也就是說Hive

Hbase學習筆記想知道的Hbase

1、 什麼是Hbase?   HBase是一個構建在HDFS之上的、分散式的、面向列的開源資料庫,不同於一般的關係資料庫,它是一個適合於非結構化海量資料儲存的資料庫,是由Google Bigtable的開源實現,它主要用於儲存海量資料,是Hadoop生態系統中的重要一員。Hbase可以使用shell、web

吳恩達深度學習筆記(34)-不知道的其他正則化方法

其他正則化方法(Other regularization methods) 除了L2正則化和隨機失活(dropout)正則化,還有幾種方法可以減少神經網路中的過擬合: 一.資料擴增 假設你正在擬合貓咪圖片分類器,如果你想通過擴增訓練資料來解決過擬合,但擴增資料代價高,而且有

[ExtJS5學習筆記]第二節 Sencha Cmd 學習筆記 使的sencha cmd跑起來

本文地址: http://blog.csdn.net/sushengmiyan/article/details/38313537 本文作者:sushengmiyan ------------------------------------------------------

vim學習筆記

一個 opera -i 退出vim ctrl 回車 做的 刪除 輸入 文本編輯 1.光標在屏幕文本中的移動既可以用箭頭鍵,也可以用hjkl字母鍵。 h 左移 j 下移 k 上移 l 右移 2.欲進入vim編輯器(從命令提示行),請輸入:vim 文件名<回車>

vim的命令學習筆記

vimvim有兩種模式,命令模式和編輯模式,模式切換鍵為Esc。在命令模式下常用的位移按鍵有h前移一字,j下移一行,k上移一行,l後移一字;詞位移w後移一詞,b前移一詞;校對編輯:i插入,a添加,c更改,d刪除。本文出自 “johjoh” 博客,請務必保留此出處http://johjoh.blog.51cto

Linux學習筆記vim編輯技巧

vim linux學習筆記 linux vim編輯技巧 vim,一個純文本(純文本信息,ASCII text)編輯器,Vi(Visual Interface) IMproved,是一個模式化的編輯器。> vim有自帶的教程,也是linux的一個內置命令一、基本模式分類1 編輯模式(命令模式)

Linux學習筆記(二)---VIM

ext vpd img ffffff linux學習 -o 學習 shadow fff Linux學習筆記(二)---VIM

Linux學習筆記(十七) vim

vim一、vim介紹vim是vi的升級版是帶有顏色顯示的vi分為一般模式、編輯模式、命令模式。yum install -y vim-enhanced安裝vim安裝完成之後使用vim打開passwdvim /etc/passwd和之前用vi打開有明顯的區別,vim帶有顏色顯示,二、vim顏色顯示和移動光標將/e