Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
VimNotes
Edit
PageHistory
Diff
Info
LikePages
See also ViNotes vim(1) -- potentially the most powerful editor unix users have access to, and one of the best things about it is in actual fact it's not restricted to unix users at all. Anybody can use vim, anywhere (more or less). Its only real drawback is that it's a little difficult to get to grips with at first. This page is not designed to cover basic editing. Rather, this page is a list of tips which will make your vim editing experience more enjoyable, particularly if vim is used as a programming editor. !! Indentation [BenStaz] finds these settings very useful when using vim for coding (any language). <verbatim> set tabstop=8 " 4 places per tab character set shiftwidth=8 " indent/outdent by 4 places set expandtab " convert hardtabs to the equivalent number of blanks set softtabstop=8 " same value as 'tabstop' == no soft tabstops set autoindent " indent of new lines as appropriate </verbatim> !! Syntax Highlighting vim, of course, supports syntax highlighting. Often this isn't on by default. The easiest way to turn this on is to type <tt>:syntax on</tt>. Voila. What's that? You're using a dark background and the highlighting looks terrible? No real problem. Try <tt>:set background=dark</tt>. If you just think it looks horrible, full stop, get a new colourscheme... they’re available from vim.org and go into your <tt>~~/.vim/colors</tt> directory (which you may have to create). Select a different colour scheme using the <tt>:colorscheme</tt> command (see <tt>:help colorscheme</tt>; note that TabCompletion after the command works as you’d expect). If you run vim in the terminal your colour schemes are by default limited to 16 colours. Some terminals such as xterm can be compiled with 256 color support. To enable vim to use these add the following lines to your .vimrc: <verbatim> " Enable 256 colors set t_Co=256 set t_AB=^[[48;5;%dm set t_AF=^[[38;5;%dm </verbatim> Note that the ^[ should be a literal escape character. Most vim colourschemes will need to be customised a little to look decent in this mode although some (such as xterm16) are designed for it. You can automatically enable syntax highlighting when starting a new vim text. vim is smart and can automatically adjust the highlighting by looking at the extension of the file. For example, ''vim test.py'' will automatically have python syntax highlighting. If you are already in a document and wish to enable syntax highlighting, then use this command. *:set filetype=<language> eg: for python highlighting: *:set filetype=python or bash Highlighting: *:set filetype=sh What syntax highlighting language is currently being used? *:set filetype --KurtGaastra !!Compiling To build from within vim, simply use ":make". It's probably a good idea to set your current working directory to the same place as your makefile is located, which you can do with ":chdir <directory>". Vim will build your project, and hopefully jump intelligently to the right place whenever you encounter errors. If you need to set environment variables for your build, it's probably a good idea to set them on your :make line, eg ":make x=n" !!Buffer Movement Vim will support multiple buffers. You can switch between them using the menu in gvim, or if you prefer to use commands you can use the following: <pre> :bn # next buffer :bp # previous buffer </pre> You can delete a buffer with <pre> :bd </pre> or <pre> :bd n # where n is the number of a buffer :bd % # current buffer :bd # # previous buffer </pre> I map these to keys to make them useful. My [.vimrc] has the following: <pre> set autowrite nmap <tab> :bn<cr> nmap <s-tab> :bp<cr> nmap <c-f4> :bn<CR>:bd #<CR> </pre> Set autowrite tells vim to save the file when you change buffers. Vim wants to do this, its a bit annoying. The above maps will map tab and shift tab to next and previous buffer, and ctrl-f4 to delete current buffer. ctrl-f4 will delete the current buffer in a way that will preserve any splits you have open, ie it'll move to the next buffer, then delete the previous one. --DanielLawson !!Character Encoding/Unicode ''This section is partially wrong and needs some cleanup.'' —AristotlePagaltzis Vim has several options to do with character encoding, and each does slightly different things. <tt>encoding</tt>: Used by vim internally for strings held in buffers, registers, expressions, etc. <tt>termencoding</tt>: Tells vim what encoding to display to the terminal, and it will convert text from its internal encoding to this encoding if necessary for display. <tt>fileencoding</tt>: The encoding that files are assumed to be encoded with on disk. Vim will try to auto-detect this; see the following: <tt>fileencodings</tt>: A list of encodings that vim will try, in the order given, when autodetecting the encoding of a file on load. If it can't detect the encoding, it falls back to latin1 (aka iso-8859-1). If you want to be modern, and only use [UTF-8] everywhere, put the following in your <tt>.vimrc</tt> file: <verbatim> set encoding=utf-8 set termencoding=utf-8 set fileencoding=utf-8 </verbatim> If you might ever use vim to edit raw binary data, then it's a good idea to make sure that vim doesn't try any conversation on file load: <verbatim> " leave these as blank, so no conversation done? set fileencoding= set fileencodings= </verbatim> !! Miscellaneous Display invisible characters such as Tab and the end-of-line character : <tt>:set list</tt> Display man page inside vim for the word your cursor is currently over. <tt>Shift + k</tt> Display Function Prototype or variable type for the word your cursor is currently over. <tt>[ then i</tt> Move vim cursor to the matching closing symbol for the opening symbol your cursor is on. <tt>%</tt> Move vim cursor to a particular line. <tt><line_no>G</tt> Automatically create folds in a sensible way according to file type. set foldmethod=syntax !!! See also * [Good vim reference guide | http://www.dc.turkuamk.fi/docs/soft/vim/vim.html] ---- InNeedOfRefactor
3 pages link to
VimNotes
:
SampleConfigFiles
InNeedOfRefactor
UnicodeNotes