How do I use VIM effectively for editing English text? - vim

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.

Related

Vim key mapping with < and > symbols

I am trying to define a vim key map for putting the selected line inside an HTML p tag:
vnoremap <leader>bp c<p><cr></p><esc>P
It doesn't work, I think vim is interpreting <p> in a special way. How can I solve this?
It looks like you are using Vim in "compatible mode" which is something only hopelessly masochistic people do. In "nocompatible mode", your mapping works as expected so you should probably make sure nocompatible is set (creating a blank ~/.vimrc should be enough).
Anyway, your <p>s are not where the problem is because they are inserted normally, it's your <cr> and your <esc> that are causing a mess: since you are running Vim in "compatible mode", the cpoptions option includes < which causes Vim to not recognize <CR> and friends as special keys.
Running Vim in "nocompatible mode" is the best way to go but you can also use the following notation if you really insist on going "compatible":
vnoremap <leader>bp c<p>^M</p>^]P
where ^M is inserted with <C-v><CR> and ^] is inserted with <C-v><Esc>.
You may want to look into Tim Pope's Surround plugin. Then you can do S<p> and surround the visually selected text with <p> tags.
However the answer please see #romainl answer. I would also suggest you read up on key-notation via :h key-notation

Insert character without entering insert mode?

Sometimes I want to insert a # to comment out a line and test it quickly. Currently I do:
i#ESC:w
Is there something shorter I can do?
Although I agree with others that there are better ways to comment and uncomment code, it seems that people have gotten distracted and forgotten to actually answer the question.
This is my approach to inserting a single character:
:noremap <key> i <Esc>r
I tend to find that I need to replace, remove, or add single characters very often if I'm correcting typos, so (resp.) r, x, and whatever is chosen for <key> in the above become very handy.
Note that . is also particularly handy for this sort of task. It repeats the previous action.
Personally though, I only map this function to a valuable key when I'm doing a task where I use it frequently enough to justify occupying a prime spot on the keyboard (such as correcting typos), because really, it only saves one keystroke per use and that's only when <key> is not a combination, which of course limits availability.
I map a couple of things to my <leader> key (\ by default):
" # comment the current line
nnoremap <leader>d I#<ESC>
" block comment in visual mode
vnoremap <leader>c <ESC>'<O/*<ESC>'>o*/<ESC>V'<k
If you want to add a # to the start of a group of lines, then do this:
<ctl-v>
j (as many times as necessary
I#
<esc>
You could use a recording. From normal mode, type:
qlml0i#<press escape>`lq
Then to comment out a line, just press #l
Mapping in vim is so easy that I might do something like
:nmap CC I#<Esc>:w<CR>
on the fly. If I get used to it, then I will add it to my vimrc file.
:help key-mapping
:help usr_40.txt
Actually there is a plugin you might wanna take a look at:
http://www.vim.org/scripts/script.php?script_id=1218
It is specifically designed for that purpose.
I'm particularly fond of the tComment plugin. gcc to comment a line, repeat to uncomment, multiple lines, motions, etc.

How to make words invisible in vim?

In vimwiki, I can input a link like this:
[[link]]
When I put cursor on the line, [[]] is visible:
>[[http://www.google.com/]]<
When the cursor is moved away, [[]] is invisible:
>http://www.google.com/<
I notice this behavior in vim's help manual(:help vim): *vim:*(*s are invisible until I type V).
I cannot figure out how it works. Thanks for your help.
This is a feature called "conceal" that was added in vim 7.3 (if I recall correctly). For a simple example, try this.
Open a buffer and type three lines, the middle one being "foobarbaz". Then enter the following ex commands:
set conceallevel=2
syntax match Todo /bar/ conceal
When your cursor is on the "foobarbaz" line, "bar" will be visible (and highlighted with the Todo highlight group if you have syntax highlighting on). Once you move off the line, "bar" will disappear.
For more information see :help conceal and :help conceallevel.
I think that hiding text can be a very helpful feature. Think about text folding or readability of links.
To hide text Vim 7.3 has introduced the "conceal" argument. Hiding text is a well defined Vim feature. It is not a dirty trick.
See
:help :syn-conceal
:help 'conceallevel'
:help 'concealcursor'
Please note that conceal works only for syntax regions, not for matches.
I have no experience with conceal, so I can't provide an example out of the box.
Habi

Reading vim plugin - strange notation and navigation

Im reading great tpope rails.vim and what does it mean:
" }}}1
" Abbreviations {{{1
exactly here: https://github.com/tpope/vim-rails/blob/master/autoload/rails.vim#L3921
Is it for better navigation?
This file is quite huge, how to navigate on it properly - using ctags?
These are so called foldmarkers. Vim 6 introduced code folding and the triple braces are the default string to mark the beginning and the end of a fold. In addition, if you prepend the opening mark {{{ with text, it'll show in the collapsed line as a header. This is only one way to fold code. Being a manual method, it is easily controlled and thus preferred by many.
See :h folding and :h fold-marker.

Hidden features of Vim

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

Resources