Me Myself and My way

Posts tagged ‘linux’

การปรับแต่ง vim ใน Ubuntu 7.10

เนื่องจากใน Ubuntu 7.10 vim ได้ปิดการใช้งาน syntax hilight และ auto indent ไว้ทำให้เวลาเขียน shell script ด้วย vim ใน ubuntu จะไม่มีการ hilight สีและ tab ให้(แบบในห้อง lab 303) เราจึงต้องมีการแก้อะไรสักหน่อยเพื่อให้มันใช้งานได้

ในขั้นแรกเราก็ต้อง install vim version ที่ใหม่กว่าที่มากับ ubuntu ซะก่อนด้วยคำสั่ง

  1. sudo apt-get install vim

หรือจะใช้

  1. sudo apt-get install gvim

ก็ได้ ตัวหลังจะเป็น vim ในแบบ application ที่ใช้ gui ของ GNOME แต่การ install จะลง library ของ vim ที่ต้องใช้ทั้งหมดเหมือนกันพอลงเสร็จแล้วก็เข้าไปแก้ไขใน file /etc/vim/vimrc โดยจะต้องมี permission เป็น su ด้วยถึงจะแก้ไขไฟล์นี้ได้ ใน ubuntu ใช้คำสั่ง

  1. sudo vim /etc/vim/vimrc

หาบรรทัดที่เขียนว่า

  1. ” Vim5 and later versions support syntax highlighting. Uncommenting the next
  2. ” line enables syntax highlighting by default.
  3. ” syntax on

เอา comment (“) ของบรรทัดสุดท้าย (syntax on) ออก ให้เป็นแบบนี้

  1. ” Vim5 and later versions support syntax highlighting. Uncommenting the next
  2. ” line enables syntax highlighting by default.
  3. syntax on

จะเป็นการเปิดใช้งาน syntax hilight ของ vimจากนั้นหาบรรทัด

  1. ” Uncomment the following to have Vim load indentation rules according to the
  2. ” detected filetype. Per default Debian Vim only load filetype specific
  3. ” plugins.
  4. ” if has(“autocmd”)
  5. ”  filetype indent on
  6. ” endif

เอา comment ตั้งแต่ if จนถึง endif ออกจะเป็นการเปิดใช้งาน autoindent ของ vimตัวอย่างไฟล์ /etc/vim/vimrc ที่ใช้งานได้.. (ถ้าไม่คิดอะไรมากก็ก๊อปไปแปะทับได้เลย)

  1. ” All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
  2. ” /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
  3. ” you can find below.  If you wish to change any of those settings, you should
  4. ” do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
  5. ” everytime an upgrade of the vim packages is performed.  It is recommended to
  6. ” make changes after sourcing debian.vim since it alters the value of the
  7. ” ‘compatible’ option.
  8. ” This line should not be removed as it ensures that various options are
  9. ” properly set to work with the Vim-related packages available in Debian.
  10. runtime! debian.vim
  11. ” Uncomment the next line to make Vim more Vi-compatible
  12. ” NOTE: debian.vim sets ‘nocompatible’.  Setting ‘compatible’ changes numerous
  13. ” options, so any other options should be set AFTER setting ‘compatible’.
  14. “set compatible
  15. ” Vim5 and later versions support syntax highlighting. Uncommenting the next
  16. ” line enables syntax highlighting by default.
  17. syntax on
  18. ” If using a dark background within the editing area and syntax highlighting
  19. ” turn on this option as well
  20. “set background=dark
  21. ” Uncomment the following to have Vim jump to the last position when
  22. ” reopening a file
  23. “if has(“autocmd”)
  24. ”  au BufReadPost * if line(“‘\””) > 0 && line(“‘\””) <= line(“$”)
  25. ”    \| exe “normal g’\”” | endif
  26. “endif
  27. ” Uncomment the following to have Vim load indentation rules according to the
  28. ” detected filetype. Per default Debian Vim only load filetype specific
  29. ” plugins.
  30. if has(“autocmd”)
  31.   filetype indent on
  32. endif
  33. ” The following are commented out as they cause vim to behave a lot
  34. ” differently from regular Vi. They are highly recommended though.
  35. “set showcmd            ” Show (partial) command in status line.
  36. “set showmatch          ” Show matching brackets.
  37. “set ignorecase         ” Do case insensitive matching
  38. “set smartcase          ” Do smart case matching
  39. “set incsearch          ” Incremental search
  40. “set autowrite          ” Automatically save before commands like :next and :make
  41. “set hidden             ” Hide buffers when they are abandoned
  42. “set mouse=a            ” Enable mouse usage (all modes) in terminals
  43. ” Source a global configuration file if available
  44. ” XXX Deprecated, please move your changes here in /etc/vim/vimrc
  45. if filereadable(“/etc/vim/vimrc.local”)
  46.   source /etc/vim/vimrc.local
  47. endif
