ویم: تفاوت بین نسخه‌ها

از ویکی فارسی اوبونتو
پرش به: ناوبری، جستجو
(پیوند به بیرون)
سطر ۱۱۸: سطر ۱۱۸:
 
برای آموزش  کار با ویم از {{ic|vimtutor}} که به همراه ویم نصب شده است، استفاده کنید.
 
برای آموزش  کار با ویم از {{ic|vimtutor}} که به همراه ویم نصب شده است، استفاده کنید.
 
{{bc|$ vimtutor}}
 
{{bc|$ vimtutor}}
 +
 +
 +
== تنظیمات ویم ==
 +
تنظیمات ویم در فایل vimrc. در خانه ذخیره میشود
 +
می‌تواند با دستور زیر به ویم ان فایل را ایجاد یا باز کنید و تنظیمات خود را در ان بنویسید
 +
{{bc|$ vim .vimrc}}
 +
 +
می‌توانید با استفاده از تنظیمات زیر ویم خود را کامل تر کنید
 +
 +
<pre>
 +
:set number " Display line numbers on the left side
 +
:set ls=2 " This makes Vim show a status line even when only one window is shown
 +
:filetype plugin on " This line enables loading the plugin files for specific file types
 +
:set tabstop=4 " Set tabstop to tell vim how many columns a tab counts for. Linux kernel code expects each tab to be eight columns wide.
 +
:set expandtab " When expandtab is set, hitting Tab in insert mode will produce the appropriate number of spaces.
 +
:set softtabstop=4 " Set softtabstop to control how many columns vim uses when you hit Tab in insert mode. If softtabstop is less than tabstop and expandtab is not set, vim will use a combination of tabs and spaces to make up the desired spacing. If softtabstop equals tabstop and expandtab is not set, vim will always use tabs. When expandtab is set, vim will always use the appropriate number of spaces.
 +
:set shiftwidth=4 " Set shiftwidth to control how many columns text is indented with the reindent operations (<< and >>) and automatic C-style indentation.
 +
:setlocal foldmethod=indent " Set folding method
 +
:set t_Co=256 " makes Vim use 256 colors
 +
:set nowrap " Don't Wrap lines!
 +
:set nocp " This changes the values of a LOT of options, enabling features which are not Vi compatible but really really nice
 +
:set clipboard=unnamed
 +
:set clipboard=unnamedplus
 +
:set autoindent " Automatic indentation
 +
:set cindent " This turns on C style indentation
 +
:set si " Smart indent
 +
:syntax enable " syntax highlighting
 +
:set showmatch " Show matching brackets
 +
:set hlsearch " Highlight in search
 +
"":set ignorecase " Ignore case in search
 +
:set noswapfile " Avoid swap files
 +
:set mouse=a " Mouse Integration
 +
:set cursorline " Highlight current line
 +
:set termbidi
 +
" auto complete for ( , " , ' , [ , {
 +
