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

出至:http://stackoverflow.com/questions/11735560/dollar-sign-at-the-end-of-every-line

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

出至:http://stackoverflow.com/questions/5939142/replacing-m-with-enter

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>.

一般模式下取代一個字元,直接用「r<CR>」。<CR>是Enter鍵的意思!

或是在命令列模式中先按下「Ctrl+V」就會出現「^」字元,接著再按下「Enter」就能順利打出「^M」這個符號了。

關閉 vim 搜尋的反白 指令

來源:http://usagiblog.wordpress.com/2006/03/03/%E9%97%9C%E6%96%BC-vim-%E7%9A%84%E6%90%9C%E5%B0%8B%E5%8F%8D%E7%99%BD/

關於 vim 的搜尋反白

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

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

/aaaaaaaaaaaaaaaaaaaaaa

若想暫時關掉, 可打:

:set nohlsearch

或是打上:
:noh

若想把這功能永遠關閉的話, 在 ~/.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