นอกจากไปแก้ใน /etc/vim/vimrc แล้วยังทำได้อีกวิธีคือ สร้างไฟล์ .vimrc ไว้ใน home directory แล้วก็ใส่สองบรรทัดนี้ลงไป

  1. syntax on
  2. set autoindent

แต่วิธีนี้ยังไม่ได้ลอง แต่ดูแ้ล้วเป็นวิธีที่เค้านิยมใช้กันมากกว่าแก้ vimrc โดยตรงนะ

รายละเอียดเพิ่มเติมใน .vimrc ดูได้จาก http://www.csxix.com/?q=node/54

How to restore Grub from a live Ubuntu cd.

Author : catlett

Source : http://ubuntuforums.org/showthread.php?t=224351

—————————————————————-

This will restore grub if you already had grub installed but lost it to a windows install or some other occurence that erased/changed your MBR so that grub no longer appears at start up or it returns an error.

(This how to is written for Ubuntu but should work on other systems. The only thing to take note of, when you see “sudo” that will mean to you that the following command should be entered at a root terminal.)

Boot into the live Ubuntu cd. This can be the live installer cd or the older live session Ubuntu cds.

When you get to the desktop open a terminal and enter. (I am going to give you the commands and then I will explain them later)

Code:
sudo grub

This will get you a “grub>” prompt (i.e. the grub shell). At grub>. enter these commands

Code:
find /boot/grub/stage1

This will return a location. If you have more than one, select the installation that you want to provide the grub files.
Next, THIS IS IMPORTANT, whatever was returned for the find command use it in the next line (you are still at grub>. when you enter the next 3 commands)

Code:
root (hd?,?)

Again use the value from the find command i.e. if find returned (hd0,1) then you would enter root (hd0,1)

Next enter the command to install grub to the mbr

Code:
setup (hd0)

Finally exit the grub shell

Code:
quit

That is it. Grub will be installed to the mbr.
When you reboot, you will have the grub menu at startup.

Now the explanation.
Sudo grub gets you the grub shell.
Find /boot/grub/stage1 has grub locate the file stage1. What this does is tell us where grub’s files are. Only a small part of grub is located on the mbr, the rest of grub is in your boot folder. Grub needs those files to run the setup. So you find the files and then you tell grub where to locate the files it will need for setup.
So root (hd?,?) tells grub it’s files are on that partition.
Finally setup (hd0) tells grub to setup on hd0. When you give grub the parameter hd0 with no following value for a partition, grub will use the mbr. hd0 is the grub label for the first drive’s mbr.
Quit will exit you from the grub shell.

Gutsy Gibbon

วันนี้ได้โอกาสอันดี (วันศุกร์ที่วันรุ่งขึ้นไม่ต้องไปไหน) ว่างๆก็เลยนั่งโหลด Ubuntu 7.10 มาลงซะหน่อย

เรื่องของเรื่องคือไอ้ pc ที่บ้านเนี่ยมันมี ubuntu ลงอยู่อยู่แล้ว แต่เนื่องจากการลง windows ใหม่ในครั้งก่อน ทำให้ grub มันถูกทับไปด้วย boot manager ของ windows (ซึ่งมักจะมองไม่เห็นอะไรทั้งสิ้นนอกจากตัวเอง -*-) จึงบูทเข้าไม่ได้ตั้งแต่นั้นมา และด้วยความที่ไม่ค่อยได้ใช้ ก็เลยไม่สนใจที่จะลง grub ใหม่

