2013年10月25日 星期五

vim 搜尋字串取代成具有空白字元的字串

 

請問大家
如何將各Arithmetic operators 算術運算子及邏輯運算子
的前後加上空格.
像是
a=b;
應為
a = b;
而對於邏輯運算子也應該用上.
不知大家都是如何去處理的?

目前都是寫完後再用搜尋取代方式(:%s/=/ = /gc)
但這樣做跟一行一行檢查一樣,而且不方便.

我想這部份可能需要用Regexp 常規表示式.
對於這個Regexp如何表示?
(+,-,*,/,+=,-=,/=,*= and ==,!=,<,>,...)
並避開一些command用的(//,/****,*/)

---------------------------------------------------------

因為,突然工作上被要求這樣..

雖然在原本的vim上,我也會有vim內建的"auto format", select all , press “=”

但是卻不能夠,滿足上述的要求,所以上網查詢了相關的"issue"。

很快地就得到了" Artistic" tool.

 

像是 opeator –pad

image

在使用原本的auto format

image

而使用" Artistic" tool.

image

如此,

1.各 opeator 和 operand 之間, 都會加上一個space pad

2.設定各indent 4 space

3.單行的判斷式,會自己加上一個brack

 

A.

download Artistic

http://sourceforge.net/projects/astyle/

 

B.steup (on windows to vim)

   1.to compress the

image

  2. select the bin document

image

  3.copy the astyle.exe to vim director

    同使用diff.exe .方式

  4.

    在vimrc中加入

map ,fc  <Esc>:%!astyle --style=ansi --pad-oper --min-conditional-indent=0 --max-code-length=120 --add-brackets --break-blocks --delete-empty-lines --indent=spaces=4<CR>

  5.當然,你也可以直接使用下command 去執行astyle (也可寫成batch file)

     同astyle --style=ansi --pad-oper --min-conditional-indent=0 --max-code-length=120 --add-brackets --break-blocks --delete-empty-lines --indent=spaces=4 <input file name>

 

 

Reference :

Artistic :

http://astyle.sourceforge.net/astyle.html#_pad-oper

Automatically formatting (adding spaces:

http://vim.1045645.n5.nabble.com/Automatically-formatting-adding-spaces-td1190147.html

工具使用] 代码排版 astyle

http://godbms.blogspot.tw/2012/02/astyle.html

代码排版工具——astyle

http://www.shui6.com/viewthread.php?tid=353

Auto format c file in vim

http://stackoverflow.com/questions/2355834/auto-format-c-file-in-vim

2013年10月13日 星期日

ssh sever & sftp

1.安裝

2.設定

3.使用方式

4.問題

 

一、安裝

不論是ssh server 或是sftp

都包在openssh-server package中,所以只需安裝openssh-server即可。

sduo apt-get install openssh-server

image


二、設定


其相關的設定在 /etc/ssh/sshd_config


    A.ssh


       只需去確定其port number即可。


       也可以去設定其只有那些IP可連進等。


   B. sftp(這裡我是先加入一個user and group for sftp,然後再將原本的加入此group來使用)


       若不新增for sftp user and group 則需將 其sshd_config中修改(去sftpusers-->use_group)



i:




/etc/ssh/sshd_config and add/edit the following lines:
 
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp -f AUTH -1 VERBOSE
 
#Uncomment this line if already commented
UsePAM yes
 
AllowGroups sftpusers sftp
 
Match Group sftpusers
ChrootDirectory %h
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp

ii:


create the relevant users & groups


 



sudo groupadd sftpusers

 


create a user suppose sftpuser



sudo adduser sftpuser
sudo usermod -a -G sftpusers sftpuser
sudo passwd sftpuser

 


iii:



sudo chown root:sftpuser /home/sftpuser
sudo chmod 750 /home/sftpuser

 


iv: to check the sftp



sftp -vvv sftpuser@localhost

v: to add exit_user to group and open the sftp 權限:



sudo usermod -a -G sftpusers steven
egrep -i "^sftp" /etc/group
sudo ls -l /home
sudo chmod u=rwx,g=rwx /home/sftpuser
 

image


image


image


image


三、使用


ssh service:


   ssh username@serviceaddress


   若無法成功時,可加上-vvv


   ssh –vvv username@serviceaddress


image


image


sftp service:


image


image


 


問題:


在使用時,有遇到下列的問題(未解決,因不知原由):


1.ICEau


2.ssh connect refuse


3.ssh connect termiaal


 


主要是因為我是先設ssh再sftp 並重開機。


它的某一個會導致 ssh server的路徑出錯.


/var/log/auth.log

May  9 14:45:48 nj sshd[5074]: pam_unix(sshd:session): session opened for user bob by (uid=0)
May 9 14:45:48 nj sshd[5091]: fatal: bad ownership or modes for chroot directory component "/home/bob/"
May 9 14:45:48 nj sshd[5074]: pam_unix(sshd:session): session closed for user bob


ChrootDirectory /路徑
 
         AllowTcpForwarding no
 
         X11Forwarding no
 
         ForceCommand internal-sftp

必須改為:


Match Group(user) 帳號


         ChrootDirectory /路徑

         AllowTcpForwarding no

         X11Forwarding no

         ForceCommand internal-sftp

其中,其ChrootDirectory 必為root的權限.

所以你應該設為/home

 

 

參考:


 http://linux.vbird.org/linux_basic/0210filepermission.php#filepermission_ch


http://www.ubuntulinuxhelp.com/how-to-ssh-on-ubuntu-a-simple-guide/


http://askubuntu.com/questions/192401/where-is-the-default-tmux-conf-file-located


http://askubuntu.com/questions/81293/what-is-the-command-to-update-time-and-date-from-internet


http://www.pool.ntp.org/zone/asia


http://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/


http://winscp.net/eng/download.php


http://www.serverubuntu.it/SFTP-chroot


http://blog.srmklive.com/2013/04/24/how-to-setup-sftp-server-ftp-over-ssh-in-ubuntu/


http://chunann.wikidot.com/chown


http://nixcraft.com/ubuntu-debian/8555-ubuntu-linux-add-user-group.html


http://bruce-wang.blogspot.tw/2009/01/vim.html


http://blog.linweiyan.com/2011/08/vim.html


http://www.ewdna.com/2012/06/ubuntu-ssh-server.html


http://blog.yam.com/sawalammx/article/5845114


http://www.cyberciti.biz/faq/linux-check-existing-groups-users/


http://ubuntuforums.org/showthread.php?t=2071536


http://stackoverflow.com/questions/17335728/connect-to-host-localhost-port-22-connection-refused


http://www.ascc.sinica.edu.tw/winscp

2013年10月5日 星期六

虛擬終端機(terminal)-rxvt

image

在我的like-unix上,又加上一個terminal了(rxvt)

看起來還不錯的。(cygwin terminal(DOS) 、rxvt and ssh client)

 

在找cygwin看看有什麼有趣的東西時,看到rxvt

它是用來代替本來cygwin -DOS 端端機。

它同樣原本在linux上的東西。

 

而在cygwin上,比起DOS中,多了

1.更多的設定

2.原生的linux

3.可以複制到windows

 

 

 

 

reference:

cygwin:

http://zh.wikipedia.org/zh-tw/Cygwin

x-windows

http://zh.wikipedia.org/wiki/X_Window_System

虛擬終端

http://zh.wikipedia.org/wiki/%E8%99%9A%E6%8B%9F%E7%BB%88%E7%AB%AF