vim 編輯文件時,每行後面總有個錢字符號「$」


Dollar sign at the end of every line

I am relatively new to Vim and am planning to code and learn Ruby on it. But whenever I start the Vim (e.g. vim LearnRuby.rb), a dollar sign appears at every line. I am wondering what’s it all about.

:set nolist

will turn off special characters for the current buffer, such as tabs being presented as ^I and end of line characters showing up as $.

However, if it’s doing that consistently when you run vim, you need to look into your .vimrc (or other startup file where applicable) and find out what’s doing the set list that causes it.

在 vim 執行「:set list!」命令,切換顯示或隱藏這一些特殊字元。

vim 中如何取代特殊字元^M


Replacing ^M with Enter

I know how to remove ^M in my files (%s/^M//g), but this one is just one line I’d like to replace ^M with enter… what’s the enter character in VIM (to use in commnad-line mode).

You can replace one character using r<CR> in normal mode.
Or you can enter a “return" in command line mode by typing <C-v><CR>.



關閉 vim 搜尋的反白 指令


關於 vim 的搜尋反白

各家 distrobution 或者各個工作站的 global settings 裡的 vimrc 可能都有各自的設定, 若您遇到的環境剛好預設把「搜尋反白」打開(set hlsearch), 說不定您會想把它關掉.

如果是搜尋動作完, 想把反白弄掉而已, 可以用「讓 vim 搜尋一段檔案裡不可能出現的字串」的方式, 我的習慣是打:


若想暫時關掉, 可打:

:set nohlsearch


若想把這功能永遠關閉的話, 在 ~/.vimrc 裡寫入 set nohlsearch 就可以了.


編輯~/.profile」 內容,加上 EDITOR 變數。使用「vim」作為預設編輯器。

#export EDITOR=vim


# . ~/.profile

測試 在 ubuntu 上預設使用 nano 作為 visudo 的編輯器,看看是否變成用「vim」了。

# sudo -E visudo


# export EDITOR=vim
# sudo -E visudoexport EDITOR=vim &amp;&amp; sudo -E visudo

Tab key == 4 spaces and auto-indent after curly braces in VIM

How do I make Vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like emacs does?

Also, how do I save these settings so I never have to input them again.

I’ve seen other questions related to this but it always seems to be a little off from what I want.

The Best Anser:

in your .vimrc:

set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

The help files take a bit of time to get used to but the more you read the better vim gets:

:help smartindent

Even better, you can embed these settings in your source for portability:

:help auto-setting

To see your current settings:

:set all

As graywh points out in the comments, smartindent has been replaced by cindent which “Works more cleverly", although still mainly for languages with C-like syntax:

:help C-indenting