remove vim files as they shall be synced via chezmoi
This commit is contained in:
3
vim/.gitignore
vendored
3
vim/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
.vim/spell/*.add
|
||||
.vim/spell/*.spl
|
||||
.vim/_email-addresses.vim
|
||||
@@ -1,5 +0,0 @@
|
||||
" Text width, comment format, indenting, formatoptions
|
||||
set tw=72 " text width for line-break
|
||||
set comments=s1:/mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-,fb:*
|
||||
set ai! " auto indent
|
||||
set fo+=tcqn " format options
|
||||
@@ -1,6 +0,0 @@
|
||||
" hide gvim elements
|
||||
set guioptions-=m "remove menu bar
|
||||
set guioptions-=T "remove toolbar
|
||||
|
||||
" font
|
||||
set guifont=Noto\ Mono\ 10
|
||||
@@ -1,11 +0,0 @@
|
||||
" delete lines until end
|
||||
nmap <C-d> dG1o
|
||||
map! <C-d> <ESC>dG1o
|
||||
|
||||
" delete current line
|
||||
nmap <C-s> ddi
|
||||
map! <C-s> <ESC>ddi
|
||||
|
||||
" add empty line
|
||||
nmap <C-a> 1o
|
||||
map! <C-a> <ESC>1o
|
||||
@@ -1,22 +0,0 @@
|
||||
setlocal spell spelllang=en_gb " default: EN spellcheck
|
||||
|
||||
" Disable spell check
|
||||
nmap <F2> :setlocal spell!<CR>
|
||||
map! <F2> <ESC>:setlocal spell!<CR>li
|
||||
|
||||
" EN spell check
|
||||
nmap <F3> :setlocal spell spelllang=en_gb<CR>
|
||||
map! <F3> <ESC>:setlocal spell spelllang=en_gb<CR>li
|
||||
|
||||
" DE spell check
|
||||
nmap <F4> :setlocal spell spelllang=de_20<CR>
|
||||
map! <F4> <ESC>:setlocal spell spelllang=de_20<CR>li
|
||||
|
||||
" highlight CApital LEtter TYpos
|
||||
:match Title /\<\u\{2}\l.\{-}\>/
|
||||
|
||||
" highlight words for better writing ( http://mashable.com/2015/05/03/words-eliminate-vocabulary/ )
|
||||
match Todo /\<that\>\c\|\<went\>\c\|\<honestly\>\c\|\<absolutely\>\c\|\<very\>\c\|\<really\>\c\|\<amazing\>\c\|\<always\>\c\|\<never\>\c\|\<literally\>\c\|\<just\>\c\|\<maybe\>\c\|\<stuff\>\c\|\<thing\>\c\|\<irregardless\>\c/
|
||||
|
||||
" LanguageTool plugin
|
||||
let g:languagetool_jar='/home/max/bin/languagetool/languagetool-commandline.jar'
|
||||
@@ -1,18 +0,0 @@
|
||||
" Some auto replacements for end of mails
|
||||
iab _v Viele Grüße<C-M>Max
|
||||
iab _vm Viele Grüße<C-M>Max Mehl
|
||||
iab _bg Beste Grüße<C-M>Max
|
||||
iab _bgm Beste Grüße<C-M>Max Mehl
|
||||
iab _mfg Mit freundlichen Grüßen<C-M>Max Mehl
|
||||
iab _b Best,<C-M>Max
|
||||
iab _br Best regards,<C-M>Max
|
||||
iab _brm Best regards,<C-M>Max Mehl
|
||||
iab _s Sincerely,<C-M>Max Mehl
|
||||
|
||||
" Shortcuts for long words
|
||||
iab _fsfe Free Software Foundation Europe
|
||||
|
||||
" Auto-replace dumb typos
|
||||
iab teh the
|
||||
iab Teh The
|
||||
iab MAx Max
|
||||
@@ -1,3 +0,0 @@
|
||||
source ~/.vim/_formatting.vim
|
||||
source ~/.vim/_line-shortcuts.vim
|
||||
source ~/.vim/_word-shortcuts.vim
|
||||
@@ -1,101 +0,0 @@
|
||||
" Include all in mail
|
||||
source ~/.vim/mail.vim
|
||||
|
||||
" Error message handling
|
||||
set shortmess=s " less messages
|
||||
set cmdheight=2
|
||||
|
||||
" Jump to To:, Cc:, Subject:
|
||||
nmap <M-t> 2GA
|
||||
map! <M-t> <ESC>2GA
|
||||
nmap <M-c> 3GA
|
||||
map! <M-c> <ESC>3GA
|
||||
nmap <M-s> 4GA
|
||||
map! <M-s> <ESC>4GA
|
||||
|
||||
" Go to first empty line and start insert mode
|
||||
execute "normal /^$/\n"
|
||||
execute ":startinsert"
|
||||
|
||||
" add two empty lines after header (where we jumped to)
|
||||
execute "call append(line('.')-1, '')"
|
||||
execute "call append(line('.')-1, '')"
|
||||
|
||||
" Email auto completion for headers
|
||||
let g:qcc_query_command='khard email --parsable --remove-first-line --search-in-source-files'
|
||||
setlocal omnifunc=QueryCommandComplete
|
||||
|
||||
" Functions
|
||||
|
||||
" Set tw to 5000 if in the first 4 lines, else 72
|
||||
au CursorMovedI * call ModifyTextWidth() " execute when cursor has moved, use for all files
|
||||
function! ModifyTextWidth()
|
||||
let line=getline('.') " get the current line number of the cursor
|
||||
if line('.') < 5 " if line number smaller than 5
|
||||
setlocal textwidth=5000 " use high tw setting
|
||||
else
|
||||
setlocal textwidth=72 " Otherwise use normal textwidth
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! Mail_Erase_Sig()
|
||||
" search for the signature pattern (takes into account signature delimiters
|
||||
" from broken mailers that forget the space after the two dashes)
|
||||
let i = 0
|
||||
while ((i <= line('$')) && (getline(i) !~ '^> *-- \=$'))
|
||||
let i = i + 1
|
||||
endwhile
|
||||
|
||||
" if found, then
|
||||
if (i != line('$') + 1)
|
||||
" first, look for our own signature, to avoid deleting it
|
||||
let j = i
|
||||
while (j < line('$') && (getline(j + 1) !~ '^-- $'))
|
||||
let j = j + 1
|
||||
endwhile
|
||||
|
||||
" second, search for the last non empty (non sig) line
|
||||
while ((i > 0) && (getline(i - 1) =~ '^\(>\s*\)*$'))
|
||||
let i = i - 1
|
||||
endwhile
|
||||
|
||||
" third, delete those lines plus the signature
|
||||
exe ':'.i.','.j.'d'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! Mail_Erase_Own_Sig()
|
||||
let i = 0
|
||||
while ((i <= line('$')) && (getline(i) !~ '^-- \=$'))
|
||||
let i = i + 1
|
||||
endwhile
|
||||
|
||||
" if found, then
|
||||
if (i != line('$') + 1)
|
||||
" first, look for our own signature, to avoid deleting it
|
||||
let j = i
|
||||
while (j < line('$') && (getline(j + 1) !~ '^-- $'))
|
||||
let j = j + 1
|
||||
endwhile
|
||||
|
||||
" second, search for the last non empty (non sig) line
|
||||
while ((i > 0) && (getline(i - 1) =~ '^\(>\s*\)*$'))
|
||||
let i = i - 1
|
||||
endwhile
|
||||
|
||||
" third, delete those lines plus the signature
|
||||
exe ':'.i.','.j.'d'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! Mail_Beginning()
|
||||
exe "normal gg"
|
||||
if getline (line ('.')) =~ '^From: '
|
||||
" if we use edit_headers in Mutt, then go after the headers
|
||||
exe "normal /^$\<CR>"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
call Mail_Erase_Own_Sig()
|
||||
call Mail_Erase_Sig()
|
||||
call Mail_Beginning()
|
||||
@@ -1,310 +0,0 @@
|
||||
*LanguageTool.txt* A grammar checker in Vim for English, French, German, etc.
|
||||
*LanguageTool*
|
||||
|
||||
Author: Dominique Pellé <dominique.pelle@gmail.com>
|
||||
Last Change: 06 Oct 2016
|
||||
|
||||
For Vim version 7.0 and above
|
||||
|
||||
============================================================================
|
||||
|
||||
1. Overview |languagetool-overview|
|
||||
2. Screenshots & Demo |languagetool-screenshots|
|
||||
3. Download |languagetool-download|
|
||||
4. Installation |languagetool-installation|
|
||||
5. Configuration |languagetool-configuration|
|
||||
6. Features |languagetool-features|
|
||||
7. Bugs |languagetool-bugs|
|
||||
8. License |languagetool-license|
|
||||
|
||||
============================================================================
|
||||
|
||||
1. Overview *languagetool-overview*
|
||||
|
||||
This plugin integrates LanguageTool into Vim. LanguageTool is an Open Source
|
||||
style and grammar checker for English, French, German, etc. See
|
||||
http://www.languagetool.org/languages/ for a complete list of supported
|
||||
languages.
|
||||
|
||||
LanguageTool detects grammar mistakes that a spelling checker cannot detect
|
||||
such as "it work" instead of "it works". Since version 1.8, LanguageTool
|
||||
can also detect spelling mistakes using Hunspell dictionaries bundled with
|
||||
LanguageTool for several languages or using morfologik for other languages.
|
||||
Vim builtin spelling checker can also of course be used along with
|
||||
LanguageTool. One advantage of the spelling checker of LanguageTool over
|
||||
Vim spelling checker, is that it uses the native Hunspell dictionary directly,
|
||||
so it works even with the latest Hunspell dictionaries containing features
|
||||
not supported by Vim. For example, the latest French Hunspell dictionaries
|
||||
from http://www.dicollect.org are not supported by Vim but they work well
|
||||
with LanguageTool. On the other hand, the Vim native spelling checker is
|
||||
faster and better integrated with Vim.
|
||||
|
||||
See http://www.languagetool.org/ for more information about LanguageTool.
|
||||
|
||||
============================================================================
|
||||
|
||||
2. Screenshots *languagetool-screenshots*
|
||||
|
||||
If you don't have time to read help files, these screenshots will give you
|
||||
an idea of what the LanguageTool plugin does:
|
||||
|
||||
http://dominique.pelle.free.fr/pic/LanguageToolVimPlugin_en.png
|
||||
http://dominique.pelle.free.fr/pic/LanguageToolVimPlugin_fr.png
|
||||
|
||||
============================================================================
|
||||
|
||||
3. Download *languagetool-download*
|
||||
|
||||
You can download the latest version of this plugin from:
|
||||
|
||||
http://www.vim.org/scripts/script.php?script_id=3223
|
||||
|
||||
LanguageTool can be downloaded from:
|
||||
|
||||
http://www.languagetool.org/
|
||||
|
||||
============================================================================
|
||||
|
||||
4. Installation *languagetool-installation*
|
||||
|
||||
4.1 Installing the plugin~
|
||||
|
||||
Unzip file LanguageTool.zip plugin from in your personal |vimfiles| directory
|
||||
(~/.vim under Unix or %HOMEPATH%\vimfiles under Windows): >
|
||||
|
||||
$ mkdir ~/.vim
|
||||
$ cd ~/.vim
|
||||
$ unzip /path-to/LanguageTool.zip
|
||||
$ vim -c 'helptags ~/.vim/doc'
|
||||
|
||||
The zip file contains the following files: >
|
||||
|
||||
plugin/LanguageTool.vim
|
||||
doc/LanguageTool.vim
|
||||
|
||||
You have to enable plugins by adding these two lines in your |.vimrc| file: >
|
||||
|
||||
set nocompatible
|
||||
filetype plugin on
|
||||
|
||||
4.2 Installing LanguageTool~
|
||||
|
||||
To use this plugin, you need to install the Java LanguageTool program. You
|
||||
can choose to:
|
||||
|
||||
* download stand-alone version of LanguageTool (LanguageTool-*.zip) from:
|
||||
http://www.languagetool.org/ using the orange button labeled
|
||||
"Download LanguageTool for stand-alone use". The standalone version of
|
||||
Vim not only does grammar checking but also contains Hunspell dictionaries
|
||||
for spell checking.
|
||||
* or download a nightly build LanguageTool-.*-snapshot.zip from
|
||||
http://www.languagetool.org/download/snapshots/. It contains a more
|
||||
recent version than the stable version but it is not as well tested.
|
||||
* or checkout and build the latest LanguageTool from sources in git.
|
||||
|
||||
Recent versions of LanguageTool require Java-8.
|
||||
|
||||
4.2.1 Download the stand-alone version of LanguageTool~
|
||||
|
||||
Download the stand-alone version of LanguageTool (LanguageTool-*.zip)
|
||||
from http://www.languagetool.org/, click on "LanguageTool stand-alone
|
||||
for your desktop" to download it. Unzip it: >
|
||||
|
||||
$ unzip LanguageTool-3.5.zip
|
||||
|
||||
This should extract the file LanguageTool-3.5/languagetool-commandline.jar
|
||||
among several other files.
|
||||
|
||||
4.2.2 Build LanguageTool from sources in git~
|
||||
|
||||
If you prefer to build LanguageTool yourself from sources, you first need
|
||||
to install the pre-requisite packages. On Ubuntu, you need to install the
|
||||
following packages: >
|
||||
|
||||
$ sudo apt-get install openjdk-8-jdk mvn git
|
||||
|
||||
LanguageTool can then be downloaded and built with Maven as follows: >
|
||||
|
||||
$ git clone https://github.com/languagetool-org/languagetool.git
|
||||
$ cd languagetool
|
||||
$ mvn clean package
|
||||
|
||||
After the build, the command line version of LanguageTool can be found in: >
|
||||
|
||||
./languagetool-standalone/target/LanguageTool-3.6-SNAPSHOT/LanguageTool-3.6-SNAPSHOT/languagetool-commandline.jar
|
||||
|
||||
4.3 Configuring the location of the jar file~
|
||||
|
||||
After installing LanguageTool, you must specify the location of the file
|
||||
languagetool-commandline.jar in your $HOME/.vimrc file. Example: >
|
||||
|
||||
let g:languagetool_jar='$HOME/languagetool/languagetool-standalone/target/LanguageTool-3.6-SNAPSHOT/LanguageTool-3.6-SNAPSHOT/languagetool-commandline.jar'
|
||||
|
||||
See section |languagetool-configuration| for more optional settings.
|
||||
|
||||
============================================================================
|
||||
|
||||
5. Configuration *languagetool-configuration*
|
||||
|
||||
LanguageTool plugin uses character encoding from the 'fenc' option or from
|
||||
the 'enc' option if 'fenc' is empty.
|
||||
|
||||
Several global variables can be set in your |vimrc| to configure the behavior
|
||||
of the LanguageTool plugin.
|
||||
|
||||
g:languagetool_jar *g:languagetool_jar*
|
||||
|
||||
This variable specifies the location of the LanguageTool java grammar
|
||||
checker program. Default is empty.
|
||||
|
||||
Example: >
|
||||
|
||||
:let g:languagetool_jar='$HOME/languagetool/languagetool-standalone/target/LanguageTool-2.5-SNAPSHOT/LanguageTool-2.5-SNAPSHOT/languagetool-commandline.jar'
|
||||
|
||||
g:languagetool_lang *g:languagetool_lang*
|
||||
|
||||
The language code to use for the language tool checker. If undefined,
|
||||
plugin tries to guess the language of the Vim spelling checker
|
||||
'spelllang' or v:lang. If neither works, plugin defaults to
|
||||
English US (en-US). Starting with LanguageTool-1.8, regional variants
|
||||
of some languages can be specified. For languages with variants
|
||||
(currently English German and Portuguese), it is necessary to specify the
|
||||
variant in order for LanguageTool to signal spelling errors. In other
|
||||
words, with :set spelllang=en LanguageTool only signals grammar
|
||||
mistakes whereas with :set spellllang=en_us LanguageTool signals
|
||||
spelling mistakes and grammar mistakes. The valid language codes are: >
|
||||
|
||||
ast Asturian
|
||||
be Belarusian
|
||||
br Breton
|
||||
ca Catalan
|
||||
cs Czech
|
||||
da Danish
|
||||
de German
|
||||
de-AT German (Austria)
|
||||
de-CH German (Switzerland)
|
||||
de-DE German (Germany)
|
||||
el Greek
|
||||
en English
|
||||
en-AU English (Australia)
|
||||
en-CA English (Canada)
|
||||
en-GB English (Great Britain)
|
||||
en-NZ English (New Zealand)
|
||||
en-US English (US)
|
||||
en-ZA English (South Africa)
|
||||
eo Esperanto
|
||||
es Spanish
|
||||
fa Persian
|
||||
fr French
|
||||
gl Galician
|
||||
is Icelandic
|
||||
it Italian
|
||||
ja Japanese
|
||||
km Khmer
|
||||
lt Lithuanian
|
||||
ml Malayalam
|
||||
nl Dutch
|
||||
pl Polish
|
||||
pt Portuguese
|
||||
pt-BR Portuguese (Brazil)
|
||||
pt-PT Portuguese (Portugal)
|
||||
ro Romanian
|
||||
ru Russian
|
||||
sk Slovak
|
||||
sl Slovenian
|
||||
sv Swedish
|
||||
ta Tamil
|
||||
tl Tagalog
|
||||
uk Ukrainian
|
||||
zh Chinese
|
||||
|
||||
g:languagetool_disable_rules *g:languagetool_disable_rules*
|
||||
|
||||
This variable specifies checker rules which are disabled. Each disabled
|
||||
rule must be comma separated.
|
||||
Default value set by plugin is: WHITESPACE_RULE,EN_QUOTES
|
||||
|
||||
g:languagetool_win_height *g:languagetool_win_height*
|
||||
|
||||
This variable specifies the height of the scratch window which contains
|
||||
all grammatical mistakes with some explanations. You can use a negative
|
||||
value to disable opening the scratch window. You can also make it empty ''
|
||||
to let Vim pick a default size.
|
||||
Default is: 14
|
||||
|
||||
You can also customize the following syntax highlighting groups: >
|
||||
|
||||
LanguageToolCmd
|
||||
LanguageToolErrorCount
|
||||
LanguageToolLabel
|
||||
LanguageToolUrl
|
||||
LanguageToolGrammarError
|
||||
LanguageToolSpellingError
|
||||
|
||||
============================================================================
|
||||
|
||||
6. Features *languagetool-features*
|
||||
|
||||
The LanguageTool plugin defines 2 commands |:LanguageToolCheck| and
|
||||
|:LanguageToolClean|.
|
||||
|
||||
:LanguageToolCheck *:LanguageToolCheck*
|
||||
|
||||
Use the |:LanguageToolCheck| command to check the grammar in the current
|
||||
buffer. This will highlight errors in the buffer. It will also open a new
|
||||
scratch window with the list of grammar mistakes with further explanations
|
||||
for each error. It also populates the location-list for the window.
|
||||
|
||||
The |:LanguageToolCheck| command accepts a range. You can for example check
|
||||
grammar between lines 100 and 200 in buffer with :100,200LanguageToolCheck,
|
||||
check grammar in the visual selection with :<',>'LanguageToolCheck, etc.
|
||||
The default range is 1,$ (whole buffer).
|
||||
|
||||
:LanguageToolClear *:LanguageToolClear*
|
||||
|
||||
Use the |:LanguageToolClear| command to clear highlighting of grammar
|
||||
mistakes, close the scratch window containing the list of errors, clear
|
||||
and close the location-list.
|
||||
|
||||
The two commands are also available from the menu in gvim: >
|
||||
|
||||
Plugin -> LanguageTool -> Check
|
||||
-> Clear
|
||||
|
||||
Using the error scratch window~
|
||||
|
||||
Pressing <Enter> on an error in the error scratch buffer will jump to that
|
||||
error.
|
||||
|
||||
Using the Location-list~
|
||||
|
||||
The |location-list| is populated when running |:LanguageToolCheck|. So you can
|
||||
use location-list Vim commands such as |:lopen| to open the location-list
|
||||
window, |:lne| to jump to the next error, etc.
|
||||
|
||||
The error scratch window may seem redundant with the location-list, but the
|
||||
scratch window is more flexible to present errors in a nice way. If you do
|
||||
not wish to popup the error scratch window, but use the location-list only,
|
||||
you can disable it by setting |g:languagetool_win_height| to a negative value.
|
||||
|
||||
============================================================================
|
||||
|
||||
7. Bugs *languagetool-bugs*
|
||||
|
||||
Please report bugs or suggestions to <dominique.pelle@gmail.com>.
|
||||
Alternatively, you can also discuss improvements to this plugin in Wiki
|
||||
by clicking on the "Vim wiki" link at the top of the script page:
|
||||
|
||||
http://www.vim.org/scripts/script.php?script_id=3223
|
||||
|
||||
============================================================================
|
||||
|
||||
8. License *languagetool-license*
|
||||
|
||||
The VIM LICENSE applies to the LanguageTool.vim plugin (see |copyright|
|
||||
except use "LanguageTool.vim" instead of "Vim").
|
||||
|
||||
LanguageTool is freely available under LGPL.
|
||||
|
||||
============================================================================
|
||||
vim:tw=78:fo=tcq2:isk=!-~,^*,^\|,^\":ts=8:ft=help:norl:
|
||||
@@ -1,65 +0,0 @@
|
||||
markdown-footnotes, add footnotes in markdown *markdown-footnotes* *footnotes*
|
||||
|
||||
===========================================================================
|
||||
0. Introduction ~
|
||||
*markdown-footnotes-intro*
|
||||
|
||||
To insert a footnote, hit `<Leader>f` in normal mode or type `[]`. Then
|
||||
|
||||
- A footnote mark will be inserted after the cursor,
|
||||
- A matching footnote mark will be inserted at the end of the file, and
|
||||
- a split window at the bottom will open, ready to edit the new footnote.
|
||||
|
||||
When done, type `ZZ` to close the split and return to the main text.
|
||||
|
||||
===========================================================================
|
||||
1. Commands ~
|
||||
*markdown-footnotes-commands*
|
||||
|
||||
`AddVimFootnote`
|
||||
: inserts footnotemark at cursor location, inserts footnotemark on new
|
||||
line at end of file, opens a split window all ready for you to enter in
|
||||
the footnote.
|
||||
|
||||
`ReturnFromFootnote`
|
||||
: closes the split window and returns to the text in proper place.
|
||||
|
||||
These are mapped to `<Leader>f` and `<Leader>r` respectively.
|
||||
|
||||
`FootnoteNumber`
|
||||
: Change the current footnote number (one obligatory argument)
|
||||
:FootnoteNumber 5
|
||||
|
||||
`FootnoteNumberRestore`
|
||||
: Restore old footnote number
|
||||
|
||||
`FootnoteUndo`
|
||||
: Decrease footnote counter by 1
|
||||
|
||||
`FootnoteMeta [<footnotetype>]`
|
||||
: Change type of the footnotes and restart counter (1, a, A, i, I, *)
|
||||
|
||||
The `<footnotetype>` argument is optional. If omitted, and your previous
|
||||
footnote type was not `arabic`, the new type will be `arabic`; if it was
|
||||
arabic, the new type will be `alpha`. If the new type is the same as the
|
||||
previous type, then the counter will not be restarted.
|
||||
|
||||
|
||||
`FootnoteRestore`
|
||||
: Restore previous footnote type and counter.
|
||||
<
|
||||
===========================================================================
|
||||
2. Config ~
|
||||
*markdown-footnotes-config*
|
||||
|
||||
By default, footnote ids are arabic numerals. You can change this by
|
||||
setting `b:vimfootnotetype` in ~/.vim/ftplugin/markdown.vim:
|
||||
|
||||
+ `arabic`: 1, 2, 3...
|
||||
+ `alpha`: a, b, c, aa, bb..., zz, a...
|
||||
+ `Alpha`: A, B, C, AA, BB..., ZZ, A...
|
||||
+ `roman`: i, ii, iii... (displayed properly up to 89)
|
||||
+ `Roman`: I, II, III...
|
||||
+ `star`: \*, \*\*, \*\*\*...
|
||||
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl
|
||||
@@ -1,206 +0,0 @@
|
||||
*surround.txt* Plugin for deleting, changing, and adding "surroundings"
|
||||
|
||||
Author: Tim Pope <http://tpo.pe/>
|
||||
License: Same terms as Vim itself (see |license|)
|
||||
|
||||
This plugin is only available if 'compatible' is not set.
|
||||
|
||||
INTRODUCTION *surround*
|
||||
|
||||
This plugin is a tool for dealing with pairs of "surroundings." Examples
|
||||
of surroundings include parentheses, quotes, and HTML tags. They are
|
||||
closely related to what Vim refers to as |text-objects|. Provided
|
||||
are mappings to allow for removing, changing, and adding surroundings.
|
||||
|
||||
Details follow on the exact semantics, but first, consider the following
|
||||
examples. An asterisk (*) is used to denote the cursor position.
|
||||
|
||||
Old text Command New text ~
|
||||
"Hello *world!" ds" Hello world!
|
||||
[123+4*56]/2 cs]) (123+456)/2
|
||||
"Look ma, I'm *HTML!" cs"<q> <q>Look ma, I'm HTML!</q>
|
||||
if *x>3 { ysW( if ( x>3 ) {
|
||||
my $str = *whee!; vllllS' my $str = 'whee!';
|
||||
|
||||
While a few features of this plugin will work in older versions of Vim,
|
||||
Vim 7 is recommended for full functionality.
|
||||
|
||||
MAPPINGS *surround-mappings*
|
||||
|
||||
Delete surroundings is *ds* . The next character given determines the target
|
||||
to delete. The exact nature of the target is explained in |surround-targets|
|
||||
but essentially it is the last character of a |text-object|. This mapping
|
||||
deletes the difference between the "i"nner object and "a"n object. This is
|
||||
easiest to understand with some examples:
|
||||
|
||||
Old text Command New text ~
|
||||
"Hello *world!" ds" Hello world!
|
||||
(123+4*56)/2 ds) 123+456/2
|
||||
<div>Yo!*</div> dst Yo!
|
||||
|
||||
Change surroundings is *cs* . It takes two arguments, a target like with
|
||||
|ds|, and a replacement. *cS* changes surroundings, placing the surrounded
|
||||
text on its own line(s) like |yS|. Details about the second argument can be
|
||||
found below in |surround-replacements|. Once again, examples are in order.
|
||||
|
||||
Old text Command New text ~
|
||||
"Hello *world!" cs"' 'Hello world!'
|
||||
"Hello *world!" cs"<q> <q>Hello world!</q>
|
||||
(123+4*56)/2 cs)] [123+456]/2
|
||||
(123+4*56)/2 cs)[ [ 123+456 ]/2
|
||||
<div>Yo!*</div> cst<p> <p>Yo!</p>
|
||||
|
||||
*ys* takes a valid Vim motion or text object as the first object, and wraps
|
||||
it using the second argument as with |cs|. (It's a stretch, but a good
|
||||
mnemonic for "ys" is "you surround".)
|
||||
|
||||
Old text Command New text ~
|
||||
Hello w*orld! ysiw) Hello (world)!
|
||||
|
||||
As a special case, *yss* operates on the current line, ignoring leading
|
||||
whitespace.
|
||||
|
||||
Old text Command New text ~
|
||||
Hello w*orld! yssB {Hello world!}
|
||||
|
||||
There is also *yS* and *ySS* which indent the surrounded text and place it
|
||||
on a line of its own.
|
||||
|
||||
In visual mode, a simple "S" with an argument wraps the selection. This is
|
||||
referred to as the *vS* mapping, although ordinarily there will be
|
||||
additional keystrokes between the v and S. In linewise visual mode, the
|
||||
surroundings are placed on separate lines and indented. In blockwise visual
|
||||
mode, each line is surrounded.
|
||||
|
||||
A "gS" in visual mode, known as *vgS* , behaves similarly. In linewise visual
|
||||
mode, the automatic indenting is suppressed. In blockwise visual mode, this
|
||||
enables surrounding past the end of the line with 'virtualedit' set (there
|
||||
seems to be no way in Vim Script to differentiate between a jagged end of line
|
||||
selection and a virtual block selected past the end of the line, so two maps
|
||||
were needed).
|
||||
|
||||
*i_CTRL-G_s* *i_CTRL-G_S*
|
||||
Finally, there is an experimental insert mode mapping on <C-G>s and <C-S>.
|
||||
Beware that the latter won't work on terminals with flow control (if you
|
||||
accidentally freeze your terminal, use <C-Q> to unfreeze it). The mapping
|
||||
inserts the specified surroundings and puts the cursor between them. If,
|
||||
immediately after the mapping and before the replacement, a second <C-S> or
|
||||
carriage return is pressed, the prefix, cursor, and suffix will be placed on
|
||||
three separate lines. <C-G>S (not <C-G>s) also exhibits this behavior.
|
||||
|
||||
TARGETS *surround-targets*
|
||||
|
||||
The |ds| and |cs| commands both take a target as their first argument. The
|
||||
possible targets are based closely on the |text-objects| provided by Vim.
|
||||
All targets are currently just one character.
|
||||
|
||||
Eight punctuation marks, (, ), {, }, [, ], <, and >, represent themselves
|
||||
and their counterparts. If the opening mark is used, contained whitespace is
|
||||
also trimmed. The targets b, B, r, and a are aliases for ), }, ], and >
|
||||
(the first two mirror Vim; the second two are completely arbitrary and
|
||||
subject to change).
|
||||
|
||||
Three quote marks, ', ", `, represent themselves, in pairs. They are only
|
||||
searched for on the current line.
|
||||
|
||||
A t is a pair of HTML or XML tags. See |tag-blocks| for details. Remember
|
||||
that you can specify a numerical argument if you want to get to a tag other
|
||||
than the innermost one.
|
||||
|
||||
The letters w, W, and s correspond to a |word|, a |WORD|, and a |sentence|,
|
||||
respectively. These are special in that they have nothing to delete, and
|
||||
used with |ds| they are a no-op. With |cs|, one could consider them a
|
||||
slight shortcut for ysi (cswb == ysiwb, more or less).
|
||||
|
||||
A p represents a |paragraph|. This behaves similarly to w, W, and s above;
|
||||
however, newlines are sometimes added and/or removed.
|
||||
|
||||
REPLACEMENTS *surround-replacements*
|
||||
|
||||
A replacement argument is a single character, and is required by |cs|, |ys|,
|
||||
and |vS|. Undefined replacement characters (with the exception of alphabetic
|
||||
characters) default to placing themselves at the beginning and end of the
|
||||
destination, which can be useful for characters like / and |.
|
||||
|
||||
If either ), }, ], or > is used, the text is wrapped in the appropriate pair
|
||||
of characters. Similar behavior can be found with (, {, and [ (but not <),
|
||||
which append an additional space to the inside. Like with the targets above,
|
||||
b, B, r, and a are aliases for ), }, ], and >. To fulfill the common need for
|
||||
code blocks in C-style languages, <C-}> (which is really <C-]>) adds braces on
|
||||
lines separate from the content.
|
||||
|
||||
If t or < is used, Vim prompts for an HTML/XML tag to insert. You may specify
|
||||
attributes here and they will be stripped from the closing tag. End your
|
||||
input by pressing <CR> or >. If <C-T> is used, the tags will appear on lines
|
||||
by themselves.
|
||||
|
||||
If s is used, a leading but not trailing space is added. This is useful for
|
||||
removing parentheses from a function call with csbs.
|
||||
|
||||
CUSTOMIZING *surround-customizing*
|
||||
|
||||
The following adds a potential replacement on "-" (ASCII 45) in PHP files.
|
||||
(To determine the ASCII code to use, :echo char2nr("-")). The carriage
|
||||
return will be replaced by the original text.
|
||||
>
|
||||
autocmd FileType php let b:surround_45 = "<?php \r ?>"
|
||||
<
|
||||
This can be used in a PHP file as in the following example.
|
||||
|
||||
Old text Command New text ~
|
||||
print "Hello *world!" yss- <?php print "Hello world!" ?>
|
||||
|
||||
Additionally, one can use a global variable for globally available
|
||||
replacements.
|
||||
>
|
||||
let g:surround_45 = "<% \r %>"
|
||||
let g:surround_61 = "<%= \r %>"
|
||||
<
|
||||
Advanced, experimental, and subject to change: One can also prompt for
|
||||
replacement text. The syntax for this is to surround the replacement in pairs
|
||||
of low numbered control characters. If this sounds confusing, that's because
|
||||
it is (but it makes the parsing easy). Consider the following example for a
|
||||
LaTeX environment on the "l" replacement.
|
||||
>
|
||||
let g:surround_108 = "\\begin{\1environment: \1}\r\\end{\1\1}"
|
||||
<
|
||||
When this replacement is used, the user is prompted with an "environment: "
|
||||
prompt for input. This input is inserted between each set of \1's.
|
||||
Additional inputs up to \7 can be used.
|
||||
|
||||
Furthermore, one can specify a regular expression substitution to apply.
|
||||
>
|
||||
let g:surround_108 = "\\begin{\1environment: \1}\r\\end{\1\r}.*\r\1}"
|
||||
<
|
||||
This will remove anything after the first } in the input when the text is
|
||||
placed within the \end{} slot. The first \r marks where the pattern begins,
|
||||
and the second where the replacement text begins.
|
||||
|
||||
Here's a second example for creating an HTML <div>. The substitution cleverly
|
||||
prompts for an id, but only adds id="" if it is non-blank. You may have to
|
||||
read this one a few times slowly before you understand it.
|
||||
>
|
||||
let g:surround_{char2nr("d")} = "<div\1id: \r..*\r id=\"&\"\1>\r</div>"
|
||||
<
|
||||
Inputting text replacements is a proof of concept at this point. The ugly,
|
||||
unintuitive interface and the brevity of the documentation reflect this.
|
||||
|
||||
Finally, It is possible to always append a string to surroundings in insert
|
||||
mode (and only insert mode). This is useful with certain plugins and mappings
|
||||
that allow you to jump to such markings.
|
||||
>
|
||||
let g:surround_insert_tail = "<++>"
|
||||
<
|
||||
ISSUES *surround-issues*
|
||||
|
||||
Vim could potentially get confused when deleting/changing occurs at the very
|
||||
end of the line. Please report any repeatable instances of this.
|
||||
|
||||
Do we need to use |inputsave()|/|inputrestore()| with the tag replacement?
|
||||
|
||||
Indenting is handled haphazardly. Need to decide the most appropriate
|
||||
behavior and implement it. Right now one can do :let b:surround_indent = 1
|
||||
(or the global equivalent) to enable automatic re-indenting by Vim via |=|;
|
||||
should this be the default?
|
||||
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
||||
@@ -1,34 +0,0 @@
|
||||
:LanguageToolCheck LanguageTool.txt /*:LanguageToolCheck*
|
||||
:LanguageToolClear LanguageTool.txt /*:LanguageToolClear*
|
||||
LanguageTool LanguageTool.txt /*LanguageTool*
|
||||
LanguageTool.txt LanguageTool.txt /*LanguageTool.txt*
|
||||
cS surround.txt /*cS*
|
||||
cs surround.txt /*cs*
|
||||
ds surround.txt /*ds*
|
||||
g:languagetool_disable_rules LanguageTool.txt /*g:languagetool_disable_rules*
|
||||
g:languagetool_jar LanguageTool.txt /*g:languagetool_jar*
|
||||
g:languagetool_lang LanguageTool.txt /*g:languagetool_lang*
|
||||
g:languagetool_win_height LanguageTool.txt /*g:languagetool_win_height*
|
||||
i_CTRL-G_S surround.txt /*i_CTRL-G_S*
|
||||
i_CTRL-G_s surround.txt /*i_CTRL-G_s*
|
||||
languagetool-bugs LanguageTool.txt /*languagetool-bugs*
|
||||
languagetool-configuration LanguageTool.txt /*languagetool-configuration*
|
||||
languagetool-download LanguageTool.txt /*languagetool-download*
|
||||
languagetool-features LanguageTool.txt /*languagetool-features*
|
||||
languagetool-installation LanguageTool.txt /*languagetool-installation*
|
||||
languagetool-license LanguageTool.txt /*languagetool-license*
|
||||
languagetool-overview LanguageTool.txt /*languagetool-overview*
|
||||
languagetool-screenshots LanguageTool.txt /*languagetool-screenshots*
|
||||
surround surround.txt /*surround*
|
||||
surround-customizing surround.txt /*surround-customizing*
|
||||
surround-issues surround.txt /*surround-issues*
|
||||
surround-mappings surround.txt /*surround-mappings*
|
||||
surround-replacements surround.txt /*surround-replacements*
|
||||
surround-targets surround.txt /*surround-targets*
|
||||
surround.txt surround.txt /*surround.txt*
|
||||
vS surround.txt /*vS*
|
||||
vgS surround.txt /*vgS*
|
||||
yS surround.txt /*yS*
|
||||
ySS surround.txt /*ySS*
|
||||
ys surround.txt /*ys*
|
||||
yss surround.txt /*yss*
|
||||
@@ -1,4 +0,0 @@
|
||||
" Include all in advanced
|
||||
source ~/.vim/advanced.vim
|
||||
|
||||
source ~/.vim/_spellcheck.vim
|
||||
@@ -1,4 +0,0 @@
|
||||
augroup filetypedetect
|
||||
" Mail
|
||||
autocmd BufRead,BufNewFile *astroid* setfiletype mail
|
||||
augroup END
|
||||
@@ -1,6 +0,0 @@
|
||||
" Include all in advanced
|
||||
source ~/.vim/advanced.vim
|
||||
|
||||
source ~/.vim/_email-addresses.vim
|
||||
source ~/.vim/_spellcheck.vim
|
||||
source ~/.vim/_gvim-style.vim
|
||||
@@ -1,396 +0,0 @@
|
||||
" LanguageTool: Grammar checker in Vim for English, French, German, etc.
|
||||
" Maintainer: Dominique Pellé <dominique.pelle@gmail.com>
|
||||
" Screenshots: http://dominique.pelle.free.fr/pic/LanguageToolVimPlugin_en.png
|
||||
" http://dominique.pelle.free.fr/pic/LanguageToolVimPlugin_fr.png
|
||||
" Last Change: 2016/10/06
|
||||
" Version: 1.30
|
||||
"
|
||||
" Long Description: {{{1
|
||||
"
|
||||
" This plugin integrates the LanguageTool grammar checker into Vim.
|
||||
" Current version of LanguageTool can check grammar in many languages:
|
||||
" ast, be, br, ca, da, de, el, en, eo, es, fa, fr, gl, is, it, ja, km, lt,
|
||||
" ml, nl, pl, pt, ro, ru, sk, sl, sv, ta, tl, uk, zh.
|
||||
"
|
||||
" See doc/LanguageTool.txt for more details about how to use the
|
||||
" LanguageTool plugin.
|
||||
"
|
||||
" See http://www.languagetool.org/ for more information about LanguageTool.
|
||||
"
|
||||
" License: {{{1
|
||||
"
|
||||
" The VIM LICENSE applies to LanguageTool.vim plugin
|
||||
" (see ":help copyright" except use "LanguageTool.vim" instead of "Vim").
|
||||
"
|
||||
" Plugin set up {{{1
|
||||
if &cp || exists("g:loaded_languagetool")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_languagetool = "1"
|
||||
|
||||
" Guess language from 'a:lang' (either 'spelllang' or 'v:lang')
|
||||
function s:FindLanguage(lang) "{{{1
|
||||
" This replaces things like en_gb en-GB as expected by LanguageTool,
|
||||
" only for languages that support variants in LanguageTool.
|
||||
let l:language = substitute(substitute(a:lang,
|
||||
\ '\(\a\{2,3}\)\(_\a\a\)\?.*',
|
||||
\ '\=tolower(submatch(1)) . toupper(submatch(2))', ''),
|
||||
\ '_', '-', '')
|
||||
|
||||
" All supported languages (with variants) from version LanguageTool.
|
||||
let l:supportedLanguages = {
|
||||
\ 'ast' : 1,
|
||||
\ 'be' : 1,
|
||||
\ 'br' : 1,
|
||||
\ 'ca' : 1,
|
||||
\ 'cs' : 1,
|
||||
\ 'da' : 1,
|
||||
\ 'de' : 1,
|
||||
\ 'de-AT' : 1,
|
||||
\ 'de-CH' : 1,
|
||||
\ 'de-DE' : 1,
|
||||
\ 'el' : 1,
|
||||
\ 'en' : 1,
|
||||
\ 'en-AU' : 1,
|
||||
\ 'en-CA' : 1,
|
||||
\ 'en-GB' : 1,
|
||||
\ 'en-NZ' : 1,
|
||||
\ 'en-US' : 1,
|
||||
\ 'en-ZA' : 1,
|
||||
\ 'eo' : 1,
|
||||
\ 'es' : 1,
|
||||
\ 'fa' : 1,
|
||||
\ 'fr' : 1,
|
||||
\ 'gl' : 1,
|
||||
\ 'is' : 1,
|
||||
\ 'it' : 1,
|
||||
\ 'ja' : 1,
|
||||
\ 'km' : 1,
|
||||
\ 'lt' : 1,
|
||||
\ 'ml' : 1,
|
||||
\ 'nl' : 1,
|
||||
\ 'pl' : 1,
|
||||
\ 'pt' : 1,
|
||||
\ 'pt-BR' : 1,
|
||||
\ 'pt-PT' : 1,
|
||||
\ 'ro' : 1,
|
||||
\ 'ru' : 1,
|
||||
\ 'sk' : 1,
|
||||
\ 'sl' : 1,
|
||||
\ 'sv' : 1,
|
||||
\ 'ta' : 1,
|
||||
\ 'tl' : 1,
|
||||
\ 'uk' : 1,
|
||||
\ 'zh' : 1
|
||||
\}
|
||||
|
||||
if has_key(l:supportedLanguages, l:language)
|
||||
return l:language
|
||||
endif
|
||||
|
||||
" Removing the region (if any) and trying again.
|
||||
let l:language = substitute(l:language, '-.*', '', '')
|
||||
return has_key(l:supportedLanguages, l:language) ? l:language : ''
|
||||
endfunction
|
||||
|
||||
" Return a regular expression used to highlight a grammatical error
|
||||
" at line a:line in text. The error starts at character a:start in
|
||||
" context a:context and its length in context is a:len.
|
||||
function s:LanguageToolHighlightRegex(line, context, start, len) "{{{1
|
||||
let l:start_idx = byteidx(a:context, a:start)
|
||||
let l:end_idx = byteidx(a:context, a:start + a:len) - 1
|
||||
let l:start_ctx_idx = byteidx(a:context, a:start + a:len)
|
||||
let l:end_ctx_idx = byteidx(a:context, a:start + a:len + 5) - 1
|
||||
|
||||
" The substitute allows matching errors which span multiple lines.
|
||||
" The part after \ze gives a bit of context to avoid spurious
|
||||
" highlighting when the text of the error is present multiple
|
||||
" times in the line.
|
||||
return '\V'
|
||||
\ . '\%' . a:line . 'l'
|
||||
\ . substitute(escape(a:context[l:start_idx : l:end_idx], "'\\"), ' ', '\\_\\s', 'g')
|
||||
\ . '\ze'
|
||||
\ . substitute(escape(a:context[l:start_ctx_idx : l:end_ctx_idx], "'\\"), ' ', '\\_\\s', 'g')
|
||||
endfunction
|
||||
|
||||
" Unescape XML special characters in a:text.
|
||||
function s:XmlUnescape(text) "{{{1
|
||||
" Change XML escape char such as " into "
|
||||
" Substitution of & must be done last or else something
|
||||
" like &quot; would get first transformed into "
|
||||
" and then wrongly transformed into " (correct is ")
|
||||
let l:escaped = substitute(a:text, '"', '"', 'g')
|
||||
let l:escaped = substitute(l:escaped, ''', "'", 'g')
|
||||
let l:escaped = substitute(l:escaped, '>', '>', 'g')
|
||||
let l:escaped = substitute(l:escaped, '<', '<', 'g')
|
||||
let l:escaped = substitute(l:escaped, '	', ' ', 'g')
|
||||
return substitute(l:escaped, '&', '\&', 'g')
|
||||
endfunction
|
||||
|
||||
" Parse a xml attribute such as: ruleId="FOO" in line a:line.
|
||||
" where ruleId is the key a:key, and FOO is the returned value corresponding
|
||||
" to that key.
|
||||
function s:ParseKeyValue(key, line) "{{{1
|
||||
return s:XmlUnescape(matchstr(a:line, '\<' . a:key . '="\zs[^"]*\ze"'))
|
||||
endfunction
|
||||
|
||||
" Set up configuration.
|
||||
" Returns 0 if success, < 0 in case of error.
|
||||
function s:LanguageToolSetUp() "{{{1
|
||||
let s:languagetool_disable_rules = exists("g:languagetool_disable_rules")
|
||||
\ ? g:languagetool_disable_rules
|
||||
\ : 'WHITESPACE_RULE,EN_QUOTES'
|
||||
let s:languagetool_win_height = exists("g:languagetool_win_height")
|
||||
\ ? g:languagetool_win_height
|
||||
\ : 14
|
||||
let s:languagetool_encoding = &fenc ? &fenc : &enc
|
||||
|
||||
" Setting up language...
|
||||
if exists("g:languagetool_lang")
|
||||
let s:languagetool_lang = g:languagetool_lang
|
||||
else
|
||||
" Trying to guess language from 'spelllang' or 'v:lang'.
|
||||
let s:languagetool_lang = s:FindLanguage(&spelllang)
|
||||
if s:languagetool_lang == ''
|
||||
let s:languagetool_lang = s:FindLanguage(v:lang)
|
||||
if s:languagetool_lang == ''
|
||||
echoerr 'Failed to guess language from spelllang=['
|
||||
\ . &spelllang . '] or from v:lang=[' . v:lang . ']. '
|
||||
\ . 'Defauling to English (en-US). '
|
||||
\ . 'See ":help LanguageTool" regarding setting g:languagetool_lang.'
|
||||
let s:languagetool_lang = 'en-US'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let s:languagetool_jar = exists("g:languagetool_jar")
|
||||
\ ? g:languagetool_jar
|
||||
\ : $HOME . '/languagetool/languagetool-commandline.jar'
|
||||
|
||||
if !filereadable(s:languagetool_jar)
|
||||
" Hmmm, can't find the jar file. Try again with expand() in case user
|
||||
" set it up as: let g:languagetool_jar = '$HOME/languagetool-commandline.jar'
|
||||
let l:languagetool_jar = expand(s:languagetool_jar)
|
||||
if !filereadable(expand(l:languagetool_jar))
|
||||
echomsg "LanguageTool cannot be found at: " . s:languagetool_jar
|
||||
echomsg "You need to install LanguageTool and/or set up g:languagetool_jar"
|
||||
echomsg "to indicate the location of the languagetool-commandline.jar file."
|
||||
return -1
|
||||
endif
|
||||
let s:languagetool_jar = l:languagetool_jar
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Jump to a grammar mistake (called when pressing <Enter>
|
||||
" on a particular error in scratch buffer).
|
||||
function <sid>JumpToCurrentError() "{{{1
|
||||
let l:save_cursor = getpos('.')
|
||||
norm! $
|
||||
if search('^Error:\s\+', 'beW') > 0
|
||||
let l:error_idx = expand('<cword>')
|
||||
let l:error = s:errors[l:error_idx - 1]
|
||||
let l:line = l:error['fromy']
|
||||
let l:col = l:error['fromx']
|
||||
let l:rule = l:error['ruleId']
|
||||
call setpos('.', l:save_cursor)
|
||||
exe s:languagetool_text_win . ' wincmd w'
|
||||
exe 'norm! ' . l:line . 'G0'
|
||||
if l:col > 0
|
||||
exe 'norm! ' . (l:col - 1) . 'l'
|
||||
endif
|
||||
|
||||
echon 'Jump to error ' . l:error_idx . '/' . len(s:errors)
|
||||
\ . ' (' . l:rule . ') ...@ ' . l:line . 'L ' . l:col . 'C'
|
||||
norm! zz
|
||||
else
|
||||
call setpos('.', l:save_cursor)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" This function performs grammar checking of text in the current buffer.
|
||||
" It highlights grammar mistakes in current buffer and opens a scratch
|
||||
" window with all errors found. It also populates the location-list of
|
||||
" the window with all errors.
|
||||
" a:line1 and a:line2 parameters are the first and last line number of
|
||||
" the range of line to check.
|
||||
" Returns 0 if success, < 0 in case of error.
|
||||
function s:LanguageToolCheck(line1, line2) "{{{1
|
||||
if s:LanguageToolSetUp() < 0
|
||||
return -1
|
||||
endif
|
||||
call s:LanguageToolClear()
|
||||
|
||||
let s:languagetool_text_win = winnr()
|
||||
sil %y
|
||||
botright new
|
||||
let s:languagetool_error_buffer = bufnr('%')
|
||||
let s:languagetool_error_win = winnr()
|
||||
sil put!
|
||||
|
||||
" LanguageTool somehow gives incorrect line/column numbers when
|
||||
" reading from stdin so we need to use a temporary file to get
|
||||
" correct results.
|
||||
let l:tmpfilename = tempname()
|
||||
let l:tmperror = tempname()
|
||||
|
||||
let l:range = a:line1 . ',' . a:line2
|
||||
silent exe l:range . 'w!' . l:tmpfilename
|
||||
|
||||
let l:languagetool_cmd = 'java'
|
||||
\ . ' -jar ' . s:languagetool_jar
|
||||
\ . ' -c ' . s:languagetool_encoding
|
||||
\ . (empty(s:languagetool_disable_rules) ? '' : ' -d '.s:languagetool_disable_rules)
|
||||
\ . ' -l ' . s:languagetool_lang
|
||||
\ . ' --api ' . l:tmpfilename
|
||||
\ . ' 2> ' . l:tmperror
|
||||
|
||||
sil exe '%!' . l:languagetool_cmd
|
||||
call delete(l:tmpfilename)
|
||||
|
||||
if v:shell_error
|
||||
echoerr 'Command [' . l:languagetool_cmd . '] failed with error: '
|
||||
\ . v:shell_error
|
||||
if filereadable(l:tmperror)
|
||||
echoerr string(readfile(l:tmperror))
|
||||
endif
|
||||
call delete(l:tmperror)
|
||||
call s:LanguageToolClear()
|
||||
return -1
|
||||
endif
|
||||
call delete(l:tmperror)
|
||||
|
||||
" Loop on all errors in XML output of LanguageTool and
|
||||
" collect information about all errors in list s:errors
|
||||
let s:errors = []
|
||||
while search('^<error ', 'eW') > 0
|
||||
let l:l = getline('.')
|
||||
" The fromx and tox given by LanguageTool are not reliable.
|
||||
" They are even sometimes negative!
|
||||
|
||||
let l:error= {}
|
||||
for l:k in [ 'fromy', 'fromx', 'tox', 'toy',
|
||||
\ 'ruleId', 'subId', 'msg', 'replacements',
|
||||
\ 'context', 'contextoffset', 'errorlength', 'url' ]
|
||||
let l:error[l:k] = s:ParseKeyValue(l:k, l:l)
|
||||
endfor
|
||||
|
||||
" Make line/column number start at 1 rather than 0.
|
||||
" Make also line number absolute as in buffer.
|
||||
let l:error['fromy'] += a:line1
|
||||
let l:error['fromx'] += 1
|
||||
let l:error['toy'] += a:line1
|
||||
let l:error['tox'] += 1
|
||||
|
||||
call add(s:errors, l:error)
|
||||
endwhile
|
||||
|
||||
if s:languagetool_win_height >= 0
|
||||
" Reformat the output of LanguageTool (XML is not human friendly) and
|
||||
" set up syntax highlighting in the buffer which shows all errors.
|
||||
sil %d
|
||||
call append(0, '# ' . l:languagetool_cmd)
|
||||
set bt=nofile
|
||||
setlocal nospell
|
||||
syn clear
|
||||
call matchadd('LanguageToolCmd', '\%1l.*')
|
||||
call matchadd('LanguageToolErrorCount', '^Error:\s\+\d\+.\d\+')
|
||||
call matchadd('LanguageToolLabel', '^\(Context\|Message\|Correction\|URL\):')
|
||||
call matchadd('LanguageToolUrl', '^URL:\s*\zs.*')
|
||||
|
||||
let l:i = 0
|
||||
for l:error in s:errors
|
||||
call append('$', 'Error: '
|
||||
\ . (l:i + 1) . '/' . len(s:errors)
|
||||
\ . ' ' . l:error['ruleId'] . ((len(l:error['subId']) == 0) ? '' : ':') . l:error['subId']
|
||||
\ . ' @ ' . l:error['fromy'] . 'L ' . l:error['fromx'] . 'C')
|
||||
call append('$', 'Message: ' . l:error['msg'])
|
||||
call append('$', 'Context: ' . l:error['context'])
|
||||
let l:re =
|
||||
\ '\%' . line('$') . 'l\%9c'
|
||||
\ . '.\{' . (4 + l:error['contextoffset']) . '}\zs'
|
||||
\ . '.\{' . (l:error['errorlength']) . '}'
|
||||
if l:error['ruleId'] =~# 'HUNSPELL_RULE\|HUNSPELL_NO_SUGGEST_RULE\|MORFOLOGIK_RULE_.*\|GERMAN_SPELLER_RULE'
|
||||
call matchadd('LanguageToolSpellingError', l:re)
|
||||
else
|
||||
call matchadd('LanguageToolGrammarError', l:re)
|
||||
endif
|
||||
if !empty(l:error['replacements'])
|
||||
call append('$', 'Correction: ' . l:error['replacements'])
|
||||
endif
|
||||
if !empty(l:error['url'])
|
||||
call append('$', 'URL: ' . l:error['url'])
|
||||
endif
|
||||
call append('$', '')
|
||||
let l:i += 1
|
||||
endfor
|
||||
exe "norm! z" . s:languagetool_win_height . "\<CR>"
|
||||
0
|
||||
map <silent> <buffer> <CR> :call <sid>JumpToCurrentError()<CR>
|
||||
redraw
|
||||
echon 'Press <Enter> on error in scratch buffer to jump its location'
|
||||
exe "norm! \<C-W>\<C-P>"
|
||||
else
|
||||
" Negative s:languagetool_win_height -> no scratch window.
|
||||
bd!
|
||||
unlet! s:languagetool_error_buffer
|
||||
endif
|
||||
|
||||
" Also highlight errors in original buffer and populate location list.
|
||||
setlocal errorformat=%f:%l:%c:%m
|
||||
for l:error in s:errors
|
||||
let l:re = s:LanguageToolHighlightRegex(l:error['fromy'],
|
||||
\ l:error['context'],
|
||||
\ l:error['contextoffset'],
|
||||
\ l:error['errorlength'])
|
||||
if l:error['ruleId'] =~# 'HUNSPELL_RULE\|HUNSPELL_NO_SUGGEST_RULE\|MORFOLOGIK_RULE_.*\|GERMAN_SPELLER_RULE'
|
||||
call matchadd('LanguageToolSpellingError', l:re)
|
||||
else
|
||||
call matchadd('LanguageToolGrammarError', l:re)
|
||||
endif
|
||||
laddexpr expand('%') . ':'
|
||||
\ . l:error['fromy'] . ':' . l:error['fromx'] . ':'
|
||||
\ . l:error['ruleId'] . ' ' . l:error['msg']
|
||||
endfor
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" This function clears syntax highlighting created by LanguageTool plugin
|
||||
" and removes the scratch window containing grammar errors.
|
||||
function s:LanguageToolClear() "{{{1
|
||||
if exists('s:languagetool_error_buffer')
|
||||
if bufexists(s:languagetool_error_buffer)
|
||||
sil! exe "bd! " . s:languagetool_error_buffer
|
||||
endif
|
||||
endif
|
||||
if exists('s:languagetool_text_win')
|
||||
let l:win = winnr()
|
||||
exe s:languagetool_text_win . ' wincmd w'
|
||||
call setmatches(filter(getmatches(), 'v:val["group"] !~# "LanguageTool.*Error"'))
|
||||
lexpr ''
|
||||
lclose
|
||||
exe l:win . ' wincmd w'
|
||||
endif
|
||||
unlet! s:languagetool_error_buffer
|
||||
unlet! s:languagetool_error_win
|
||||
unlet! s:languagetool_text_win
|
||||
endfunction
|
||||
|
||||
hi def link LanguageToolCmd Comment
|
||||
hi def link LanguageToolErrorCount Title
|
||||
hi def link LanguageToolLabel Label
|
||||
hi def link LanguageToolUrl Underlined
|
||||
hi def link LanguageToolGrammarError Error
|
||||
hi def link LanguageToolSpellingError WarningMsg
|
||||
|
||||
" Menu items {{{1
|
||||
if has("gui_running") && has("menu") && &go =~# 'm'
|
||||
amenu <silent> &Plugin.LanguageTool.Chec&k :LanguageToolCheck<CR>
|
||||
amenu <silent> &Plugin.LanguageTool.Clea&r :LanguageToolClear<CR>
|
||||
endif
|
||||
|
||||
" Defines commands {{{1
|
||||
com! -nargs=0 LanguageToolClear :call s:LanguageToolClear()
|
||||
com! -nargs=0 -range=% LanguageToolCheck :call s:LanguageToolCheck(<line1>,
|
||||
\ <line2>)
|
||||
" vim: fdm=marker
|
||||
@@ -1,273 +0,0 @@
|
||||
" Maintainer: David Sanson <dsanson@gmail.com>
|
||||
" Description: Extended Markdown Footnotes in Vim
|
||||
" Version: 1.0
|
||||
" URL: https://github.com/vim-pandoc/vim-markdownfootnotes
|
||||
"
|
||||
" I've taken the original and modified the output to fit the widely
|
||||
" supported extended markdown format for footnotes.[^note]
|
||||
"
|
||||
" [^note]: Like this.
|
||||
"
|
||||
" The original script either puts notes at the end, or before your
|
||||
" email sig line (i.e., if there is a line that consists of two dashes,
|
||||
" it puts the notes before that line). This version just puts them at
|
||||
" the end.
|
||||
"
|
||||
" Based On:
|
||||
" VimFootnotes
|
||||
" Author: Mikolaj Machowski <mikmach@wp.pl>
|
||||
" Version: 0.6
|
||||
" Description: Footnotes in Vim
|
||||
" Installation: See below
|
||||
" Last Change: pon wrz 30 09:00 2002 C
|
||||
" URL: http://www.vim.org/scripts/script.php?script_id=431
|
||||
" Help Part:
|
||||
" Inspired by Emmanuel Touzery tip:
|
||||
" http://vim.sourceforge.net/tip_view.php?tip_id=332
|
||||
" and discussion below (thanks to Luc for pluginization hints)
|
||||
" I added functions and turned it into vim script.
|
||||
"
|
||||
" Installation: Drop it to your plugin directory or use pathogen.
|
||||
"
|
||||
" Settings:
|
||||
"
|
||||
" By default, footnote ids are arabic numerals. You can change this by
|
||||
" setting b:vimfootnotetype,
|
||||
"
|
||||
" arabic (default) - [1] [2] [3] ...
|
||||
" alpha - [a] [b] ... [z] [aa] [bb] ... [zz] [a] ...
|
||||
" Alpha - as above but uppercase [A] ...
|
||||
" roman - [i] [ii] [iii] displayed properly up to 89
|
||||
" Roman - as above but uppercase [I] ...
|
||||
" star - [*] [**] [***] ...
|
||||
"
|
||||
" Commands:
|
||||
"
|
||||
" Those mappings correspond to two commands that you can use in your own
|
||||
" mappings:
|
||||
"
|
||||
" AddVimFootnote
|
||||
" ~ inserts footnotemark at cursor location, inserts footnotemark on new
|
||||
" line at end of file, opens a split window all ready for you to enter in
|
||||
" the footnote.
|
||||
|
||||
" ReturnFromFootnote
|
||||
" ~ closes the split window and returns to the text in proper place.
|
||||
"
|
||||
" These are mapped to <Leader>f and <Leader>r respectively.
|
||||
"
|
||||
" FootnoteNumber
|
||||
" ~ Change the current footnote number (one obligatory argument)
|
||||
" :FootnoteNumber 5
|
||||
"
|
||||
" FootnoteNumberRestore
|
||||
" ~ Restore old footnote number
|
||||
|
||||
" FootnoteUndo
|
||||
" ~ Decrease footnote counter by 1
|
||||
"
|
||||
" FootnoteMeta
|
||||
" ~ Change type of the footnotes and restart counter (1, a, A, i, I, *)
|
||||
" :FootnoteMeta
|
||||
" If your previous footnote type was alpha, Alpha, roman, Roman or star
|
||||
" new type will be arabic.
|
||||
" If your previous footnote type was arabic new type will be alpha.
|
||||
" :FootnoteMeta name_of_the_type
|
||||
" Change footnote type to name_of_the_type. If name_of_the_type is the
|
||||
" same as your current footnote type nothing would be changed.
|
||||
" You can change your default type of footnote before inserting first
|
||||
" footnote.
|
||||
"
|
||||
" FootnoteRestore
|
||||
" ~ Restore previous footnote type and counter. Unfortunately there is no easy
|
||||
" way to sort footnotes at the end of file without handmade :!sort on marked
|
||||
" lines (it doesn't work for 'star' type).
|
||||
" :FootnoteRestore
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
if exists("b:loaded_footnote_vim") | finish | endif
|
||||
let b:loaded_footnote_vim = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if !exists("g:vimfootnotetype")
|
||||
let g:vimfootnotetype = "arabic"
|
||||
endif
|
||||
if !exists("g:vimfootnotenumber")
|
||||
let g:vimfootnotenumber = 0
|
||||
endif
|
||||
|
||||
" Mappings
|
||||
if !hasmapto('<Plug>AddVimFootnote', 'i')
|
||||
imap <Leader>f <Plug>AddVimFootnote
|
||||
endif
|
||||
if !hasmapto('<Plug>AddVimFootnote', 'n')
|
||||
nmap <Leader>f <Plug>AddVimFootnote
|
||||
endif
|
||||
|
||||
if !hasmapto('<Plug>ReturnFromFootnote', 'i')
|
||||
imap <Leader>r <Plug>ReturnFromFootnote
|
||||
endif
|
||||
if !hasmapto('<Plug>ReturnFromFootnote', 'n')
|
||||
nmap <Leader>r <Plug>ReturnFromFootnote
|
||||
endif
|
||||
|
||||
nnoremap <Plug>AddVimFootnote :call <SID>VimFootnotes('a')<CR>
|
||||
inoremap <Plug>AddVimFootnote <C-O>:call <SID>VimFootnotes('a')<CR>
|
||||
|
||||
inoremap <Plug>ReturnFromFootnote <C-O>:q<CR><Right>
|
||||
noremap <Plug>ReturnFromFootnote :q<CR><Right>
|
||||
|
||||
" :Footnote commands
|
||||
command! -nargs=1 FootnoteNumber call <sid>VimFootnoteNumber(<q-args>)
|
||||
command! -nargs=0 FootnoteNumberRestore call <sid>VimFootnoteNumberRestore()
|
||||
command! -nargs=0 FootnoteUndo let g:vimfootnotenumber = g:vimfootnotenumber - 1
|
||||
command! -nargs=? FootnoteMeta call <sid>VimFootnoteMeta(<f-args>)
|
||||
command! -nargs=0 FootnoteRestore call <sid>VimFootnoteRestore()
|
||||
|
||||
function! s:VimFootnoteNumber(newnumber)
|
||||
let g:oldvimfootnotenumber = g:vimfootnotenumber
|
||||
let g:vimfootnotenumber = a:newnumber - 1
|
||||
endfunction
|
||||
|
||||
function! s:VimFootnoteNumberRestore()
|
||||
if exists(g:oldvimfootnotenumber)
|
||||
let g:vimfootnotenumber = g:oldvimfootnotenumber
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:VimFootnoteMeta(...)
|
||||
let g:oldvimfootnotetype = g:vimfootnotetype
|
||||
let g:oldvimfootnotenumber = g:vimfootnotenumber
|
||||
if a:0 == "0"
|
||||
if (g:vimfootnotetype == "arabic")
|
||||
let g:vimfootnotetype = "alpha"
|
||||
else
|
||||
let g:vimfootnotetype = "arabic"
|
||||
endif
|
||||
else
|
||||
if (a:1 == g:vimfootnotetype)
|
||||
echomsg "You have chosen the same footnote type! Command won't affect."
|
||||
return 0
|
||||
else
|
||||
let g:vimfootnotetype = a:1
|
||||
endif
|
||||
endif
|
||||
let g:vimfootnotenumber = 0
|
||||
endfunction
|
||||
|
||||
function! s:VimFootnoteRestore()
|
||||
if exists("g:oldvimfootnotenumber")
|
||||
let oldvimfootnotetype2 = g:vimfootnotetype
|
||||
let oldvimfootnotenumber2 = g:vimfootnotenumber
|
||||
let g:vimfootnotetype = g:oldvimfootnotetype
|
||||
let g:vimfootnotenumber = g:oldvimfootnotenumber
|
||||
let g:oldvimfootnotetype = oldvimfootnotetype2
|
||||
let g:oldvimfootnotenumber = oldvimfootnotenumber2
|
||||
else
|
||||
echomsg "You didn't change footnote type. Yet."
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:VimFootnoteType(footnumber)
|
||||
if (g:vimfootnotetype =~ "alpha\\|Alpha")
|
||||
if (g:vimfootnotetype == "alpha")
|
||||
let upper = "0"
|
||||
else
|
||||
let upper = "-32"
|
||||
endif
|
||||
if (a:footnumber <= 26)
|
||||
let ftnumber = nr2char(a:footnumber+96+upper)
|
||||
elseif (a:footnumber <= 52)
|
||||
let ftnumber = nr2char(a:footnumber+70+upper).nr2char(a:footnumber+70+upper)
|
||||
else
|
||||
let g:vimfootnotenumber = 1
|
||||
let ftnumber = nr2char(97+upper)
|
||||
endif
|
||||
elseif (g:vimfootnotetype == "star")
|
||||
let starnumber = 1
|
||||
let ftnumber = ""
|
||||
while (starnumber <= a:footnumber)
|
||||
let ftnumber = ftnumber . '*'
|
||||
let starnumber = starnumber + 1
|
||||
endwhile
|
||||
elseif (g:vimfootnotetype =~ "roman\\|Roman")
|
||||
let ftnumber = ""
|
||||
let oneroman = ""
|
||||
let counter = g:vimfootnotenumber
|
||||
if (counter >= 50)
|
||||
let ftnumber = "l"
|
||||
let counter = counter - 50
|
||||
endif
|
||||
if (counter > 39 && counter < 50)
|
||||
let ftnumber = "xl"
|
||||
let counter = counter - 40
|
||||
endif
|
||||
if (counter > 10)
|
||||
let tenmodulo = counter % 10
|
||||
let number_roman_ten = (counter - tenmodulo) / 10
|
||||
let romanten = 1
|
||||
while (romanten <= number_roman_ten)
|
||||
let ftnumber = ftnumber.'x'
|
||||
let romanten = romanten + 1
|
||||
endwhile
|
||||
elseif (counter == 10)
|
||||
let ftnumber = ftnumber.'x'
|
||||
let tenmodulo = ""
|
||||
else
|
||||
let tenmodulo = counter
|
||||
endif
|
||||
if (tenmodulo == 1)
|
||||
let oneroman = 'i'
|
||||
elseif (tenmodulo == 2)
|
||||
let oneroman = 'ii'
|
||||
elseif (tenmodulo == 3)
|
||||
let oneroman = 'iii'
|
||||
elseif (tenmodulo == 4)
|
||||
let oneroman = 'iv'
|
||||
elseif (tenmodulo == 5)
|
||||
let oneroman = 'v'
|
||||
elseif (tenmodulo == 6)
|
||||
let oneroman = 'vi'
|
||||
elseif (tenmodulo == 7)
|
||||
let oneroman = 'vii'
|
||||
elseif (tenmodulo == 8)
|
||||
let oneroman = 'viii'
|
||||
elseif (tenmodulo == 9)
|
||||
let oneroman = 'ix'
|
||||
elseif (tenmodulo == 0)
|
||||
let oneroman = ''
|
||||
endif
|
||||
let ftnumber = ftnumber . oneroman
|
||||
if (g:vimfootnotetype == "Roman")
|
||||
let ftnumber = substitute(ftnumber, ".*", "\\U\\0", "g")
|
||||
endif
|
||||
else
|
||||
let ftnumber = a:footnumber
|
||||
endif
|
||||
return ftnumber
|
||||
endfunction
|
||||
|
||||
function! s:VimFootnotes(appendcmd)
|
||||
if (g:vimfootnotenumber != 0)
|
||||
let g:vimfootnotenumber = g:vimfootnotenumber + 1
|
||||
let g:vimfootnotemark = <sid>VimFootnoteType(g:vimfootnotenumber)
|
||||
let cr = "\<cr>"
|
||||
else
|
||||
let g:vimfootnotenumber = 1
|
||||
let g:vimfootnotemark = <sid>VimFootnoteType(g:vimfootnotenumber)
|
||||
let cr = "\<cr>"
|
||||
endif
|
||||
exe "normal ".a:appendcmd."[^".g:vimfootnotemark."]\<esc>"
|
||||
:below 4split
|
||||
normal G
|
||||
exe "normal o".cr."[^".g:vimfootnotemark."]: "
|
||||
startinsert!
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
@@ -1,242 +0,0 @@
|
||||
" Query Command Complete
|
||||
" ======================
|
||||
"
|
||||
" Vim plugin to suggest completions with the results of an external
|
||||
" query command.
|
||||
"
|
||||
" The original intention is to use it as a mutt query_command wrapper
|
||||
" to complete addresses in the mail headers, but it can be adapted
|
||||
" to any other kind of functionality by modifying the exposed setting
|
||||
" parameters.
|
||||
"
|
||||
" Last Change: 2013 Jun 16
|
||||
" Author: Caio Romão (http://caioromao.com)
|
||||
" License: This file is placed in the public domain
|
||||
" Contributors:
|
||||
" Brian Henderson https://github.com/bhenderson
|
||||
" Mark Stillwell https://github.com/marklee77
|
||||
" Rui Abreu Ferreira http://ruiabreu.org
|
||||
"
|
||||
" Setup:
|
||||
" This plugin exports the completion function QueryCommandComplete,
|
||||
" which can be set as the complete function (or omni function) for
|
||||
" any filetype. If you have a working mutt setup with query_command
|
||||
" configured, the plugin works out of the box.
|
||||
"
|
||||
" Example:
|
||||
" let g:qcc_query_command='abook'
|
||||
" au BufRead /tmp/mutt* setlocal omnifunc=QueryCommandComplete
|
||||
"
|
||||
" Settings:
|
||||
" Note: Overriding settings on a buffer-basis is supported. So
|
||||
" b:qcc_query_command takes precedence over g:qcc_query_command
|
||||
"
|
||||
" g:qcc_query_command
|
||||
" External command that queries for contacts
|
||||
" If empty, QueryCommandComplete tries to guess what command to
|
||||
" run by executing `mutt -Q query_command`.
|
||||
"
|
||||
" g:qcc_line_separator
|
||||
" Separator for each entry in the result from the query
|
||||
" default: '\n'
|
||||
"
|
||||
" g:qcc_field_separator
|
||||
" Separator for the fields of an entry from the result
|
||||
" default: '\t'
|
||||
"
|
||||
" g:qcc_pattern
|
||||
" Pattern used to match against the current line to decide
|
||||
" whether to call the query command
|
||||
" default: '^\(To\|Cc\|Bcc\|From\|Reply-To\):'
|
||||
"
|
||||
" g:qcc_multiline
|
||||
" Whether to try matching g:qcc_pattern against the current
|
||||
" and any previous line
|
||||
" default: 0
|
||||
"
|
||||
" g:qcc_multiline_pattern
|
||||
" Pattern to match against the current line when deciding
|
||||
" wether to keep looking for a line that matches g:qcc_pattern
|
||||
" This provides finer control over the recursion, which
|
||||
" is useful if calling the completion on really big files.
|
||||
" default: '.*'
|
||||
"
|
||||
" g:qcc_format_word
|
||||
" Format string to be used when building the word field
|
||||
" of the completion (i.e.: the final result, what gets fed into
|
||||
" the current line when you select an option)
|
||||
" default: '${1} <${0}>' (as in: FirstName <email@domain.com>)
|
||||
"
|
||||
" g:qcc_format_abbr
|
||||
" Format string to be used when building the abbreviation
|
||||
" for the completion menu (i.e.: the first row in the completion
|
||||
" menu).
|
||||
" default: '${1}'
|
||||
"
|
||||
" g:qcc_format_menu
|
||||
" Format string for the optional second column of the completion
|
||||
" menu.
|
||||
" default: '${2}'
|
||||
"
|
||||
|
||||
|
||||
if exists("g:loaded_QueryCommandComplete") || &cp
|
||||
finish
|
||||
endif
|
||||
|
||||
function! s:GetSetting(name)
|
||||
let global_option = 'g:qcc_' . a:name
|
||||
let local_option = 'b:qcc_' . a:name
|
||||
|
||||
let result = ''
|
||||
if exists(local_option)
|
||||
let result = {local_option}
|
||||
elseif exists(global_option)
|
||||
let result = {global_option}
|
||||
endif
|
||||
|
||||
return result
|
||||
endfunction
|
||||
|
||||
let g:loaded_QueryCommandComplete = 1
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
function! s:DefaultIfUnset(name, default)
|
||||
if !exists(a:name)
|
||||
let {a:name} = a:default
|
||||
endif
|
||||
endfunction
|
||||
|
||||
call s:DefaultIfUnset('g:qcc_line_separator', '\n')
|
||||
call s:DefaultIfUnset('g:qcc_field_separator', '\t')
|
||||
call s:DefaultIfUnset('g:qcc_pattern', '^\(To\|Cc\|Bcc\|From\|Reply-To\):')
|
||||
call s:DefaultIfUnset('g:qcc_multiline', 0)
|
||||
call s:DefaultIfUnset('g:qcc_multiline_pattern', '.*')
|
||||
call s:DefaultIfUnset('g:qcc_format_word', '${1} <${0}>')
|
||||
call s:DefaultIfUnset('g:qcc_format_abbr', '${1} <${0}>')
|
||||
call s:DefaultIfUnset('g:qcc_format_menu', '${2}')
|
||||
|
||||
" Given a format string where the placeholders are in the format
|
||||
" '${index}' and index is a valid index the the given 'fields'
|
||||
" argument, this function returns a string with all placeholders
|
||||
" replaced by the corresponding data in the fields list.
|
||||
" FIXME I can't help but think there's a standard way to do this
|
||||
" but I failed finding it. Please call me a dumbass if you
|
||||
" know The Easy Way.
|
||||
function! s:ApplyFieldsToFormatString(fields, format)
|
||||
let result = a:format
|
||||
|
||||
while 1
|
||||
let placeholder = matchstr(result, '${[0-9]}')
|
||||
|
||||
if (empty(placeholder))
|
||||
break
|
||||
endif
|
||||
|
||||
let index = matchstr(placeholder, '[0-9]')
|
||||
|
||||
" If ${NUMBER} is not a valid index in a:fields,
|
||||
" use '' as a fallback.
|
||||
" FIXME Decide whether to warn/err/whatever here
|
||||
let content = ''
|
||||
if (len(a:fields) > index)
|
||||
let content = a:fields[index]
|
||||
endif
|
||||
|
||||
let result = substitute(result, placeholder, content, 'g')
|
||||
|
||||
endwhile
|
||||
|
||||
return result
|
||||
endfunction
|
||||
|
||||
function! s:MakeCompletionEntry(fields)
|
||||
let entry = {}
|
||||
let entry.word = s:ApplyFieldsToFormatString(a:fields, s:GetSetting('format_word'))
|
||||
let entry.abbr = s:ApplyFieldsToFormatString(a:fields, s:GetSetting('format_abbr'))
|
||||
let entry.menu = s:ApplyFieldsToFormatString(a:fields, s:GetSetting('format_menu'))
|
||||
let entry.icase = 1
|
||||
return entry
|
||||
endfunction
|
||||
|
||||
function! s:FindStartingIndex()
|
||||
let cur_line = getline('.')
|
||||
|
||||
" locate the start of the word
|
||||
let start = col('.') - 1
|
||||
while start > 0 && cur_line[start - 1] =~ '[^:,]'
|
||||
let start -= 1
|
||||
endwhile
|
||||
|
||||
" lstrip()
|
||||
while cur_line[start] =~ '[ ]'
|
||||
let start += 1
|
||||
endwhile
|
||||
|
||||
return start
|
||||
endfunction
|
||||
|
||||
function! s:GenerateCompletions(findstart, base)
|
||||
if a:findstart
|
||||
return s:FindStartingIndex()
|
||||
endif
|
||||
|
||||
let results = []
|
||||
let cmd = s:GetSetting('query_command')
|
||||
if cmd !~ '%s'
|
||||
let cmd .= ' %s'
|
||||
endif
|
||||
let cmd = substitute(cmd, '%s', shellescape(a:base), '')
|
||||
let lines = split(system(cmd), g:qcc_line_separator)
|
||||
|
||||
for my_line in lines
|
||||
let fields = split(my_line, g:qcc_field_separator)
|
||||
|
||||
let entry = s:MakeCompletionEntry(fields)
|
||||
|
||||
call add(results, entry)
|
||||
endfor
|
||||
|
||||
return results
|
||||
endfunction
|
||||
|
||||
function! s:ShouldGenerateCompletions(line_number)
|
||||
let current_line = getline(a:line_number)
|
||||
|
||||
if current_line =~ g:qcc_pattern
|
||||
return 1
|
||||
endif
|
||||
|
||||
if ! g:qcc_multiline || a:line_number <= 1 || current_line !~ g:qcc_multiline_pattern
|
||||
return 0
|
||||
endif
|
||||
|
||||
return s:ShouldGenerateCompletions(a:line_number - 1)
|
||||
endfunction
|
||||
|
||||
function! s:CheckSettings()
|
||||
" Try to use mutt's query_command by default if nothing is set
|
||||
if empty(s:GetSetting('query_command'))
|
||||
let s:querycmd = system('mutt -Q query_command 2>/dev/null')
|
||||
let s:querycmd = substitute(s:querycmd, '^query_command="\(.*\)"\n', '\1','')
|
||||
|
||||
if len(s:querycmd)
|
||||
let g:qcc_query_command = s:querycmd
|
||||
let g:qcc_multiline = 1
|
||||
autocmd FileType mail setlocal omnifunc=QueryCommandComplete
|
||||
else
|
||||
echoerr "QueryCommandComplete: g:qcc_query_command not set!"
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! QueryCommandComplete(findstart, base)
|
||||
if s:CheckSettings() && s:ShouldGenerateCompletions(line('.'))
|
||||
return s:GenerateCompletions(a:findstart, a:base)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
@@ -1,593 +0,0 @@
|
||||
" surround.vim - Surroundings
|
||||
" Author: Tim Pope <http://tpo.pe/>
|
||||
" Version: 2.1
|
||||
" GetLatestVimScripts: 1697 1 :AutoInstall: surround.vim
|
||||
|
||||
if exists("g:loaded_surround") || &cp || v:version < 700
|
||||
finish
|
||||
endif
|
||||
let g:loaded_surround = 1
|
||||
|
||||
" Input functions {{{1
|
||||
|
||||
function! s:getchar()
|
||||
let c = getchar()
|
||||
if c =~ '^\d\+$'
|
||||
let c = nr2char(c)
|
||||
endif
|
||||
return c
|
||||
endfunction
|
||||
|
||||
function! s:inputtarget()
|
||||
let c = s:getchar()
|
||||
while c =~ '^\d\+$'
|
||||
let c .= s:getchar()
|
||||
endwhile
|
||||
if c == " "
|
||||
let c .= s:getchar()
|
||||
endif
|
||||
if c =~ "\<Esc>\|\<C-C>\|\0"
|
||||
return ""
|
||||
else
|
||||
return c
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:inputreplacement()
|
||||
let c = s:getchar()
|
||||
if c == " "
|
||||
let c .= s:getchar()
|
||||
endif
|
||||
if c =~ "\<Esc>" || c =~ "\<C-C>"
|
||||
return ""
|
||||
else
|
||||
return c
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:beep()
|
||||
exe "norm! \<Esc>"
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
function! s:redraw()
|
||||
redraw
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
" Wrapping functions {{{1
|
||||
|
||||
function! s:extractbefore(str)
|
||||
if a:str =~ '\r'
|
||||
return matchstr(a:str,'.*\ze\r')
|
||||
else
|
||||
return matchstr(a:str,'.*\ze\n')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:extractafter(str)
|
||||
if a:str =~ '\r'
|
||||
return matchstr(a:str,'\r\zs.*')
|
||||
else
|
||||
return matchstr(a:str,'\n\zs.*')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:fixindent(str,spc)
|
||||
let str = substitute(a:str,'\t',repeat(' ',&sw),'g')
|
||||
let spc = substitute(a:spc,'\t',repeat(' ',&sw),'g')
|
||||
let str = substitute(str,'\(\n\|\%^\).\@=','\1'.spc,'g')
|
||||
if ! &et
|
||||
let str = substitute(str,'\s\{'.&ts.'\}',"\t",'g')
|
||||
endif
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! s:process(string)
|
||||
let i = 0
|
||||
for i in range(7)
|
||||
let repl_{i} = ''
|
||||
let m = matchstr(a:string,nr2char(i).'.\{-\}\ze'.nr2char(i))
|
||||
if m != ''
|
||||
let m = substitute(strpart(m,1),'\r.*','','')
|
||||
let repl_{i} = input(substitute(m,':\s*$','','').': ')
|
||||
endif
|
||||
endfor
|
||||
let s = ""
|
||||
let i = 0
|
||||
while i < strlen(a:string)
|
||||
let char = strpart(a:string,i,1)
|
||||
if char2nr(char) < 8
|
||||
let next = stridx(a:string,char,i+1)
|
||||
if next == -1
|
||||
let s .= char
|
||||
else
|
||||
let insertion = repl_{char2nr(char)}
|
||||
let subs = strpart(a:string,i+1,next-i-1)
|
||||
let subs = matchstr(subs,'\r.*')
|
||||
while subs =~ '^\r.*\r'
|
||||
let sub = matchstr(subs,"^\r\\zs[^\r]*\r[^\r]*")
|
||||
let subs = strpart(subs,strlen(sub)+1)
|
||||
let r = stridx(sub,"\r")
|
||||
let insertion = substitute(insertion,strpart(sub,0,r),strpart(sub,r+1),'')
|
||||
endwhile
|
||||
let s .= insertion
|
||||
let i = next
|
||||
endif
|
||||
else
|
||||
let s .= char
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
return s
|
||||
endfunction
|
||||
|
||||
function! s:wrap(string,char,type,...)
|
||||
let keeper = a:string
|
||||
let newchar = a:char
|
||||
let s:input = ""
|
||||
let type = a:type
|
||||
let linemode = type ==# 'V' ? 1 : 0
|
||||
let special = a:0 ? a:1 : 0
|
||||
let before = ""
|
||||
let after = ""
|
||||
if type ==# "V"
|
||||
let initspaces = matchstr(keeper,'\%^\s*')
|
||||
else
|
||||
let initspaces = matchstr(getline('.'),'\%^\s*')
|
||||
endif
|
||||
let pairs = "b()B{}r[]a<>"
|
||||
let extraspace = ""
|
||||
if newchar =~ '^ '
|
||||
let newchar = strpart(newchar,1)
|
||||
let extraspace = ' '
|
||||
endif
|
||||
let idx = stridx(pairs,newchar)
|
||||
if newchar == ' '
|
||||
let before = ''
|
||||
let after = ''
|
||||
elseif exists("b:surround_".char2nr(newchar))
|
||||
let all = s:process(b:surround_{char2nr(newchar)})
|
||||
let before = s:extractbefore(all)
|
||||
let after = s:extractafter(all)
|
||||
elseif exists("g:surround_".char2nr(newchar))
|
||||
let all = s:process(g:surround_{char2nr(newchar)})
|
||||
let before = s:extractbefore(all)
|
||||
let after = s:extractafter(all)
|
||||
elseif newchar ==# "p"
|
||||
let before = "\n"
|
||||
let after = "\n\n"
|
||||
elseif newchar ==# 's'
|
||||
let before = ' '
|
||||
let after = ''
|
||||
elseif newchar ==# ':'
|
||||
let before = ':'
|
||||
let after = ''
|
||||
elseif newchar =~# "[tT\<C-T><,]"
|
||||
let dounmapp = 0
|
||||
let dounmapb = 0
|
||||
if !maparg(">","c")
|
||||
let dounmapb = 1
|
||||
" Hide from AsNeeded
|
||||
exe "cn"."oremap > <CR>"
|
||||
endif
|
||||
let default = ""
|
||||
if newchar ==# "T"
|
||||
if !exists("s:lastdel")
|
||||
let s:lastdel = ""
|
||||
endif
|
||||
let default = matchstr(s:lastdel,'<\zs.\{-\}\ze>')
|
||||
endif
|
||||
let tag = input("<",default)
|
||||
echo "<".substitute(tag,'>*$','>','')
|
||||
if dounmapb
|
||||
silent! cunmap >
|
||||
endif
|
||||
let s:input = tag
|
||||
if tag != ""
|
||||
let tag = substitute(tag,'>*$','','')
|
||||
let s:input = tag . '>'
|
||||
let before = '<'.tag.'>'
|
||||
if tag =~ '/$'
|
||||
let after = ''
|
||||
else
|
||||
let after = '</'.substitute(tag,' .*','','').'>'
|
||||
endif
|
||||
if newchar == "\<C-T>" || newchar == ","
|
||||
if type ==# "v" || type ==# "V"
|
||||
let before .= "\n\t"
|
||||
endif
|
||||
if type ==# "v"
|
||||
let after = "\n". after
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
elseif newchar ==# 'l' || newchar == '\'
|
||||
" LaTeX
|
||||
let env = input('\begin{')
|
||||
let env = '{' . env
|
||||
let env .= s:closematch(env)
|
||||
echo '\begin'.env
|
||||
if env != ""
|
||||
let before = '\begin'.env
|
||||
let after = '\end'.matchstr(env,'[^}]*').'}'
|
||||
endif
|
||||
elseif newchar ==# 'f' || newchar ==# 'F'
|
||||
let fnc = input('function: ')
|
||||
if fnc != ""
|
||||
let s:input = fnc."\<CR>"
|
||||
let before = substitute(fnc,'($','','').'('
|
||||
let after = ')'
|
||||
if newchar ==# 'F'
|
||||
let before .= ' '
|
||||
let after = ' ' . after
|
||||
endif
|
||||
endif
|
||||
elseif newchar ==# "\<C-F>"
|
||||
let fnc = input('function: ')
|
||||
let s:input = fnc."\<CR>"
|
||||
let before = '('.fnc.' '
|
||||
let after = ')'
|
||||
elseif idx >= 0
|
||||
let spc = (idx % 3) == 1 ? " " : ""
|
||||
let idx = idx / 3 * 3
|
||||
let before = strpart(pairs,idx+1,1) . spc
|
||||
let after = spc . strpart(pairs,idx+2,1)
|
||||
elseif newchar == "\<C-[>" || newchar == "\<C-]>"
|
||||
let before = "{\n\t"
|
||||
let after = "\n}"
|
||||
elseif newchar !~ '\a'
|
||||
let before = newchar
|
||||
let after = newchar
|
||||
else
|
||||
let before = ''
|
||||
let after = ''
|
||||
endif
|
||||
let after = substitute(after ,'\n','\n'.initspaces,'g')
|
||||
if type ==# 'V' || (special && type ==# "v")
|
||||
let before = substitute(before,' \+$','','')
|
||||
let after = substitute(after ,'^ \+','','')
|
||||
if after !~ '^\n'
|
||||
let after = initspaces.after
|
||||
endif
|
||||
if keeper !~ '\n$' && after !~ '^\n'
|
||||
let keeper .= "\n"
|
||||
elseif keeper =~ '\n$' && after =~ '^\n'
|
||||
let after = strpart(after,1)
|
||||
endif
|
||||
if before !~ '\n\s*$'
|
||||
let before .= "\n"
|
||||
if special
|
||||
let before .= "\t"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if type ==# 'V'
|
||||
let before = initspaces.before
|
||||
endif
|
||||
if before =~ '\n\s*\%$'
|
||||
if type ==# 'v'
|
||||
let keeper = initspaces.keeper
|
||||
endif
|
||||
let padding = matchstr(before,'\n\zs\s\+\%$')
|
||||
let before = substitute(before,'\n\s\+\%$','\n','')
|
||||
let keeper = s:fixindent(keeper,padding)
|
||||
endif
|
||||
if type ==# 'V'
|
||||
let keeper = before.keeper.after
|
||||
elseif type =~ "^\<C-V>"
|
||||
" Really we should be iterating over the buffer
|
||||
let repl = substitute(before,'[\\~]','\\&','g').'\1'.substitute(after,'[\\~]','\\&','g')
|
||||
let repl = substitute(repl,'\n',' ','g')
|
||||
let keeper = substitute(keeper."\n",'\(.\{-\}\)\(\n\)',repl.'\n','g')
|
||||
let keeper = substitute(keeper,'\n\%$','','')
|
||||
else
|
||||
let keeper = before.extraspace.keeper.extraspace.after
|
||||
endif
|
||||
return keeper
|
||||
endfunction
|
||||
|
||||
function! s:wrapreg(reg,char,...)
|
||||
let orig = getreg(a:reg)
|
||||
let type = substitute(getregtype(a:reg),'\d\+$','','')
|
||||
let special = a:0 ? a:1 : 0
|
||||
let new = s:wrap(orig,a:char,type,special)
|
||||
call setreg(a:reg,new,type)
|
||||
endfunction
|
||||
" }}}1
|
||||
|
||||
function! s:insert(...) " {{{1
|
||||
" Optional argument causes the result to appear on 3 lines, not 1
|
||||
let linemode = a:0 ? a:1 : 0
|
||||
let char = s:inputreplacement()
|
||||
while char == "\<CR>" || char == "\<C-S>"
|
||||
" TODO: use total count for additional blank lines
|
||||
let linemode += 1
|
||||
let char = s:inputreplacement()
|
||||
endwhile
|
||||
if char == ""
|
||||
return ""
|
||||
endif
|
||||
let cb_save = &clipboard
|
||||
set clipboard-=unnamed clipboard-=unnamedplus
|
||||
let reg_save = @@
|
||||
call setreg('"',"\r",'v')
|
||||
call s:wrapreg('"',char,linemode)
|
||||
" If line mode is used and the surrounding consists solely of a suffix,
|
||||
" remove the initial newline. This fits a use case of mine but is a
|
||||
" little inconsistent. Is there anyone that would prefer the simpler
|
||||
" behavior of just inserting the newline?
|
||||
if linemode && match(getreg('"'),'^\n\s*\zs.*') == 0
|
||||
call setreg('"',matchstr(getreg('"'),'^\n\s*\zs.*'),getregtype('"'))
|
||||
endif
|
||||
" This can be used to append a placeholder to the end
|
||||
if exists("g:surround_insert_tail")
|
||||
call setreg('"',g:surround_insert_tail,"a".getregtype('"'))
|
||||
endif
|
||||
if col('.') >= col('$')
|
||||
norm! ""p
|
||||
else
|
||||
norm! ""P
|
||||
endif
|
||||
if linemode
|
||||
call s:reindent()
|
||||
endif
|
||||
norm! `]
|
||||
call search('\r','bW')
|
||||
let @@ = reg_save
|
||||
let &clipboard = cb_save
|
||||
return "\<Del>"
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:reindent() " {{{1
|
||||
if exists("b:surround_indent") ? b:surround_indent : (!exists("g:surround_indent") || g:surround_indent)
|
||||
silent norm! '[=']
|
||||
endif
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:dosurround(...) " {{{1
|
||||
let scount = v:count1
|
||||
let char = (a:0 ? a:1 : s:inputtarget())
|
||||
let spc = ""
|
||||
if char =~ '^\d\+'
|
||||
let scount = scount * matchstr(char,'^\d\+')
|
||||
let char = substitute(char,'^\d\+','','')
|
||||
endif
|
||||
if char =~ '^ '
|
||||
let char = strpart(char,1)
|
||||
let spc = 1
|
||||
endif
|
||||
if char == 'a'
|
||||
let char = '>'
|
||||
endif
|
||||
if char == 'r'
|
||||
let char = ']'
|
||||
endif
|
||||
let newchar = ""
|
||||
if a:0 > 1
|
||||
let newchar = a:2
|
||||
if newchar == "\<Esc>" || newchar == "\<C-C>" || newchar == ""
|
||||
return s:beep()
|
||||
endif
|
||||
endif
|
||||
let cb_save = &clipboard
|
||||
set clipboard-=unnamed clipboard-=unnamedplus
|
||||
let append = ""
|
||||
let original = getreg('"')
|
||||
let otype = getregtype('"')
|
||||
call setreg('"',"")
|
||||
let strcount = (scount == 1 ? "" : scount)
|
||||
if char == '/'
|
||||
exe 'norm! '.strcount.'[/d'.strcount.']/'
|
||||
elseif char =~# '[[:punct:]]' && char !~# '[][(){}<>"''`]'
|
||||
exe 'norm! T'.char
|
||||
if getline('.')[col('.')-1] == char
|
||||
exe 'norm! l'
|
||||
endif
|
||||
exe 'norm! dt'.char
|
||||
else
|
||||
exe 'norm! d'.strcount.'i'.char
|
||||
endif
|
||||
let keeper = getreg('"')
|
||||
let okeeper = keeper " for reindent below
|
||||
if keeper == ""
|
||||
call setreg('"',original,otype)
|
||||
let &clipboard = cb_save
|
||||
return ""
|
||||
endif
|
||||
let oldline = getline('.')
|
||||
let oldlnum = line('.')
|
||||
if char ==# "p"
|
||||
call setreg('"','','V')
|
||||
elseif char ==# "s" || char ==# "w" || char ==# "W"
|
||||
" Do nothing
|
||||
call setreg('"','')
|
||||
elseif char =~ "[\"'`]"
|
||||
exe "norm! i \<Esc>d2i".char
|
||||
call setreg('"',substitute(getreg('"'),' ','',''))
|
||||
elseif char == '/'
|
||||
norm! "_x
|
||||
call setreg('"','/**/',"c")
|
||||
let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
|
||||
elseif char =~# '[[:punct:]]' && char !~# '[][(){}<>]'
|
||||
exe 'norm! F'.char
|
||||
exe 'norm! df'.char
|
||||
else
|
||||
" One character backwards
|
||||
call search('\m.', 'bW')
|
||||
exe "norm! da".char
|
||||
endif
|
||||
let removed = getreg('"')
|
||||
let rem2 = substitute(removed,'\n.*','','')
|
||||
let oldhead = strpart(oldline,0,strlen(oldline)-strlen(rem2))
|
||||
let oldtail = strpart(oldline, strlen(oldline)-strlen(rem2))
|
||||
let regtype = getregtype('"')
|
||||
if char =~# '[\[({<T]' || spc
|
||||
let keeper = substitute(keeper,'^\s\+','','')
|
||||
let keeper = substitute(keeper,'\s\+$','','')
|
||||
endif
|
||||
if col("']") == col("$") && col('.') + 1 == col('$')
|
||||
if oldhead =~# '^\s*$' && a:0 < 2
|
||||
let keeper = substitute(keeper,'\%^\n'.oldhead.'\(\s*.\{-\}\)\n\s*\%$','\1','')
|
||||
endif
|
||||
let pcmd = "p"
|
||||
else
|
||||
let pcmd = "P"
|
||||
endif
|
||||
if line('.') + 1 < oldlnum && regtype ==# "V"
|
||||
let pcmd = "p"
|
||||
endif
|
||||
call setreg('"',keeper,regtype)
|
||||
if newchar != ""
|
||||
let special = a:0 > 2 ? a:3 : 0
|
||||
call s:wrapreg('"',newchar, special)
|
||||
endif
|
||||
silent exe 'norm! ""'.pcmd.'`['
|
||||
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
|
||||
call s:reindent()
|
||||
endif
|
||||
if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
|
||||
silent norm! cc
|
||||
endif
|
||||
call setreg('"',original,otype)
|
||||
let s:lastdel = removed
|
||||
let &clipboard = cb_save
|
||||
if newchar == ""
|
||||
silent! call repeat#set("\<Plug>Dsurround".char,scount)
|
||||
else
|
||||
silent! call repeat#set("\<Plug>C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:input,scount)
|
||||
endif
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:changesurround(...) " {{{1
|
||||
let a = s:inputtarget()
|
||||
if a == ""
|
||||
return s:beep()
|
||||
endif
|
||||
let b = s:inputreplacement()
|
||||
if b == ""
|
||||
return s:beep()
|
||||
endif
|
||||
call s:dosurround(a,b,a:0 && a:1)
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:opfunc(type,...) " {{{1
|
||||
let char = s:inputreplacement()
|
||||
if char == ""
|
||||
return s:beep()
|
||||
endif
|
||||
let reg = '"'
|
||||
let sel_save = &selection
|
||||
let &selection = "inclusive"
|
||||
let cb_save = &clipboard
|
||||
set clipboard-=unnamed clipboard-=unnamedplus
|
||||
let reg_save = getreg(reg)
|
||||
let reg_type = getregtype(reg)
|
||||
let type = a:type
|
||||
if a:type == "char"
|
||||
silent exe 'norm! v`[o`]"'.reg.'y'
|
||||
let type = 'v'
|
||||
elseif a:type == "line"
|
||||
silent exe 'norm! `[V`]"'.reg.'y'
|
||||
let type = 'V'
|
||||
elseif a:type ==# "v" || a:type ==# "V" || a:type ==# "\<C-V>"
|
||||
let &selection = sel_save
|
||||
let ve = &virtualedit
|
||||
if !(a:0 && a:1)
|
||||
set virtualedit=
|
||||
endif
|
||||
silent exe 'norm! gv"'.reg.'y'
|
||||
let &virtualedit = ve
|
||||
elseif a:type =~ '^\d\+$'
|
||||
let type = 'v'
|
||||
silent exe 'norm! ^v'.a:type.'$h"'.reg.'y'
|
||||
if mode() ==# 'v'
|
||||
norm! v
|
||||
return s:beep()
|
||||
endif
|
||||
else
|
||||
let &selection = sel_save
|
||||
let &clipboard = cb_save
|
||||
return s:beep()
|
||||
endif
|
||||
let keeper = getreg(reg)
|
||||
if type ==# "v" && a:type !=# "v"
|
||||
let append = matchstr(keeper,'\_s\@<!\s*$')
|
||||
let keeper = substitute(keeper,'\_s\@<!\s*$','','')
|
||||
endif
|
||||
call setreg(reg,keeper,type)
|
||||
call s:wrapreg(reg,char,a:0 && a:1)
|
||||
if type ==# "v" && a:type !=# "v" && append != ""
|
||||
call setreg(reg,append,"ac")
|
||||
endif
|
||||
silent exe 'norm! gv'.(reg == '"' ? '' : '"' . reg).'p`['
|
||||
if type ==# 'V' || (getreg(reg) =~ '\n' && type ==# 'v')
|
||||
call s:reindent()
|
||||
endif
|
||||
call setreg(reg,reg_save,reg_type)
|
||||
let &selection = sel_save
|
||||
let &clipboard = cb_save
|
||||
if a:type =~ '^\d\+$'
|
||||
silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char.s:input,a:type)
|
||||
else
|
||||
silent! call repeat#set("\<Plug>SurroundRepeat".char.s:input)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:opfunc2(arg)
|
||||
call s:opfunc(a:arg,1)
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:closematch(str) " {{{1
|
||||
" Close an open (, {, [, or < on the command line.
|
||||
let tail = matchstr(a:str,'.[^\[\](){}<>]*$')
|
||||
if tail =~ '^\[.\+'
|
||||
return "]"
|
||||
elseif tail =~ '^(.\+'
|
||||
return ")"
|
||||
elseif tail =~ '^{.\+'
|
||||
return "}"
|
||||
elseif tail =~ '^<.+'
|
||||
return ">"
|
||||
else
|
||||
return ""
|
||||
endif
|
||||
endfunction " }}}1
|
||||
|
||||
nnoremap <silent> <Plug>SurroundRepeat .
|
||||
nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
|
||||
nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR>
|
||||
nnoremap <silent> <Plug>CSurround :<C-U>call <SID>changesurround(1)<CR>
|
||||
nnoremap <silent> <Plug>Yssurround :<C-U>call <SID>opfunc(v:count1)<CR>
|
||||
nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR>
|
||||
" <C-U> discards the numerical argument but there's not much we can do with it
|
||||
nnoremap <silent> <Plug>Ysurround :<C-U>set opfunc=<SID>opfunc<CR>g@
|
||||
nnoremap <silent> <Plug>YSurround :<C-U>set opfunc=<SID>opfunc2<CR>g@
|
||||
vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
|
||||
vnoremap <silent> <Plug>VgSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1)<CR>
|
||||
inoremap <silent> <Plug>Isurround <C-R>=<SID>insert()<CR>
|
||||
inoremap <silent> <Plug>ISurround <C-R>=<SID>insert(1)<CR>
|
||||
|
||||
if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
|
||||
nmap ds <Plug>Dsurround
|
||||
nmap cs <Plug>Csurround
|
||||
nmap cS <Plug>CSurround
|
||||
nmap ys <Plug>Ysurround
|
||||
nmap yS <Plug>YSurround
|
||||
nmap yss <Plug>Yssurround
|
||||
nmap ySs <Plug>YSsurround
|
||||
nmap ySS <Plug>YSsurround
|
||||
xmap S <Plug>VSurround
|
||||
xmap gS <Plug>VgSurround
|
||||
if !exists("g:surround_no_insert_mappings") || ! g:surround_no_insert_mappings
|
||||
if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
|
||||
imap <C-S> <Plug>Isurround
|
||||
endif
|
||||
imap <C-G>s <Plug>Isurround
|
||||
imap <C-G>S <Plug>ISurround
|
||||
endif
|
||||
endif
|
||||
|
||||
" vim:set ft=vim sw=2 sts=2 et:
|
||||
Binary file not shown.
37
vim/.vimrc
37
vim/.vimrc
@@ -1,37 +0,0 @@
|
||||
syn on
|
||||
" Enable Ctrl+Backspace deleting the last word
|
||||
imap <C-BS> <C-W>
|
||||
set backspace=indent,eol,start " more powerful backspacing
|
||||
|
||||
set nocompatible " no vi compatible, seems to be good
|
||||
set expandtab " covert TAB to spaces
|
||||
set shiftwidth=2 " width of tabs
|
||||
set softtabstop=2 " width of tabs
|
||||
|
||||
" Ctrl copy/cut paste behaviour
|
||||
vmap <C-c> "+yi
|
||||
vmap <C-x> "+c
|
||||
vmap <C-v> c<ESC>"+p
|
||||
imap <C-v> <C-r><C-o>+
|
||||
|
||||
" Reformat shortcuts
|
||||
nmap <F1> gqap " wrap paragraph
|
||||
map! <F1> <ESC>gqapi
|
||||
nmap <F5> vipJ " unwrap paragraph
|
||||
map! <F5> <ESC>vipJi
|
||||
"nmap <F3> kgqj " merge the previous line with the current one, with a correct formatting
|
||||
"map! <F3> <ESC>kgqji
|
||||
|
||||
" Arrow left moves up line when at position 0
|
||||
set whichwrap+=<,>,[,]
|
||||
|
||||
|
||||
" ASTROID
|
||||
autocmd BufRead /home/max/.cache/astroid/* :source ~/.vim/astroid.vim
|
||||
|
||||
" Thunderbird
|
||||
autocmd BufRead /tmp/*.eml :source ~/.vim/mail.vim
|
||||
|
||||
" textern (Firefox Addon)
|
||||
autocmd BufRead /*/textern/textern* :source ~/.vim/mail.vim
|
||||
autocmd BufRead /*/textern*/*.txt :source ~/.vim/mail.vim
|
||||
Reference in New Issue
Block a user