Giter Club home page Giter Club logo

caw.vim's Introduction

Build Status

Requirements

  • Vim 8.0 or later

Features

  • Supports 300+ filetypes (:help caw-supported-filetypes).
    • But caw.vim does not slow down your Vim startup because each comment string are defined at ftplugin files (after/ftplugin/<filetype>/caw.vim).
  • Supports operator keymappings (:help caw-keymappings-operator).
    • If g:caw_operator_keymappings is non-zero, all default keymappings map to operator keymappings.
    • If you need kana/vim-operator-user to use operator keymappings.
  • Supports also non-operator keymappings (:help caw-keymappings-non-operator).
  • Dot-repeatable if you installed kana/vim-repeat
  • The comment behavior only depends on 'filetype' by default. But if you have installed Shougo/context_filetype.vim, caw.vim also depends on the filetype of the context of the current cursor location. So you can comment/uncomment JavaScript in HTML correctly.
  • Well-tested powered by thinca/vim-themis

How it works

The below are the examples in "filetype=c". caw.vim supports 300+ filetypes (:help caw-supported-filetypes).

Type "gci" (toggle: "gcc", uncomment: "gcui")
  before:
      "   <- inserted here"
  after:
      "   # <- inserted here"

Type "gcI" (uncomment: "gcuI")
  before:
      "   inserted the first column"
  after:
      "#    inserted the first column"

Type "gca" (uncomment: "gcua")
  before:
      "inserted after this"
  after:
      "inserted after this    # "

Type "gcw" (uncomment: "gcuw")
  before:
      "  wrap!"
  after:
      "  /* wrap! */"

Type "gcb"
  before:
      "  box!"
  after:
      "  /********/"
      "  /* box! */"
      "  /********/"

Type "gco"
  before:
      "   func1();"
  after:
      "   func1()"
      "   // "  (now cursor is at the end and entered insert-mode)

Type "gcO"
  before:
      "   func1();"
  after:
      "   // "  (now cursor is at the end and entered insert-mode)
      "   func1();"

caw.vim's People

Contributors

ceda-ei avatar freed-wu avatar gonzoooooo avatar h1mesuke avatar haya14busa avatar hexium310 avatar ianpurvis avatar ichizok avatar jakalada avatar jubnzv avatar kotapiku avatar lumakernel avatar machakann avatar maku693 avatar mattn avatar minodisk avatar notomo avatar obcat avatar qs-f avatar rhysd avatar sciencesakura avatar shougo avatar tsuyoshicho avatar tyru avatar ujihisa avatar uplus avatar zchee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

caw.vim's Issues

Change comment type quickly

Type "rotate" mapping to change comment type quickly.

Example

In filetype=c, "rotate" mapping rotates the following comment types (including no comment string?)

oneline

// comment

wrap

/* comment */

multiline (#65)

/*
 * comment
 */

Tasks

  • Implement
  • Write tests
  • Add examples to :help caw-introduction and README.md

Error "Can't open i.vim" on MS Windows (and maybe Mac OS X)

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

Context filetype detection not working

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.

複数行のtoggleでコメントアウト時に末尾に空白が付く

filetype=zsh で確認。

fooooooooooooooooooooooo
bar

こんなテキストがあった場合に、この範囲を toggle すると、

# fooooooooooooooooooooooo_
# bar______________________

こうなります(_ は空白)。
もう一度 toggle すると末尾の空白も消えて元に戻ります。

Separate each object to each file

Current chaotic objects in one script file (autoload/caw.vim) style is horrible and difficult to add new features / fix bugs.

Target

  • s:comments
  • s:caw.xxx

コメントとコードが混じった範囲をトグルした場合の挙動が不自然

例えば以下のようなコードがあった場合、

" test1
call s:test1()
" test2
call s:test2()

この範囲をトグルすると以下のようになります。

test1
call s:test1()
test2
call s:test2()

この挙動は明らかに不便なので混じっている場合は一括でコメントアウトした方がいいかと思うのですが、どうでしょう。

メモから

CommentAnyWay.vimのダメなところ

  • 下手にオブジェクト指向なソースなので、多分とってもメモリを食う
    コメントを付けるだけのプラグインに大量のメモリを食われるのは馬鹿げている
  • 数年前に書いたので、自分自身にとってもソースコードがブラックボックスになっている
  • マルチラインコメントがバグだらけ
  • 定義がfiletypeに分かれておらず、プラグイン中にハードコードされている

CommentAnyWay.vimの素晴らしいところ

  • 設定の柔軟性
  • ワンラインコメントの時、自動的にインサートモードに入る機能
  • s:RegisterOptions()
  • Vim自身のコメントのオプションをパースして、
    ユーザによってセットされていなくて、
    CommentAnyWay.vimが定義を持っていなくても、
    定義が(うまくいけば)読み込める点

じゃあ新しいのを作ろう

具体的に、新しいプラグインに実装するのは次のようなもの。

  • そこそこな設定の柔軟性
    • あまりにも設定できる箇所が多すぎてもよくわからないしコードも繁雑になりがち
  • マルチラインコメントは実装しない
    • Vimの機能だけで自分的には十分 (:help format-comments)
  • ワンラインコメントの時、自動的にインサートモードに入る機能
  • s:RegisterOptions()
  • Vim自身のコメントのオプションをパースして、
    ユーザによってセットされていなくて、
    CommentAnyWay.vimが定義を持っていなくても、
    定義が(うまくいけば)読み込める点

新しい機能としては

  • 後ろに付いてるコメントを1つ上の行に持っていったりと
    コメントの形式を変換する機能
  • 随時追加予定

TODO

  • デバッグ用にコメントアウトしてるものをコメントイン(謎)したりコメントアウトするマッピング
  • 現在のシンタックスハイライトがどのファイルで定義されているかを見て
    HTML中のJSの部分では//でコメントアウトしたい

Align comments

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

Move comment string to various positions

Toggle a position of comment string in previous line, next line, after current line.

After current line:

hello    " :-)

Previous line:

" :-)
hello

Next line:

hello
" :-)

バッファを閉じた(:q)ときに E108

すいません、確かな再現方法がいまいちわかっていないのですが、最近からバッファを閉じたときに次のようなエラーがでる時があります。

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 を引いてそのウィンドウを閉じたときに多いような気がします。

tabの場合の処理

「<Tab>foo」という行があったとしたら、
「# <Tab>foo」ではなく「#<Tab>foo」になってほしい
(g:caw_sp_iを無視してほしい)

`<Plug>(caw:zeropos:toggle)` does not work on a buffer of ft=vim

Issue

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]

