Preventing vim to auto-expand folds - vim

I'm using foldmethod=marker and #{{{ #}}} markers in Python code.
After typing #{{{ vim automatically expands all folds below the cursor.
Is it possible to turn this off?

Try removing block from the "foldopen" option.
:set foldopen-=block
Or maybe the foldclose=all option...
:set foldclose=all

Try adding a match for the # {{{ like # {{{1 and then a # }}}1

Related

How to turn off Vim relativenumber setting?

Today I have discovered vim's relativenumber option. I really would like to use it, but sometimes I need to swap between relative numbering and classic one.
I have tried to turn it off with :set relativenumber=off option (which returns me error attached above) and using :set number again but none of those works.
To turn on relative line numbering use this:
:set rnu
To turn it off use this:
:set nornu
By the way, if you had Googled around for your question, you would have found this great post which discusses things in more detail.
To turn on whatever option in vim:
:set <option>
To turn off whatever option in Vim:
:set no<option>
To toggle an option on/off:
:set <option>!
To check if an option is on or off:
:set <option>?
To set an option back to its default:
:set <option>&
I just use this toggle switch in my vimrc file.
function! NumberToggle()
if(&rnu == 1)
set nornu
else
set rnu
endif
endfunc
nnoremap <C-l> :call NumberToggle()<cr>
Relative Numbering is not turned on by default in vim, which means that you are probably turning it on through your ~/.vimrc file or one of your plugins. Look for set relativenumber or set rnu.
To turn it off for the current vim session you would simply run set norelativenumber or set nornu for short. This is a normal vim pattern for turning on and off settings like this. For example, spell check is set spell to activate and set nospell to deactivate.
To find this information and more on relative numbering, I recommend that you look in the vim help docs. For this case, while in vim run :h relativenumber
You actually have hybrid mode on (the line number your cursor is on is labelled as the absolute line number, not 0). In this case, both nu and rnu are on. You'll need to remove both to remove line numbers:
The following should work:
set nornu nonu

How to fold all code between {{{ and }}} in vim

I have a lot of code like this
#{{{
code here
#}}}
#{{{
more code here
#}}}
etc...
I want to fold all of them instead of going to each #{{{ line and type zfa{.
I read the vim documentation and tried typing set foldmethod={{{ but I got the error E474: Invalid argument: foldmethod={{{ .
What do I press on my keyboard to tell vim to fold all code between #{{{ and #}}}?
And what do I press to expand them all again?
The foldmethod option is not for setting the fold marker.
You can set up fold markers by doing something like this:
set foldmethod=marker
set foldmarker={{{,}}}
As for vim's folding shortcuts, this article on the vim tips wiki is very helpful.
http://vim.wikia.com/wiki/Folding
For more help on folding, you can do :help folding inside of vim.
For help on the keyboard shortcuts for folding, do :help fold-commands
In your vimrc add the option set foldmethod=marker. Then to fold you type zm and to unfold type zr.

how to activate vim folding markers?

I have inherited some c++ code with vim-based folding markers like this:
// CONSTRUCTORS/DESTRUCTORS /*{{{*/
Foo::Foo()
{
}
Foo::~Foo()
{
}
/*}}}*/
What do I need to put into my .vimrc to enable folding toggles like zm and space-bar?
With my current settings, when I hit space bar inside or zm, vim does nothing.
The default keybindings for folding are za or zm (though zm I think only closes folds, while za toggles them), so you should add the following lines to your .vimrc:
set foldmethod=marker to enable folding triggered by markers (the {{{ things in your code)
nnoremap <space> za to enable space to trigger the fold in normal mode.
But! if you're not sure if you want to enable folding in other files, you could use autocmds, like so:
autocmd FileType vim,c++,txt setlocal foldmethod=markerand that will ensure that folding only works in vim, c++, and text files.
By the way, what you've posted is only one kind of folding mentioned by vim guru Steve Losh in this article. Read it to learn more about folding. It's super cool.
If you only have a few files or if you just wish to control option(s) on a per file basis you may want to use modeline. My intro to folding came when I download a z-shell script and when I opened it, was surprised to find everything folded. Found something like this at the end of the file:
# vim:ts=4:sw=4:ai:foldmethod=marker:foldlevel=0:
Change commenting to match your code type, and insure there is a space before the word vim. As always a good place to start: :help modeline and :help folding. You may have to add set modeline to your .vimrc file if modeline was not set at build time.
OK, after googling around for a bit, I found this which seems to work:
set foldmethod=marker
nnoremap <space> za

vim autoindent stop from removing indents

I try to use vim with its autoindent feature which works reasonably well. But I find it very annoying that in some situation it removes indents as well because it produces additional work. For example when I have a single indented line, I go to the end of the line and type then vim removes the indent of the line. How can I turn of the removal of existing indents?
Did you tried:
:set noautoindent
:set noai #same as above
Or try to do with smart indent
:set nosmartindent
:set nosi #same

Word wrap in Gvim

How do I make Gvim word wrap in such a way that doesn't break words in the middle?
Looks like there is a solution online after all.
:set formatoptions=l
:set lbr
Link: http://vim.wikia.com/wiki/Word_wrap_without_line_breaks
You can
:set nowrap
to just let huge lines scroll of the edge of your screen. But tw is probably the better way to go.
you can
:set wrap linebreak nolist
:set tw=78
sets the text width to 78 characters. You can use "[movement]gq" to re-wrap some text.
I use the following settings to wrap long lines for things like markdown files.
:set wrap
:set linebreak
:set nolist " list disables linebreak
:set textwidth=0
:set wrapmargin=0
Source: http://vim.wikia.com/wiki/Word_wrap_without_line_breaks
You can also use wrapmargin, which the manual defines as:
Number of characters from the right window border where wrapping
starts. When typing text beyond this limit, an <EOL> will be inserted
and inserting continues on the next line.

Resources