Octopress 部落格

一個靜態網站的部落格框架

Vim 筆記(八)

寫程式時,需要快速找到相對映的大括號,中括號,小括號,可以按 % 去尋找!

避免使用滑鼠時按到中間滾輪時是貼上
” Mouse wheel for scroll only - disable middle button paste
:map
:imap

Python 的 Class 寫法

class chello:
def show(self):
return “hello world class!”

a = chello();
print a.show();

or

class chello:
@property
def show(self):
return “hello world class!”

a = chello()
print a.show

or

#!/usr/bin/python
class chello:
def show(self):
return “hello world class!”

x = chello();
print x.show();

or

class chello:
@classmethod
def show(self):
return “hello class world123!”

a = chello()
print a.show()

Vim 筆記(七)

” 設定TXT副檔名使用todolist的顏色格式
au BufRead,BufNewFile *.txt setfiletype todotxt

” 設定在按下Enter後可以新增一行
” Insert newline without entering insert mode
map O
map o

” 設定按下F3可以產生日期標記
” To insert timestamp, press F3.
nmap a=strftime(“%Y-%m-%d %a %I:%M %p”)
imap =strftime(“%Y-%m-%d %a %I:%M %p”)

” 設定可見的書籤
” 設定書籤(Markers), F5 設定此行 F6 移除此行書籤
:highlight SignColumn guibg=darkgrey
:sign define piet text=>> texthl=Search

function! SignFixme()
execute(“:sign place “.line(“.”).” line=”.line(“.”).” name=piet file=”.expand(“%:p”))
endfunction
map :call SignFixme()

function! SignLines()
execute(“:sign unplace “.line(“.”))
endfunction
map :call SignLines()

” 設定移動 buffers(需配合minibufexpl.vim套件)
map :bn
map :bp

” 設定關閉 swap 功能
:set noswf

” 設定按 Ctrl+s 存檔
:nmap :w
:imap :w

” 設定PHP摺疊
set foldmarker=}
set foldmethod=marker
set foldlevel=2 ” 預設全部關閉
let php_folding = 1 ” 這個很重要
set foldnestmax=3

””“”“”“”“”“”“”“”“”“”“”“””
” tags(需要搭配ctags.exe)
””“”“”“”“”“”“”“”“”“”“”“””
let Tlist_Ctags_Cmd=’C:\vim\vim72\ctags.exe’
let g:showfuncctagsbin = ‘c:\vim\vim72\ctags.exe’

set tags=tags;
set autochdir
set tagrelative