error gif

The way to reproduce

  1. execute vim -u vimrc -N (the vimrc is attached below)
  2. execute :e some_vim_file.vim
  3. insert some text
  4. type gcc in a line
  5. you will see the error

The 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)

Note

The error causes after dedb063

Environment

Smarter 'gcc' mapping (like Emacs "comment-dwim")

Currently gcc (by default, if <Plug>(caw:prefix) is not mapped by user)
is mapped to <Plug>(caw:hatpos:toggle).

call s:map_user('c', 'i:toggle')

But I want gcc mapping to be smarter: Detect which comment action should current comment under cursor be handled by (except jump and input):

  • hatpos
  • zeropos
  • dollarpos
  • wrap
  • box

And dispatch invoked method to detected action:

<Plug>(caw:{action}:{method})

Reference

About Emacs comment plugin (Japanese)

空行を含むコメント行の範囲をtoggleするとさらにコメントアウトされる

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すれば再現するはずです。

Generate ftplugin file if current filetype isn't supported

  1. If any mapping is executed but current filetype isn't supported, generate a ftplugin file or set buffer-local variables.
    • b:caw_oneline_comment
    • b:caw_wrap_oneline_comment
    • b:caw_wrap_multiline_comment
  2. If a user doesn't want to generate it, caw.vim should temporarily disable a prompt.

Operatorが欲しい

コメントアウトやコメントトグルする operator が欲しいです!

Upload to vim.org (ready for the next release)

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...

  • Write a changelog
  • Update help for a new feature, and so on
    • This is not released to vim.org yet ...
    • CommentAnyWay.vim is old and another plugin
  • Write help for #48
  • Write help for #50
  • Write remaining TODO in help (c286f58)
  • Think of required features for an initial release
    • #17, #18, #41, #57
    • Implement them all (freeze date: 2016/04/09 2016/04/17)
      • It is the "freeze date" when we implement/fix all of features/bugs (in addition to #48)
  • Create v1.0 tag
  • Wait 2 weeks until "freeze date"
  • If any problems do not occur and above tasks are all done, ship it :shipit:

Support for JSX and TSX

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!

Special behaviour for line continuation comment in Vim script

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?

Support multiline comment (not box comment)

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;
}

Options

  • start comment (e.g.: /**, /*)
  • middle comment (e.g.: *)
  • end comment (e.g.: */)
  • keep start comment line blank after comment string?

Comment/Uncomment/Toggle current comment block

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

Different comment format is inserted

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)

Can't comment/uncomment a hatpos portion of a line

ref #26

gc$ (comment)

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;

gcui (uncomment)

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;

Move some startup codes into autoload/caw.vim

it is not necessary to initialize global variables.

TODO

  • Change
  • Add to release note about destructive change
    • This can be destructive change for a user who supposes to refer global variables after loading plugin/caw.vim manually like :runtime! plugin/caw.vim.

Indentation loss on XML elements

Environment

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

Issue

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.

Example

The commenting below is within JSP files. However, even an HTML filetype does not change this behavior.

Original

 <div>
  <picture>
    <source
      media="(min-width: 1200px)"
      srcset="img.png, img.png@2x 2x"
    />
    <img src="img.png" alt="image" class="image" />
  </picture>
</div>

Commented

<%-- <div>                                               --%>
<%--   <picture>                                         --%>
<%--     <source                                         --%>
<%--       media="(min-width: 1200px)"                   --%>
<%--       srcset="img.png, img.png@2x 2x"               --%>
<%--     />                                              --%>
<%--     <img src="img.png" alt="image" class="image" /> --%>
<%--   </picture>                                        --%>
<%-- </div>                                              --%>

Uncommented

<div>
<picture>
<source
media="(min-width: 1200px)"
srcset="img.png, img.png@2x 2x"
/>
<img src="img.png" alt="image" class="image" />
</picture>
</div>

Python で gco, gcO を使うとエラー

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側で対処が可能かも知れないと思ったので報告しておきます。

haskellで動作しません

caw.vim/autoload/caw.vim
368行目に以下の様にhaskellは'--'でコメントアウトする、と追加すると
haskellで動くようになりました。

autoload/caw.vim- \ 'h': '//',
autoload/caw.vim: \ 'haskell': '--',
autoload/caw.vim- \ 'haml': '-#',

gco and gcO don't work.

最新(master)の caw で、gco/gcO が使えなくなっていることに気付きました。

調べてみたところ、caw#keymapping_stub() において、s:caw.jump に comment_database が設定されていないために action が call() されないようになっています。

Support for motion commands

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.