Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts

November 10, 2015

local vimrc

localrc repository

https://github.com/vim-scripts/localrc.vim
https://github.com/thinca/vim-localrc

.vimrc (with Vundle)

Bundle 'https://github.com/thinca/vim-localrc'
call localrc#load('.local.vimrc', getcwd())
.local.vimrc
setlocal tabstop=4
setlocal shiftwidth=4
setlocal softtabstop=4

April 15, 2013

October 27, 2010

vim 替換換行符號

:%s/ctrl-v ctrl-m/ctrl-v [enter]/g

August 13, 2010

開啟游標位置字串的檔案 (進階版)

基本用法參考這裡


進階設定
  • path - 到哪些路徑去尋找這個檔案
  • includeexpr - lua 跟 java 的 include path 是 dir1.dir2.file,可以修改要尋找的檔案字串
  • suffixesadd - 增加尋找的副檔名
範例
set includeexpr=substitue(v:fname,'\\.','/','g')
set suffixesadd=.lua,.java

June 17, 2010

vim 指令備忘 #1

  • :new 開新的水平分割空視窗
  • :vnew/:vne 開新的垂直分割空視窗
  • :read !cmd 讀進外部執行命令的結果

vim 比對 pattern 刪除

  • :g/pattern/d 刪除所有pattern所在的行
  • :g!/pattern/d 刪除所有pattern以外的行

December 30, 2009

vim 的 regular expression #2

route = "abc", name = "123"

如果只要 match route = "abc" 的話
用 route = [^,]*

December 04, 2009

開啟游標位置字串的檔案

游標移到想要開啟的檔案,如果檔名有空白,可以用 visual 選

  • gf (gotofile)
  • Ctrl-w + f: 在 split window 裡面開啟
  • Ctrl-w + gf: 在新 tab 開啟
Reference: http://vim.wikia.com/wiki/Open_file_under_cursor

June 02, 2009

vim 計算機

把選起來的區塊裡面的數字加上 250 的寫法

s/\%V\d\+/\=submatch(0)+250/

%V: visual block

搜尋 _[1-9]+_ 的數字再加上 2

s/_\([1-9]\+\)_/\="_".eval(submatch(1)+2)."_"/

字串要用 " " 表示,並用 . 串接起來

April 20, 2009

vim jumps

更詳細的說明

  • Ctrl-O 上一個頁面
  • Ctrl-I/Tab 下一個頁面
  • '[number] 跳到第number個頁面
  • :ju[mp] 列出所有的jump頁面

March 11, 2009

vim 的 regular expression #1

%s/[,]\{1,}$// - 把結尾一個到多個的 , 去除掉

  • \{1,} 至少一個
  • \{,1} 至多一個
Edit: 2009/9/8
%s/[,]\+$// - 用 + 取代 {1,}

December 15, 2008

vim的搜尋取代

參考B大的文章,把每次都會忘記的部份簡單記起來。

要搜尋的字串用 \(PATTERN\) 包起來,用\1,\2,...表示match到的pattern。

  • 貼上yank的字串 - Ctrl-R + 0(數字0)
  • 貼上前一次用 / 作 search 的字串 - Ctrl-R + /
-
我果然還是太菜了啊 ><

August 21, 2008

vim settings: ctags

  • 用 ctags -R * 建立 tags 檔
  • 在 .vimrc 裡面
    • set tags=[TAGFILE]
  • Ctrl-] 在同個視窗內跳到定義,Ctrl-W ] 開新視窗
    • 或是 :tag [TAG] 來跳到定義, :stag 開新視窗
    • :tn 跳到下一個符合的檔案, :tp 跳到上一個
  • Ctrl-T 跳回
  • g] 可以列出符合該 tag 的所有檔案
  • vim tags tip
  • a.vim - 快速在 .h 和 .cpp 兩個檔案切換
    • :A 切換.h/.cpp檔
    • :AS, :AV 在水平/垂直分割視窗開啟對應的.h/.cpp檔

January 25, 2008

Auto update last modified user/time vim script


From Tip #890: Last modified: <CURRENT DATETIME>

" Search the first 8 lines for Last Updated: and update the current user/datetime
function! LastMod()
 if &modified
  if line("$") > 8
   let l = 8
  else
   let l = line("$")
  endif
  let time = strftime("%m\\\/%d, %Y")
  exe "1," . l . "g/Last Updated: /s/Last Updated: .*/Last Updated: yyhuang " . time . "/"
  endif
endfun

" This autocommand will call LastMod function everytime you save a file
autocmd BufWrite * ks|call LastMod()|'s

June 14, 2007

vim: 搜尋快速鍵

* : 向後搜尋目前游標位置的字, 同 /\<word\>
# : 向前搜尋目前游標位置的字, 同 ?\<word\>
g* : /word
g# : ?word

Reference: http://www.vim.org/htmldoc/pattern.html##

這只是用來當筆記用的,想要更多更詳細 vim 的應用請看 http://greenisland.csie.nctu.edu.tw/wp/category/comuter/vim/