แต่วันนี้ด้วยฤกษ์งามยามดี ที่สัปดาห์นี้จะสอบ unix แล้ว ไอ้ในห้องเรียนก็ไมได้ตั้งใจทำ ตั้งใจฟังเท่าไร จึงทำให้ถึงคราวต้องกู้ชีพ ubuntu ที่บ้านเพื่อใช้ทำ lab เก่าๆเตรียมสอบ

แต่ไหนๆก็ไหนๆละ อยากลอง 7.10 ซะหน่อย เห็นเค้าว่ามี คอมป๊ง คอมปิ๊ซ (compiz) ให้เล่น ตื่นตาตื่นใจดี ก็เลยตัดสินใจโหลดมาใหม่ แล้วลง 7.10 ไปโลด

distro ที่โหลดมาเป็นของ ubuntuclub คือตอนแรกก็กะว่าจะโหลด original distro. เพราะเหมือนจำได้ว่า ตอน 6.10 ก็โหลดของ original มามันก็ไม่มีปัญหากะภาษาไทยนี่.. (แต่มีข้อแม้ว่าต้องเลือก language ตอนลงเป็น thai ด้วยนะ)

แต่ก็นะ ด้วยความอยากรุ้ อยากลอง ก็เลยโหลดของ ubuntuclub มา..

ขั้นตอน install ค่อนข้างจะแตกต่างจาก 6.10 พอสมควร แต่เรียกได้ว่าพัฒนาไปในทางที่ดีขึ้น(เยอะ)เลย ส่วนที่เห็นแตกต่างชัดก็คือไอ้ส่วน partition manager ที่เหมือนจะทำได้ดีขึ้น นอกจากนี้ยังสามารถ detect user ใน windows partition ได้ และสามารถ import documents and setting มาใช้ใน ubuntu ได้ด้วย (อันนี้ไมได้ลองอ่ะ ว่ามันเวิร์คไหม – -) แต่ก็นั่นแหละ การลงครั้งแรกของผมต้องหยุดลงที่ step นี้ ทั้งๆที่ผมไม่ได้เลือกให้มัน import บ้าบออะไรมาเลย แต่ installer ก็ดันค้างนิ่งซะงั้น..

ก็เลยต้องมาเริ่มลง เริ่มแบ่ง partition กันใหม่ พอไปถึงไอ้หน้าเลือก import ข้อมูลก็ลุ้นระทึก มันค้างอีกไหมฟะ.. ปรากฎคราวนี้ผ่านอย่างไว ชึบชับมาก พอผ่านตรงนั้นมาได้ มันก็เริ่ม copy file ละ ก็ปล่อยให้มันลงๆไป แล้วขึ้นไปนอนกลิ้งข้างบน..

สักพักกลับมาดู เอ้อ เสร็จละนี่หว่า แต่ไอวินโทรมาลากดอทพอดี ก็เลยไปดอทก่อนละกัน เด๋วค่อยมาเล่น..

หลังจากดอทเสร็จ ก็ลงมาเล่นๆ สิ่งแรกที่(พยายาม) จะเล่นเลย คือไอ้ compiz นี่แหละ เห็นขึ้นชื่อลือชา…

ปรากฎ.. จนป่านนี้ผมยังเล่นมันไม่ได้เลยพี่นอ้ง !!

คือ ก่อนอื่นจะใช้งานมันได้เนี่ย ก็ต้องไป enable extra visual effect ใน system > preference > appearance ก่อน เสร็จแล้วก็ต้องไปปรับ (config) มันใน system > preference > advance desktop effect setting อีก

ทีนี้ การจะใช้งานมันได้เนี่ย การ์ดจอของเครือ่งจะต้องรอบรับ open gl(x) อีก ซึ่งถ้าไม่รองรับมันจะไม่ให้เปิดการทำงานของ extra visual effect และนั่นคือสาเหตุที่ผมยังไมได้เล่นมันเลย..

