tpope / vim-commentary

commentary.vim: comment stuff out
http://www.vim.org/scripts/script.php?script_id=3695
5.88k stars 215 forks source link

Breaks indentation #20

Closed dhruvasagar closed 7 years ago

dhruvasagar commented 10 years ago

Hi,

while using commentary to comment on javascript files, I have noticed that we add spaces instead of tabs after the commentstring, which breaks linters (jshint) for javascript.

dhruvasagar commented 10 years ago

If the file has tabs, we should use tabs for indents, otherwise spaces?

tpope commented 10 years ago

We should, but I'm not sure what should happen when 'tabstop' does not equal 'shiftwidth', and we break a tab in half.

dhruvasagar commented 10 years ago

hmm

seliverstov-maxim commented 4 years ago

it breaks indention before:

class SomeClass
    def some_method
        do_something
    end
end

use command for method:

class SomeClass
# def some_method
# do_something
# end
end

use command for method again:

class SomeClass
def some_method
do_something
end
end

expectation:

class SomeClass
#   def some_method
#       do_something
#   end
end
seliverstov-maxim commented 4 years ago

Reopen issue pls

tpope commented 4 years ago

This is with hard tabs? Your example doesn't have hard tabs.

What is the value of :echo get(b:, 'commentary_startofline')?

seliverstov-maxim commented 4 years ago

Nothing happen if I enter this command :echo get(b:, 'commentary_startofline')

This is with hard tabs? Your example doesn't have hard tabs.

Yes. It's spaces.

my vimrc

set nrformats=
set clipboard=unnamedplus
set shiftwidth=2
set smarttab
set expandtab
set smartindent

set nocompatible        " use vim defaults
set scrolloff=3         " keep 3 lines when scrolling
set ai                  " set auto-indenting on for programming

set showcmd             " display incomplete commands
set nobackup            " do not keep a backup file
set number              " show line numbers
set ruler               " show the current row and column

set hlsearch            " highlight searches
set incsearch           " do incremental searching
set showmatch           " jump to matches when entering regexp
set ignorecase          " ignore case when searching
set smartcase           " no ignorecase if Uppercase char present

set visualbell t_vb=    " turn off error beep/flash
set novisualbell        " turn off visual bell

set backspace=indent,eol,start  " make that backspace key work the way it should
set runtimepath=$VIMRUNTIME     " turn off user scripts, https://github.com/igrigorik/vimgolf/issues/129

syntax on               " turn syntax highlighting on by default
filetype on             " detect type of file
filetype indent on      " load indent file for specific file type

set t_RV=               " http://bugs.debian.org/608242, http://groups.google.com/group/vim_dev/browse_thread/thread/9770ea844cec3282
set rtp +=~/.vim
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'
Plug 'rking/ag.vim'
Plug 'slim-template/vim-slim'
Plug 'chrisbra/vim-commentary'
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-entire'
call plug#end()
set runtimepath^=~/.vim/bundle/ctrlp.vim

map <C-r> :NERDTreeFind<CR>
map <C-n> :NERDTreeToggle<CR>
map <C-j> :tabprevious<CR>
map <C-k> :tabnext<CR>

autocmd BufWritePre * %s/\s\+$//e

let g:ctrlp_max_files=0
let g:ctrlp_max_depth=40

set backupdir=/tmp//
set directory=/tmp//
set undodir=/tmp//
seliverstov-maxim commented 4 years ago

Issue is "Breaks indentation". My indention reliazed by spaces.

seliverstov-maxim commented 4 years ago

I suppose that if there is a space at the beginning of the line then replace it by #. At least leave as is but don't delete spaces.