:inoremap        (  ()<Left>
 +
:inoremap        "  ""<Left>
 +
:inoremap        `  ``<Left>
 +
:inoremap        '  ''<Left>
 +
:inoremap        [  []<Left>
 +
:inoremap      {  {}<Left>
 +
 +
" auto comment and uncooment with F6 and F7 key
 +
:autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
 +
:autocmd FileType sh,ruby,python  let b:comment_leader = '# '
 +
:autocmd FileType vim  let b:comment_leader = '" '
 +
 +
:noremap <silent> #6 :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR> " commenting line with F6
 +
:noremap <silent> #7 :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR> " uncommenting line with F7
 +
:map <F5> :!python3 ./% <CR>
 +
 +
:noremap <silent> #3 :tabprevious<CR> " switch to previous tab with F3
 +
:noremap <silent> #4 :tabnext<CR> " switch to next tab with F2
 +
:map <F8> :setlocal spell! spelllang=en_us<CR> " check spelling with F8
 +
:set pastetoggle=<F2> " Paste mode toggle with F2 Pastemode disable auto-indent and bracket auto-compelation and it helps you to paste code fro elsewhere .
 +
 +
 +
"rr
 +
" noremap <F5> :! AsyncRun -raw python % <CR>
 +
 +
</pre>
 +
  
 
== پیوند به بیرون ==
 
== پیوند به بیرون ==

نسخهٔ ‏۲۲ تیر ۱۴۰۰، ساعت ۱۵:۳۷

نشان ویرایشگر متن ویم

ویم (به انگلیسی Vim مخفّف Vi IMproved به معنای وی بهبود یافته)، یک ویرایشگر متن سبک، قدرتمند، آزاد و سازگار با وی است.

ویم به دلیل وجود میان‌برهای بسیار، سرعت بالایی به کاربر می‌دهد.


ویژگی‌ها

  • سبک
  • سریع
  • در دسترس (روی بیشتر توزیع ها به صورت پیش‌فرض نصب است)

نصب

برای نصب این نرم افزار، از فرمان زیر استفاده کنید:

$ sudo apt install vim

برای نصب محیط گرافیکی ویم، بدین صورت عمل کنید:

$ sudo apt install gvim

کاربرد

برای گشودن پروندهٔ مورد نظر با استفاده از ویم، از این فرمان استفاده کنید:

$ vim FILE

ویم دارای سه حالت دستور، درج و بصری است. در هرکجا برای وارد شدن به حالت دستور، کافی است دکمهٔ فرار را بزنید.

می‌توانید از فرمان‌های زیر در حالت دستور استفاده کنید.:

حرکت مکان‌نما

 h = رفتن به چپ
 j = رفتن به پایین
 k = رفتن به بالا
 l = رفتن به راست
 
 w = رفتن به واژهٔ پسین (word)
 b = رفتن به واژهٔ پیشین (back)
 e = رفتن به انتهای واژه (end)
 W = رفتن به واژهٔ کامل پسین (Word)
 B = رفتن به واژهٔ کامل پیشین (Back)
 E = رفتن به انتهای واژهٔ کامل (End)
 
 0 = رفتن به ابتدای خط
 ^ = رفتن به نخستین نویسهٔ خط
 $ = رفتن به انتهای خط
 G = رفتن به آخرین خط پرونده (Go)
 20G = رفتن به خط شمارهٔ ۲۰
 '' = بازگشت به آخرین مکان پیش از زدن دستور پیشین

برش و جای‌گذاری

 y = فرستادن متن انتخابی به حافظه (yank)
 yw = فرستادن واژهٔ جاری به حافظه (yank word)
 y3w = فرستادن ۳ واژه از واژهٔ جاری به حافظه (yank 3 words)
 y10w = فرستادن ۱۰ واژه از واژهٔ جاری به حافظه (yank 10 words)
 yW = فرستادن واژهٔ کامل جاری به حافظه (yank Word)
 y3W = فرستادن ۳ واژهٔ کامل از واژهٔ کامل جاری به حافظه (yank 3 Words)
 yy = فرستادن خط جاری به حافظه
 y3y = فرستادن ۳ خط از خط جاری مکان‌نما به حافظه
 
 x = حذف نویسهٔ زیر مکان‌نما و فرستادن به حافظه
 dw = حذف یک واژه و فرستادن به حافظه (delete word)
 d3w = حذف ۳ واژه و فرستادن به حافظه (delete 3 words)
 d10w = حذف ۱۰ واژه و فرستادن به حافظه (delete 10 words)
 dW = حذف یک واژهٔ کامل و فرستادن به حافظه (delete Word)
 d3W = حذف ۳ واژهٔ کامل و فرستادن به حافظه (delete 3 Words)
 dd = حذف یک خط و فرستادن به حافظه
 d3d = حذف ۳ خط و فرستادن به حافظه
 
 d0 = حذف تا ابتدای خط و فرستادن به حافظه
 d^ = حذف تا نخستین نویسهٔ خط و فرستادن به حافظه
 d$ = حذف تا انتخای خط و فرستادن به حافظه
 dG = حذف تا آخرین خط پرونده و فرستادن به حافظه
 d20G = حدف تا خط شمارهٔ ۲۰ و فرستادن به حافظه
 
 p = جای‌گذاری از حافظه پس از مکان‌نما
 P = جای‌گذاری از حافظه پیش از مکان‌نما

رفتن به حالت‌های دیگر

 i = ورود به حالت درج پیش از مکان‌نما (insert)
 I =  ورود به حالت درج در ابتدای خط فعلی
 a = ورود به حالت درج پس از مکان‌نما
 A = ورود به حالت درج در انتهای خط فعلی
 o = ایجاد یک خط در پایین خط جاری و ورود به حالت درج در ابتدای خط جدید (open)
 O = ایجاد یک خط در بالای خط جاری و ورود به حالت درج در ابتدای خط جدید (open)
 v = ورود به حالت بصری (visual)
 V = ورود به حالت بصری خطّی
 ^v = ورود به حالت بصری بلوکی

جست‌وجو

 * = جست‌وجو برای واژهٔ زیر مکان نما
 / = جست‌وجوی سریع متن دلخواه در پرونده
 n = رفتن به یافتهٔ پسین (next)
 N = رفتن به یافتهٔ پیشین
 :s/old/new/g = جایگزینی واژه در خط جاری
 :%s/old/new/g = جایگزینی واژه در تمام پرونده
 :%s/old/new/gc =  جایگزینی واژه در تمام پرونده، با تأیید

ویرایش

 u = برگردان (undo)
 ^r = از نو (redo)
 r = جایگزینی تک‌نویسهٔ زیر مکان‌نما (replace)
 J = آوردن خطّ زیرین به انتهای خطّ جاری (Join)
 cw = تعویض واژهٔ جاری (change word)
 c3w = تعویض ۳ واژه از واژهٔ جاری (change 3 words)
 cW = تعویض واژهٔ جاری (change Word)
 cc = تعویض خط جاری
 c0 = تعویض تا ابتدای خط جاری
 c20G = تعویض تا خط شمارهٔ ۲۰
 . = تکرار دستور پیشین

ذخیره و خروج

:w = نوشن در پرونده (write)
:wq = ذخیره و خروج (write quit)
:q! = خروج بدون ذخیره (quit)
:e! = بارگذاری مجدد صفحه

پشتیبانی فارسی

برای پشتیبانی از زبان‌های دوجهته در ویم، از دستور زیر استفاده کنید:

:set termbidi

آموزش

برای آموزش کار با ویم از vimtutor که به همراه ویم نصب شده است، استفاده کنید.

$ vimtutor


تنظیمات ویم

تنظیمات ویم در فایل vimrc. در خانه ذخیره میشود می‌تواند با دستور زیر به ویم ان فایل را ایجاد یا باز کنید و تنظیمات خود را در ان بنویسید

$ vim .vimrc

می‌توانید با استفاده از تنظیمات زیر ویم خود را کامل تر کنید

:set number " Display line numbers on the left side
:set ls=2 " This makes Vim show a status line even when only one window is shown
:filetype plugin on " This line enables loading the plugin files for specific file types
:set tabstop=4 " Set tabstop to tell vim how many columns a tab counts for. Linux kernel code expects each tab to be eight columns wide.
:set expandtab " When expandtab is set, hitting Tab in insert mode will produce the appropriate number of spaces.
:set softtabstop=4 " Set softtabstop to control how many columns vim uses when you hit Tab in insert mode. If softtabstop is less than tabstop and expandtab is not set, vim will use a combination of tabs and spaces to make up the desired spacing. If softtabstop equals tabstop and expandtab is not set, vim will always use tabs. When expandtab is set, vim will always use the appropriate number of spaces.
:set shiftwidth=4 " Set shiftwidth to control how many columns text is indented with the reindent operations (<< and >>) and automatic C-style indentation. 
:setlocal foldmethod=indent " Set folding method
:set t_Co=256 " makes Vim use 256 colors
:set nowrap " Don't Wrap lines!
:set nocp " This changes the values of a LOT of options, enabling features which are not Vi compatible but really really nice
:set clipboard=unnamed
:set clipboard=unnamedplus
:set autoindent " Automatic indentation
:set cindent " This turns on C style indentation
:set si " Smart indent
:syntax enable " syntax highlighting
:set showmatch " Show matching brackets
:set hlsearch " Highlight in search
"":set ignorecase " Ignore case in search
:set noswapfile " Avoid swap files
:set mouse=a " Mouse Integration
:set cursorline " Highlight current line
:set termbidi
" auto complete for ( , " , ' , [ , { 
:inoremap        (  ()<Left>
:inoremap        "  ""<Left>
:inoremap        `  ``<Left>
:inoremap        '  ''<Left>
:inoremap        [  []<Left>
:inoremap      {  {}<Left>

" auto comment and uncooment with F6 and F7 key
:autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
:autocmd FileType sh,ruby,python   let b:comment_leader = '# '
:autocmd FileType vim   let b:comment_leader = '" '

:noremap <silent> #6 :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR> " commenting line with F6
:noremap <silent> #7 :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR> " uncommenting line with F7
:map <F5> :!python3 ./% <CR>

:noremap <silent> #3 :tabprevious<CR> " switch to previous tab with F3
:noremap <silent> #4 :tabnext<CR> " switch to next tab with F2
:map <F8> :setlocal spell! spelllang=en_us<CR> " check spelling with F8
:set pastetoggle=<F2> " Paste mode toggle with F2 Pastemode disable auto-indent and bracket auto-compelation and it helps you to paste code fro elsewhere .


"rr
" noremap <F5> :! AsyncRun -raw python % <CR> 


پیوند به بیرون

خلاصه دستور های ویم

ویدیو های آموزش فارسی ویم

ادیتور ویم برای برنامه نویسی

تولید vimrc