” 我的 statusline 設定
set ls=2 “laststatus
set statusline=[%n]
set statusline+=%<\ "cut at start set statusline+=%<%F "顯示檔案名稱 set statusline+=\ [%{(&fenc==\"\")?&enc:&fenc}, " encoding set statusline+=%{&fileformat} " file format set statusline+=%{(&bomb?\",BOM\":\"\")}] " detect bomb set statusline+=%=Lines:%L "顯示行數 set statusline+=\ [%p%%] "顯示游標所在整的檔案的百分比位置 set statusline+=\ \ Ln:%l,\ Col:%c "顯示行列位置 set statusline+=\ %([%1*%M%*%R%Y]%) "設定是否修改、是否唯讀、檔案副檔名 " 設定按 Ctrl+F3 去開關menu和toolbar map : if &guioptions =~# ‘T’
\set guioptions-=T
\set guioptions-=m
\else
\set guioptions+=T
\set guioptions+=m
\endif

“設定tab在vim裡頭佔的空白格數
set tabstop=4

” 設定編碼
let $LANG=”zh_TW.UTF-8”
set termencoding=utf8
set encoding=utf-8

Vim筆記(六)

Highlight 命令(觀看Vim所有顏色的名稱)
:so $VIMRUNTIME/syntax/hitest.vim

試用了幾個想用Vim 打一些平常的紀錄,
像task,也像todolist, 也像yaml ,
所以上網找了一些格式的顏色,但是沒有看到比較好的,
找到了 todolist.vim ,感覺還不錯, txt.vim 也不錯
還有 yaml.vim , 不知道有沒有比較好的…還在找尋中…….

設定為
:set ft=todolsit
:set ft=yaml
:set ft=txt
這些syntax 可以到 vim 的 script 內下載!!

Vim筆記(五)

剛剛在 c9s 的 blog 中看到要修改並刪除一個字的按鍵:
ciw –>還蠻好用的

將有 bomb 的字元移除,但要小心,有時後移除後存檔,檔案文字會亂掉
:set nobomb

轉換編碼
:e ++enc=ucs-2le xxxx(檔案名稱)
:w ++enc=ucs-2le xxxx(檔案名稱)

Vim筆記(四)

將目前程式作縮排排版
gg=G

移動到檔案頭
[]

移動到檔案尾
][

找文件內的關鍵字
在關鍵字上按 * 或是按 gd , 就會將關鍵字反白.

搜尋多的檔案內中的關鍵字(搜尋所有php檔案,檔案裡面有test的關鍵字
:vimgrep /test/*.php

用vimgrep 搜尋完後,用 :copen 開啟搜尋後結果,
或是用 :clist 觀看搜尋結果

設定書籤(Markers), F5 設定此行 F6 移除此行書籤
:highlight SignColumn guibg=darkgrey
:sign define piet text=>> texthl=Search

function! SignFixme()
execute(“:sign place “.line(“.”).” line=”.line(“.”).” name=piet file=”.expand(“%:p”))
endfunction
map :call SignFixme()

function! SignLines()
execute(“:sign unplace “.line(“.”))
endfunction
map :call SignLines()

將vim中複製的資料,存到windows的剪貼簿
用 shift+v , 框起需要複製的行數,
之後,按下 Ctrl+C, 就會複製到 windows的剪貼簿內!

Vim筆記(三)

Vim 全選:
ggVG

消除^M:
:%/^M//gg (^M 為 Ctrl+Q 再按 ctrl+M)

將兩個以上空白替換成一個空白
:%s/\([ ]\{2,\}\)/ /gg

Vim筆記(二)

設定如果有出現 Error 這個字的話, 就會將這個字以紅底白字顯示
:match ErrorMsg /^Error/

如果要看有哪些顏色群組可以用,可以下
:so $VIMRUNTIME/syntax/hitest.vim

移除效果:
:match NONE

自定顏色群組:
highlight MyGroup ctermbg=red guibg=red guifg=yellow term=bold

Vim筆記

Windows 下:
視窗最大化: alt+space+x
視窗最小化: alt+space+n
視窗還原大小: alt+space+r

Vim 下:
回到行的最前面: 數字0
回到行的最後面: $
自動換行: :set wrap
不換行: :set nowrap
方向鍵:左、下、上、右:h、j、k、l
複製一個字: yw
複製資料到buffer內,才能用yy,p
set nocompatible

設定程式語法顏色開啟:
syntax on
syntax off (關閉)

設定不要Toolbar
:set guioptions-=T

設定左邊有滾輪
:set guioptions+=l

設定可以左右移動的滾輪
:set guioptions+=b

設定Menu不顯示
:set guioptions-=m

設定右邊的滾輪不顯示
:set guioptions-=r

設定沒有GUI的TAB
:set guioptions-=e

設定游標整行會有顏色(Vim 7.0以上)
:set cursorline

設定游標整列會有顏色(Vim 7.0以上)
:set cursorcolumn

設定滑鼠模式:
:behave mswin
:behave xterm

顯示看不見的字元
:set list
:set nolist

選擇字體
:set guifont=*

設定檔案是否備份
:set backup
:set nobackup

比較兩份文件
先用 splite 的方式打開兩份文件
:diffthis –>比較兩份文件
:diffupdate –>更新比較

跳出(離開)Vim
:qa

設定 Vim Session
:browse mksession(mks) –> 儲存Session
:mks session.vim –> 儲存Session
:mks! session.vim –> 再次儲存Session
vim -S session.vim –> 取出Session
:source(so) session.vim –> 取出Session

將行號加入到程式中
:%! nl -ba

加裝 MiniBufExplorer 之後, 所要使用的功能
切換 miniBufExpl 視窗的開關
:TMiniBufExplorer
d 刪除Buff
Ctrl+Tab 再按Shift+Tab (可以選擇Buff內的檔案)

自動縮排:
gg+v+G+=


GVIM 下的Ctrl+v 可以用 Ctrl+Q 來替代

所以, DOS下的有^M的符號,
可以用 %s/^M//gg 來去除掉

小數點可以重覆上個命令 .

開始選區塊按 v, 選完後按 y 是複製

觀看程式時, 選到要尋找的關鍵字處,
按下 * 可以尋找下個相同的關鍵字 !

用滑鼠將檔案拖曳(Drag)到Gvim後,會用tab開啟檔案
To open each buffer in its own tabpage, add this to your vimrc:
:au BufAdd,BufNewFile * nested tab sball

quickfix windows 編譯程式時出現訊息的視窗,可以用 :copen 開啟此視窗!