vim how to set good indet without syntax highlighting? - vim

I have mapped F8 to :set syntax=off<cr>.
I like editing without syntax highlighting, but if I switch syntax off, my indent rules also switched off. How can I have good indent without syntax highlighting?

If vim autoindent is ok for you , you can
set autoindent
after you "syntax off".
On the other hand, if you use your own index function. Try to run following command, which may help.
set indentexpr=<your function>
Or check the indent function by:
set indentexpr?
and reset it to the result after "syntax off"

What you want is to map that key to
:syntax off
Note that syntax is a command, and off an argument. You were setting the syntax option to the type off and consequentially affecting the indent rules.
Check :h :syntax and :h 'syntax' to read more.

Related

vim mouse mode disable on .vimrc

If I set :set mouse-=a to .vimrc, the highlight color will not be seen when I open the file with vim.
how can I set :set mouse-=a automatically when I use the vim editor with the previous feature(color, etc.)?
The syntax in .vimrc is set mouse=a.
You only use a preceding colon when you are using the command pallet accesed by pressing escape key.
The correct syntax in .vimrc to enable your mouse's usage is the following:
set mouse=a
It appears, according to your question, that you have added a hyphen character(-) before the equals sign, making it -=, when it should just be an equals sign (=).
Could you please make sure to remove the hyphen and see if it works after that?

Vim autoindent indents incorrectly

When writing code in vim, I've noticed that it sometimes messes up the indentation of the current line after pressing return. (In the gif, I go into insert mode, with the cursor at the end of the date function. When I press return, the whole "echo date('Y');" part looses its indentation when it should not).
I have a ton of directives in my vimrc to try and stop all kinds of autoindentation, but much to my irritation, the problem persists.
filetype plugin indent off
filetype plugin off
set noautoindent
set nosmartindent
set nocindent
set indentexpr=''
let b:did_indent = 1
set ft?
filetype indent off
I wish there was a way to have vim indent files much like your "more standard" text editors, whereby they don't try to be smart, but just maintain the current indentation of the current line in the new line. Like this:
Is this possible?
set smartindent is only needed on my VIM to get the effect you shown by gedit.
So it seems that this line was causing the first issue displayed in the vim. Its part of the Vundle plugin manager inclusion code:
filetype plugin indent on
Ensuring that my indent rules were after this fixed the problem completely.

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.

Indent lines as I type in vim

I know that gg=G is one of the simplest and easiest commands to indent lines in vim.
But, is there a way to indent lines as I type and press Enter?
Yes. Add the following to your vimrc:
set autoindent
filetype plugin indent on
Autoindent just indents based on the previous line's indentation if it does not know how to indent. Filetype indentation uses some things vim knows about what kind of programming language you are writing in to indent it correctly. Filetype indentation will override autoindentation.

vim: autoindent not working

my autoindent is not working, any diagnostic tests to figure it out?
my ":set" is:
:set
--- Options --- cindent laststatus=2 scroll=17
tabstop=4 window=36
filetype=cpp number
smartindent ttyfast
helplang=en paste
syntax=cpp ttymouse=xterm2
backspace=indent,eol,start
fileencoding=utf-8
fileencodings=ucs-bom,utf-8,default,latin1
printoptions=paper:letter
runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim72,/usr/share/vim/vimfiles/af
ter,/var/lib/vim/addons/after,~/.vim/after
suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
try:
:set ai
or:
:set autoindent
find more about auto-indent:
:h ai
Otherwise, it's might be something with file type detection.
I had a stale function in indentexpr which persisted after changing the filetype. This eventually fixed it for me:
:set indentexpr=
In case someone else face the same issue, I had a similar issue that none of the above fixed.
What was wrong for me was the tab interpretations. here is the set up that made it work:
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set smartindent
And to check when indenting if the indentation was correct, I added the following, still in my vimrc file:
" helper for indent mistake
set list listchars=tab:»·,trail:·
Which display a "»" instead of the regular "·" if my indent is wrong. Very handy.
Hope it helps.
I had the same issue and these settings fixed it.
filetype on
filetype plugin on
filetype indent on
You should probably turn off smartindent and use :filetype indent on and cindent (which seems to be also set) instead.
Here's one way to test out whether you have the configuration correct, then persist your configuration so Vim always operates thusly. This font indicates text which should be typed in literally, except <CR> means press the "Enter" or "Return" key.
Create a new system user, with a new home directory.
Start Vim. All settings should be set however they ship with Vim by default.
Open a file, say, test.txt.
Make sure autoindent is enabled (:set ai?<CR>)
Prove that autoindent doesn't happen:
Type a space or two, then hit enter.
When the cursor advances to the next line, it should return to column 1, the far-left column.
Turn on autoindent (:set ai<CR>)
Make sure autoindent is enabled (:set ai?<CR>)
Prove that autoindent happens:
Type a space or two, then hit enter.
When the cursor advances to the next line, it should still be in the same column.
Persist autoindent with :mkvimrc<CR>.
Hope that helps! Here are some other notes:
These instructions might be specific to left-to-right locales.
Here's my vimrc
"The 'autoindent' option is reset when the 'paste' option is set". So try to remove 'paste' from your settings (vim-options).
:set smartindent? showd: nosmartindent
Then activating it with :set smartindent solved problem for me.
I had the same problem, and I have tried many commands, all failed.
At last, I use the following command, and it works:
autocmd VimEnter * set autoindent
It's not a elegant method, however, it does works.

Resources