tyru / caw.vim Goto Github PK
View Code? Open in Web Editor NEWVim comment plugin: supported operator/non-operator mappings, repeatable by dot-command, 300+ filetypes
Vim comment plugin: supported operator/non-operator mappings, repeatable by dot-command, 300+ filetypes
gcc
operates on current line.
But I want current new mappings (comment, uncomment, toggle) that operates on current comment block.
A new mapping of uncomment or toggle uncomment comment block when the cursor is on any line of the following text.
# foo
# bar
# baz
ref. #2
https://github.com/tyru/caw.vim/issues?q=is%3Aissue+is%3Aopen+label%3Arelease%2F1.1
ref #26
Currently hatpos keymappings are linewise.
They should work also characterwise-ly.
I think this should be controllable by global variable.
Because some users don't like this behavior.
(however it should be enabled by default)
Add a new mapping gc$
and separate with gci
.
|
is cursor.
int foo |= 1;
to
int foo // = 1;
This won't be supported. Because it complicates uncomment behavior such as printf("// comment");
.
In comment and while normal-mode:
int foo // = 1;
to
int foo = 1;
コメントアウトやコメントトグルする operator が欲しいです!
具体的に、新しいプラグインに実装するのは次のようなもの。
新しい機能としては
Given a single-file vue component, like test.vue
When I comment code in the script or style portion of the file
I expect //
comments but I get <!-- -->
html comments.
すいません、確かな再現方法がいまいちわかっていないのですが、最近からバッファを閉じたときに次のようなエラーがでる時があります。
function 23_LoadFTPlugin の処理中にエラーが検出されました:
行 2:
E108: その変数はありません: "b:caw_wrap_oneline_comment"
<SNR>23
が指すのは $VIMRUNTIME/ftplugin.vim
で、 s:LoadFTPlugin()
の冒頭は
func! s:LoadFTPlugin()
if exists("b:undo_ftplugin")
exe b:undo_ftplugin
unlet! b:undo_ftplugin b:did_ftplugin
endif
なので、 b:undo_ftplugin
の内容に関係しそうです。help を引いてそのウィンドウを閉じたときに多いような気がします。
After uncommenting a block containing empty lines, white spaces will occur.
NVIM v0.3.1
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20181019-50893-1j0fv9i/neovim-0.3.1/build/config -I/tmp/neovim-20181019-50893-1j0fv9i/neovim-0.3.1/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/tmp/neovim-20181019-50893-1j0fv9i/neovim-0.3.1/build/src/nvim/auto -I/tmp/neovim-20181019-50893-1j0fv9i/neovim-0.3.1/build/include
Compiled by [email protected]
Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/local/Cellar/neovim/0.3.1/share/nvim"
Run :checkhealth for more info
When uncommenting XML/HTML elements, caw does not restore the previous (and preserved in commented state) indentation but instead pulls all attributes to the root indent level. This cannot be expected behavior.
Additionally, wrapping comment tags appear to require the use of gcw
and gcuw
which I feel is rather clumsy. I'd expect gcc
with selected lines to do the same. However, with JSP files for example, this does not even attempt to comment correctly but just uses the C default //
instead. It took me quite a while to figure out why.
The commenting below is within JSP files. However, even an HTML filetype does not change this behavior.
<div>
<picture>
<source
media="(min-width: 1200px)"
srcset="img.png, img.png@2x 2x"
/>
<img src="img.png" alt="image" class="image" />
</picture>
</div>
<%-- <div> --%>
<%-- <picture> --%>
<%-- <source --%>
<%-- media="(min-width: 1200px)" --%>
<%-- srcset="img.png, img.png@2x 2x" --%>
<%-- /> --%>
<%-- <img src="img.png" alt="image" class="image" /> --%>
<%-- </picture> --%>
<%-- </div> --%>
<div>
<picture>
<source
media="(min-width: 1200px)"
srcset="img.png, img.png@2x 2x"
/>
<img src="img.png" alt="image" class="image" />
</picture>
</div>
it is not necessary to initialize global variables.
plugin/caw.vim
manually like :runtime! plugin/caw.vim
.Toggle a position of comment string in previous line, next line, after current line.
After current line:
hello " :-)
Previous line:
" :-)
hello
Next line:
hello
" :-)
.
でコメントアウト操作を繰り返したいです。
caw.vim/autoload/caw.vim
368行目に以下の様にhaskellは'--'でコメントアウトする、と追加すると
haskellで動くようになりました。
autoload/caw.vim- \ 'h': '//',
autoload/caw.vim: \ 'haskell': '--',
autoload/caw.vim- \ 'haml': '-#',
例えば以下のようなコードがあった場合、
" test1
call s:test1()
" test2
call s:test2()
この範囲をトグルすると以下のようになります。
test1
call s:test1()
test2
call s:test2()
この挙動は明らかに不便なので混じっている場合は一括でコメントアウトした方がいいかと思うのですが、どうでしょう。
b:caw_oneline_comment
b:caw_wrap_oneline_comment
b:caw_wrap_multiline_comment
s:comments.oneline.get_comment_builtin()
s:comments.wrap_oneline.get_comment_builtin()
s:comments.wrap_multiline.get_comment_builtin()
Is it possible to support motion commands when commenting? Specifically, I wish to do 5gcc
to toggle comments on the next five lines. This is a feature I sorely miss from NerdCommenter My current alternative is to visually select the 5 lines, then gcc
to comment them out; this is much slower however.
Thanks!
http://twitter.com/thinca/status/59298483198361601
@tyru caw.vim で、空行を含むコメント行の範囲を toggle するとさらにコメントアウトされてしまいます。
http://twitter.com/tyru/status/59299252869939200
@thinca 空行以外で選択されてる範囲がコメントアウトされちゃうってことですか?それだとしたらfiletype=vimで再現しないです。filetypeを教えてくれますか?
http://twitter.com/thinca/status/59299553660243968
@tyru vim で再現しています。空行を含む範囲を2回toggleすれば再現するはずです。
Type "rotate" mapping to change comment type quickly.
In filetype=c, "rotate" mapping rotates the following comment types (including no comment string?)
// comment
/* comment */
/*
* comment
*/
:help caw-introduction
and README.mdThe plugin can wrap some of a line from visual mode but can't uncomment it.
In wrap comment:
<!-- foo -->
<!-- bar -->
<!-- loooooong -->
uncomment on loooooong
line:
<!-- foo -->
<!-- bar -->
loooooong line
wrap comments of foo
and bar
are aligned automatically.
ref. #5
Current chaotic objects in one script file (autoload/caw.vim
) style is horrible and difficult to add new features / fix bugs.
s:comments
s:caw.xxx
In a file whose filetype
is javascript
, Caw.vim uses JavaScript's style comment always.
But if the JavaScript file contains the JSX's style code snippets, then it must be distinguished between the JavaScript code and the JSX one to comment out. The examples are as follows.
Uncommented:
const foo = 'this is js style';
const bar = (
<h1>this is jsx style</h1>
);
Commented:
/* const foo = 'this is js style'; */
const bar = (
{/* <h1>this is jsx style</h1> */}
);
or
// const foo = 'this is js style';
const bar = (
{
// <h1>this is jsx style</h1>
}
);
It is the same as the TSX (JSX in TypeScript).
Thanks!
When <Plug>(caw:zeropos:toggle)
was executed on a buffer of ft=vim, vim showed the following error.
[Vim(let):E704: Funcref variable name must start with a capital: caw_zeropos_sp]:
:[function caw#keymapping_stub[48]..15[7]..11[3]..6, line 3]
vim -u vimrc -N
(the vimrc
is attached below):e some_vim_file.vim
gcc
in a lineThe vimrc used in the above steps is the following:
language C
set runtimepath+=~/.vim/bundle/vim-operator-user/
set runtimepath+=~/.vim/bundle/caw.vim/
set runtimepath+=~/.vim/bundle/caw.vim/after/
filetype plugin indent on
let g:caw_operator_keymappings = 1
nmap gcc <Plug>(caw:zeropos:toggle)
The error causes after dedb063
Align dollarpos comments after executing <Plug>(caw:dollarpos:comment)
for multiple lines.
g:caw_dollarpos_align
g:caw_dollarpos_align
This problem should be fixed in HEAD. keeping this issue open for announce purpose.
I mistakenly git-commit
-ed both i.vim
and I.vim
.
This results in the following error on filesystems that ignores filename cases like NTFS, HFS+:
[Vim(source):E484: ファイル "..../autoload/caw/actions/i.vim" を開けません]::[function caw#keymapping_stub[21]..caw#new, 行 8]
If you see a message like above, please get a caw.vim source code from this repository again.
git clone https://github.com/tyru/caw.vim
最新(master)の caw で、gco/gcO が使えなくなっていることに気付きました。
調べてみたところ、caw#keymapping_stub() において、s:caw.jump に comment_database が設定されていないために action が call() されないようになっています。
how to reproduce:
select visually the body of the function, gcc
, select it again an gcc
.
def test():
pass
____
pass
Not prepare some fixed action.
caw.vim becomes more flexible.
On filetype=lisp
;; (print 'hi)
-> <Plug>(caw:i:toggle)
-> ; (print 'hi)
-> <Plug>(caw:i:toggle)
-> (print 'hi)
;; (print 'hi)
-> <Plug>(caw:i:toggle)
-> (print 'hi)
filetype=zsh で確認。
fooooooooooooooooooooooo
bar
こんなテキストがあった場合に、この範囲を toggle すると、
# fooooooooooooooooooooooo_
# bar______________________
こうなります(_ は空白)。
もう一度 toggle すると末尾の空白も消えて元に戻ります。
I just noticed a very tiny thing: in autoload/caw.vim
, there is
\ 'haskell': '--',
\ 'haml': '-#',
but ha-M lies before ha-S, so the proper order is haml
then haskell
.
「<Tab>foo」という行があったとしたら、
「# <Tab>foo」ではなく「#<Tab>foo」になってほしい
(g:caw_sp_i
を無視してほしい)
via #42
(#42 is PR, but I changed this repository's branch policy in #53 and deprecate release branch)
I need to write a big changelog...
vim-ft-vim_foldと関係あるのかは不明。
thincaさんと自分の環境で再現。
Since v8.1.0369, Vim script supports "line continuation comment".
let array = [
"\ this line is a comment
\ 'first element',
"\ line continuation comment must start with `"\ `
\ 'second element',
\ ]
Normally, caw.vim makes a line \ 'text'
into " \ 'text'
by comment out. But this is invalid comment.
Can we add a new rule that changes \ 'text'
into "\ 'text'
when a line starts with \
in Vim script?
Typing <Plug>(caw:wrap:uncomment)
in comment string
int i = /* 1 ? 2 : */ 0;
results in
int i = 1 ? 2 : 0;
Typing <Plug>(caw:wrap:uncomment)
in comment string does not change anything.
int i = /* 1 ? 2 : */ 0;
The next release: deprecate it
The next*2 release: remove it
The next release: remove it
In some cases, different comment format is inserted. For instance, I wrote a Python code (only one line) as below:
print("Hello World")
I executed gci
, and then the code became
/* print("Hello World") */
it has also happened in Ruby file. A code
puts "Hello World"
became
/* puts "Hello World" */
In both case, :echo &ft
taught the correct file type (i.e. python
and ruby
)
For below static method,
public static int add(int i1, int i2) {
return i1 + i2;
}
Create template comment like below:
/**
* @param i1
* @param i2
* @return
*/
Support multiline comment, like javadoc and C.
/**
* @param i1
* @param i2
* @return i1 + i2
*/
public static int add(int i1, int i2) {
return i1 + i2;
}
/*
* i1 + i2
*/
int add(int i1, int i2) {
return i1 + i2;
}
/**
, /*
)*
)*/
)Python のスクリプトを編集中、gco を使うと以下のようなエラーが出ました。
[Vim(let):E121: Undefined variable: dummy]::[function caw#keymapping_stub..98_caw_jump_comment_
next..98_caw_jump_comment..98_get_indent..98_get_indent_num..GetPythonIndent..75
_SearchParensPair, line 11]
手元にあるファイルをいくつか試してみましたが、バッファの初めの方の位置で使う分には大丈夫なのですが、
ある地点からこのエラーが出るようになり、以後、バッファの末尾まで、gco を使うと必ずこのエラーが出ます。
エラーを出しているのは indent/python.vim の関数なので、caw.vim の問題ではないと思うのですが、
caw.vim側で対処が可能かも知れないと思ったので報告しておきます。
Currently gcc
(by default, if <Plug>(caw:prefix)
is not mapped by user)
is mapped to <Plug>(caw:hatpos:toggle)
.
Line 139 in 037fb8d
But I want gcc
mapping to be smarter: Detect which comment action should current comment under cursor be handled by (except jump
and input
):
And dispatch invoked method to detected action:
<Plug>(caw:{action}:{method})
For example, 3gcc
comment or uncomment 3 line.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.