Emacs has ispell-word, ispell-region commands, which spellcheck current word, current selected region. Do we have such equivalent in vim?
I find this is useful to spell check a particular block of code comments.
Spelling in Vim is syntax-based. That is, for various programming languages it is enabled exactly for all comments. Simply toggle :h 'spell' option for the current buffer and, assuming syntax is on, it just works.
See also :h :syn-spell and :h spell.txt
Related
The default behavior in Vim is to syntax highlight special characters such as Numbers, booleans, etc. However when working with comments I find this to be a major distraction since Vim is highlighting them by default. I'd like to keep any syntax coloring in a comment to be the same all across the board. (in my case, light gray)
What is the colorscheme or vimrc setting to maintain a a consistent comment color?
Also unlet c_comment_strings does not resolve the issue.
This is not about particular color scheme. This is about syntax matching rule that allows to find strings/numbers even inside comments. So it depends upon a language.
For C/C++ it is governed by existence of c_comment_strings variable (see also :h c.vim). And it is not a true default. That variable either intentionally defined in your vimrc or it comes from standard defaults.vim. In latter case you need to unlet it.
For other languages refer to Vim docs on a particular syntax.
How to make Vim autocomplete a word based on words already in the buffer?
How can I make Vim autocomplete words, based on words already found in the buffer, just like it is possible with Emacs (M-%)?
<C-n> and <C-p> will complete what is in all buffers. <C-x><C-n> and <C-x><C-p> will do exactly what you asked for and only give completion for tokens in the current buffer. However, there are a lot of completion options in Vim. To learn more about them, I would suggest reading the help section on them :help ins-completion (this is called insert mode completion).
A few other completion options in Vim are <C-x><C-f> to complete file paths and <C-x><C-l> to complete entire lines.
C-x C-n and C-x C-p do that in insert mode (next and previous)
Another solution is to use a plugin with an auto popup : neocomplcache plugin
It provides keyword completion system by maintaining a cache of keywords in the current buffer. neocomplcache could be customized easily and has a lot more features than the Vim's standard completion feature.
In Zsh, I can use filename completion with slashes to target a file deep in my source tree. For instance if I type:
vim s/w/t/u/f >TAB<
zsh replaces the pattern with:
vim src/wp-contents/themes/us/functions.php
What I'd like is to be able to target files the same way at the Vim command line, so that typing
:vi s/w/t/u/f >TAB<
will autocomplete to:
:vi src/wp-contents/themes/us/functions.php
I'm trying to parse the Vim docs for wildmode, but I don't see what settings would give me this. It's doing autocompletion for individual filenames, but not file paths. Does Vim support this natively? Or how can I customize the autocomplete algorithm for files?
Thanks for any advice!
-mykle-
I couldn't find a plugin to do this, so I wrote one. It's called vim-zsh-path-completion. It does what you're looking for, although via <C-s> rather than <Tab>. You can use it with <Tab> for even more control over what matches, though.
It's got bugs, but for basic paths without spaces/special characters, it should work. I think it's useful enough in its current state to be helpful. I hope to iron out the bugs and clean up the code, but I figured I'd start soliciting feedback now.
Thanks for the idea!
Original (wrong) answer, but with some useful information about Vim's wildmode.
Put the following in your .vimrc:
set wildmenu
set wildmode=list:longest
That will complete to the longest unique match on <Tab>, including appending a / and descending into directories where appropriate. If there are multiple matches, it will show a list of matches for what you've entered so far. Then you can type more characters and <Tab> again to complete.
I prefer the following setting, which completes to the first unique match on <Tab>, and then pops up a menu if you hit <Tab> again, which you can navigate with the arrow keys and hit enter to select from:
set wildmode=list:longest,list:full
Check out :help wildmenu and :help wildmode. You might also want to set wildignore to a list of patterns to ignore when completing. I have mine as:
set wildignore=.git,*.swp,*/tmp/*
Vim doesn't have such a feature by default. The closest buil-in feature is the wildmenu/wildmode combo but it's still very different.
A quick look at the script section of vim.org didn't return anything but I didn't look too far: you should dig further. Maybe it's there, somewhere.
Did you try Command-T, LustyExplorer, FuzzyFinder, CtrlP or one of the many similar plugins?
I use CtrlP and fuzzy matching can be done on filepath or filename. When done on filepath, I can use the keysequence below to open src/wp-contents/themes/us/functions.php (assuming functions.php is the only file under us that starts with a f):
,f " my custom mapping for the :CtrlP command
swtuf<CR>
edit
In thinking about a possible solution I'm afraid I was a little myopic. I was focused on your exact requirements but Vim has cool tricks when it comes to opening files!
The :e[dit] command accepts two types of wildcards: * is like the * you would use in your shell and ** means "any subdirectory".
So it's entirely possible to do:
:e s*/w*/t*/u*/f*<Tab>
or something like:
:e **/us/f<Tab>
or even:
:e **/fun<Tab>
Combined with the wildmode settings in Jim's answer, I think you have got a pretty powerful file navigation tool, here.
As a programmer by heart, if not by profession, I increasingly rely on, nay live in VIM for most editing-related tasks. What tips can you offer for using (almost) everyone's favorite editor for editing general-purpose text, say, an article? I mean plain text, with minimal markup using Markdown or RST; I'm not looking for support for LaTeX or for entering mathematical formulae.
I enable soft-wrapping when I'm editing most text files:
:set wrap
If you decide to do the same, then you'll want to know about gj and gk in normal mode, to move by screen lines instead of physical lines. I use them so often I remapped the up and down arrow keys to them instead of k and j.
Whether you're editing hard- or soft-wrapped files, you'll get a lot of mileage out of gqap (or its cousin gwap) to re-wrap a single paragraph with hard newlines, and vipJ to join all the lines of a hard-wrapped paragraph back into a single line.
You might also want to consider including a in formatoptions, to enable automatic paragraph formatting:
:set formatoptions+=a
When you're doing all this wrapping and unwrapping, it's nice to keep Vim from mangling numbered lists:
:set formatoptions+=n
In fact, I'd suggest reviewing all the formatoptions and adjusting them to your particular preferences:
:help fo-table
More info:
:help gj
:help gk
:help gqap
:help auto-format
:help formatoptions
Spell checking:
:setlocal spell spelllang=en_us
" ]s moves to the next mispelled word
" [s moves to the previous mispelled word
Set a thesuarus for Vim
Use par to format text
It's not very well maintained, but the Vim-Outliner project makes Vim into a killer outliner for plain text writing. You can download v0.34 here (there's a more recent version, I think, but I'm not sure where to get it):
http://www.vimoutliner.org/postnuke-phoenix-0.7.2.3/html/modules.php?op=modload&name=Downloads&file=index&req=viewdownload&cid=4
I really enjoyed this blogpost about writing better with latex. You could use vim-latex :) It's more about writing better, than just editing english text though.
http://matt.might.net/articles/shell-scripts-for-passive-voice-weasel-words-duplicates/
Use insert abbreviations:
iabbr teh the
iabbr i I
iabbr definately definitely
Edit, another tip:
set wrap nolist linebreak
This tells vim to wrap lines that are too long with "visual" newlines rather than adding an actual newline character to the file. The 'list' option must be off because it automatically disables the 'linebreak' option.
Over the years, I thought I'm a Vim master! Recently I visited a real Vim master! oops! My knowledge is awfully superficial!
For example I didn't know it's possible to add a \c to make search case insensitive. (instead of :set ignorecase)
I clearly remember when how I'm surprised when I found SuperTab or TagList plugins first time. Vim's official site says "Vim isn't an editor designed to hold its users' hands. It is a tool, the use of which must be learned.", so naturally it should have many undiscovered features.
So I'm asking, what are your favorite features of Vim? What are things you can do with it that you can't or are more difficult in the other editors?
Of course there's some same topics about other editors:
Hidden Features of Eclipse
Hidden Features of TextPad
About the "hidden" part... Try these:
:help 42
:help!
:o)
It took me a few years before I learned about text objects
:help text-object
:nmap cw ciw
:nmap cW ciW
Also nice are ci" and ci (when I want to change a string or function args).
This is not exactly a hidden feature but it's a little known feature.
If you type :X then you can encrypt your file with a password.
You can check the correctness of the text using line:
:set spell