คือ.. ไม่รู้ว่าการ์ดจอมันไม่ support จริงๆ หรือว่าระบบมันบ๊องเอง ตัวไดรเวอร์คิดว่าไม่น่าใช่ปัญหา เพราะดูใน Hardware Manager มันก็เป็นของ nvidia นะ.. แต่ยังไม่ได้ลอง update เหมือนกัน.. (จริงๆการ์ดจอมันควรจะ support นี่หว่า. gf5600xt มันก็ไม่ได้เก่าเข้ารกเข้าพงอย่างนั้นนะ..)

งือ นั่นแหละ ก็เลยพักมันไว้ก่อน ยังไม่เล่นก็ได้(วะ)..

พอมาเล่นส่วนอื่นๆ.. ภาษาไทยต้องบอกว่าเนียนดี แต่ไม่ดีที่สุด อย่างที่เขียนอยู่ตอนนี้ ถ้า scroll ขึ้นลงไปมา จะเห็นการกระพริบของวรรณยุกต์ชัดเจนเหมือนกัน แต่เรื่องสระลอยนั้นไม่มีเลย.. แต่มีการที่ตัวอักษรในเวบมันห่างกันแปลกๆ (ใน csxix.com นี่แหละ) ทั้งๆที่สระก็ไม่ลอย.. แต่ทำไมมันดันอยู่ห่างกันเองก็ไม่รู้ อาจจะเกี่ยวข้องกับ css ด้วยละมั้ง เพราะว่าในที่อื่นๆ ก็แทบจะไม่มีปัญหาอะไรเลย

นอกนั้นก็มีข้อเสียเดิมๆ ที่เจอมา 3 version 2 distro แล้ว (mandriva , ubuntu 6.1 – 7.1) คือ ไม่เข้าใจว่าทำไมเวลากด space bar ลบข้อความใน browser มันจะ delayๆ ล่ะ..

คือ ไม่รู้เคยเจอกันไหม แบบว่า กด backspace ค้าง แล้ว cursor มันวิ่งช้ามากๆ แต่พอปล่อยแล้วมันดันวิ่งไม่หยุด !! ซะงั้น มันก็ลบเลยจุดที่ต้องการไปไกลเลยอะเซ่… อยากบอกว่าเป็นบ่อยมาก… มันไม่เนียนเหมอืน windows อะ..

(ตอนแรกคิดว่าเป็นที่ settings แต่ไปลองปรับๆดูใน system > pref > keyboard แล้วมันก็ไม่เห็นดีขึ้น แถมใช้งานใน terminal หรือใน textbox ของโปรแกรมอื่นๆก็ไม่เป็น ชึบชับปกติดี แต่ใน firefox เนี่ย เป็นอย่างแรง…

งือ.. ใครพอจะรู้ทางแก้ก็รบกวนบอกด้วยนะ (หรือมันจะเกี่ยวกะ wysiwyg editor ของเว็บกันแน่ ?)

นอกจากนี้เจอปัญหาอีกอย่างนึง ก็คือลง add-on ของ firefox โดยผ่านทางระบบของมันโดยตรงไม่ได้ (ใครที่เคยใช้ window แล้วกด install missing plugin แล้วได้ นั่นแหละ.. ทำไมผมทำไม่ได้ในนี้ก็ไม่รู้) ไม่รู้ว่ามันไม่ได้อยู่แล้วเพราะเป็น *nix รึเปล่า หรือว่าอะไรมันเพี้ยนไปอีก.. แต่ที่รู้ๆ ก็คือต้องไปโหลด tar.gz มาแตกลงเครื่อง แล้วค่อยสั่ง install ผ่าน bash เอง.. คือ มันไม่ชึบชับเอาซะเลย…

งืมๆ บ่นไปเยอะล่ะ ทีนี้มาพูดถึงเรื่องที่ประทับใจกะ 7.10 distro ubuntuclub นี้หน่อยดีกว่า

  • default theme สวยมาก ทำคล้ายๆ vista ต้องบอกว่าสวยกว่า theme เลียนแบบหลายๆ theme ใน xp
  • ภาษาไทยค่อนข้างสมบูรณ์
  • installer ทำได้ดี
  • driver detect ได้ครบทุกตัว (แจ่มมาก…)

ไม่ร้จะเขียนไรแล้ว ยังเล่นไปไม่มากเท่าไรด้วย…จบมันดื้อๆงี้หและ – -*