VIM Syntax highlighting not functioning - vim

I am fairly new to vim and trying to get syntax highlighting in place. i made and edited my vimrc file and when i look at that file it is colored. But when i go to my python files they have no highlighting. Any help would be great!
L: http://vim.wikia.com/wiki/Example_vimrc
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode
" Description: A minimal, but feature rich, example .vimrc. If you are a
" newbie, basing your first .vimrc on this file is a good choice.
" If you're a more advanced user, building your own .vimrc based
" on this file is still a good idea.
"------------------------------------------------------------
" Features {{{1
"
" These options and commands enable some very useful features in Vim, that
" no user should have to live without.
" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
set nocompatible
" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on
" Enable syntax highlighting
syntax on
"------------------------------------------------------------
" Must have options {{{1
"
" These are highly recommended options.
" Vim with default settings does not allow easy switching between multiple files
" in the same editor window. Users can use multiple split windows or multiple
" tab pages to edit multiple files, but it is still best to enable an option to
" allow easier switching between files.
"
" One such option is the 'hidden' option, which allows you to re-use the same
" window and switch from an unsaved buffer without saving it first. Also allows
" you to keep an undo history for multiple files when re-using the same window
" in this way. Note that using persistent undo also lets you undo in multiple
" files even in the same window, but is less efficient and is actually designed
" for keeping undo history after closing Vim entirely. Vim will complain if you
" try to quit without saving, and swap files will keep you safe if your computer
" crashes.
set hidden
" Note that not everyone likes working this way (with the hidden option).
" Alternatives include using tabs or split windows instead of re-using the same
" window as mentioned above, and/or either of the following options:
" set confirm
" set autowriteall
" Better command-line completion
set wildmenu
" Show partial commands in the last line of the screen
set showcmd
" Highlight searches (use <C-L> to temporarily turn off highlighting; see the
" mapping of <C-L> below)
set hlsearch
" Modelines have historically been a source of security vulnerabilities. As
" such, it may be a good idea to disable them and use the securemodelines
" script, <http://www.vim.org/scripts/script.php?script_id=1876>.
" set nomodeline
"------------------------------------------------------------
" Usability options {{{1
"
" These are options that users frequently set in their .vimrc. Some of them
" change Vim's behaviour in ways which deviate from the true Vi way, but
" which are considered to add usability. Which, if any, of these options to
" use is very much a personal preference, but they are harmless.
" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase
" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start
" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent
" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline
" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler
" Always display the status line, even if only one window is displayed
set laststatus=2
" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm
" Use visual bell instead of beeping when doing something wrong
set visualbell
" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=
" Enable use of the mouse for all modes
set mouse=a
" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2
" Display line numbers on the left
set number
" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200
" Use <F11> to toggle between 'paste' and 'nopaste'
set pastetoggle=<F11>
"------------------------------------------------------------
" Indentation options {{{1
"
" Indentation settings according to personal preference.
" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
set shiftwidth=2
set softtabstop=2
set expandtab
" Indentation settings for using hard tabs for indent. Display tabs as
" two characters wide.
"set shiftwidth=2
"set tabstop=2
"------------------------------------------------------------
" Mappings {{{1
"
" Useful mappings
" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
" which is the default
map Y y$
" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
nnoremap <C-L> :nohl<CR><C-L>
"------------------------------------------------------------
File in in location of :
/home/pi

Solved, using sudo to launch vim and was referencing the from vimrc

Related

Visible Lines/Underscores on Vim

I have these lines or underscores I am trying to remove on vim text editor:
The horizontal lines disappear when there is some text or code on a line.
Please let me know if you came across this before! Thanks.
Here is my .vimrc:
call plug#begin('~/.vim/plugged')
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" - Vim (Windows): '~/vimfiles/plugged'
" - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
" - e.g. `call plug#begin('~/.vim/plugged')`
" - Avoid using standard Vim directory names like 'plugin'
" Make sure you use single quotes
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'
" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'
" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" On-demand loading
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Using a non-default branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }
" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }
" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'
" Initialize plugin system
" - Automatically executes `filetype plugin indent on` and `syntax enable`.
call plug#end()
" You can revert the settings after the call like so:
" filetype indent off " Disable file-type-specific indentation
" syntax off " Disable syntax highlighting
Plug 'crispybaccoon/dawn.vim'
set background=dark
colorscheme dawn
" Access full color space
if (has("termguicolors"))
set termguicolors
endif
" sometimes fixes problems on some terminals
set t_Co=256
" Disable compatibility with vi which can cause unexpected issues.
set nocompatible
" Enable type file detection. Vim will be able to try to detect the type of file in use.
filetype on
" Enable plugins and load plugin for the detected file type.
filetype plugin on
" Load an indent file for the detected file type.
filetype indent on
" Turn syntax highlighting on.
syntax on
" Add numbers to each line on the left-hand side.
set number
" Highlight cursor line underneath the cursor horizontally.
"set cursorline
" Highlight cursor line underneath the cursor vertically.
"set cursorcolumn
" Set shift width to 4 spaces.
set shiftwidth=4
" Set tab width to 4 columns.
set tabstop=4
" Use space characters instead of tabs.
set expandtab
" Do not save backup files.
set nobackup
" Do not let cursor scroll below or above N number of lines when scrolling.
set scrolloff=10
" Do not wrap lines. Allow long lines to extend as far as the line goes.
set nowrap
" While searching though a file incrementally highlight matching characters as you type.
set incsearch
" Ignore capital letters during search.
set ignorecase
" Override the ignorecase option if searching for capital letters.
" This will allow you to search specifically for capital letters.
set smartcase
" Show partial command you type in the last line of the screen.
set showcmd
" Show the mode you are on the last line.
set showmode
" Show matching words during a search.
set showmatch
" Use highlighting when doing a search.
set hlsearch
" Set the commands to save in history default number is 20.
set history=1000
" Enable auto completion menu after pressing TAB.
set wildmenu
" Make wildmenu behave like similar to Bash completion.
set wildmode=list:longest
" There are certain files that we would never want to edit with Vim.
" Wildmenu will ignore files with these extensions.
set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx
I have been trying to customize my vim text editor. I also have tried to install plugins for different themes. I tried using tree-sitter as well but that is not really working for me right now.
seems like the line
colorscheme dawn
was the one causing this issue.
i have contacted the theme creator and posted the issue on the github repository that i got it from. thanks guys!

VIM: Backspace deletes in normal mode, but does nothing in insert mode.

Preliminary Info:
Issue is in terminal Vim, not gVim
I used CMDER (based on conemu) as my terminal emulator
I am on Windows 10
Detailed Description:
When I'm in Insert mode, I can type text as normal, but backspace does nothing. While in normal mode, the backspace key deletes text. This is exactly opposite the behavior I had just earlier today. I have read numerous other posts online describing Vim's unorthodox backspace behavior, but the suggested config settings (namely bs=2 or bs=indent,eol,start) had done nothing.
More unusual is that gVim behaves "normally" that is: Backspace move the cursor to the left in normal mode, and deletes text in insert mode.
What I would like is for backspace to delete text in insert mode (just like most other programs) and to be navigation/disabled in normal mode. How can I regain this behavior?
Below is a copy of my _vimrc: (I would put this on github but my git is messed up at the moment and I've yet to fix it.) Additionally there was a function that was inside of the _vimrc by default. I have no idea what it does but omitted it to save space. If you want to see if I can post it in a reply.
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
" Pathogen - Plugin manager
execute pathogen#infect()
set nocompatible " Turns off Vi compatability gubbinz
" Color Theme
if !has("gui_running") " Allows some 256 color themes to work in Terminal
set term=xterm
set t_Co=256
let &t_AB="\e[48;5;%dm"
let &t_AF="\e[38;5;%dm"
colorscheme gruvbox
endif
let g:gruvbox_dark_contrast = 'hard' " Both of these are just visual gruvbox tweaks
let g:gruvbox_light_contrast = 'hard'
set guifont=Consolas:h10:cANSI:qDRAFT " Changes font
set bs=indent,eol,start " Makes backspace be normal
set filetype=ON " Has vim check for filetype
set showcmd " Displays incomplete commands
set ruler " Shows position of cursor in document
set syntax=ON " Turns on syntax highlighting
set number " Show line numbers
set linebreak " Break lines at word (requires Wrap lines)
set showbreak=+++ " Wrap-broken line prefix
set textwidth=100 " Line wrap (number of cols)
set showmatch " Highlight matching brace
set hlsearch " Highlight all search results
set smartcase " Enable smart-case search
set incsearch " Searches for strings incrementally
set autoindent " Auto-indent new lines
set shiftwidth=4 " Number of auto-indent spaces
set smartindent " Enable smart-indent
set smarttab " Enable smart-tabs
set softtabstop=4 " Number of spaces per Tab
set undolevels=1000 " Number of undo levels
set backspace=indent,eol,start " Backspace behaviour
set go=egrLTm " Changes flags that specify how the GUI loads
Most likely, your insert-mode backspace is mapped to do nothing (i.e. <nop>). Verify this by typing :verbose imap <bs>. This will show if backspace key is mapped and where the map was set.
What I would like is for backspace to delete text in insert mode (just like most other programs) and to be navigation/disabled in normal mode. How can I regain this behavior?
You can do:
iunmap <bs>
nnoremap <bs> <nop>
The first line unmaps <bs> in insert mode, thus <bs> will recover its default functionality. The second line maps <bs> in normal mode to do nothing.

Why might this .vimrc.after file not be loading correctly?

So I have a .vimrc.after setup as below using the Janus plugin on Ubuntu 14.04. The main trouble I'm having is that a line of text gets a line break (instead of wrapping) even when I don't press the enter key. Any ideas as to why is this happening? I've been experimenting a bit but haven't been able to come up with happening.
" When editing a text file, if you want word wrapping, but only want line breaks inserted when you explicitly press the Enter key:
:set wrap
:set linebreak
:set nolist " list disables linebreak
" In addition, you will need to prevent Vim from automatically inserting line breaks in newly entered text. The easiest way to do this is:
:set textwidth=0
:set wrapmargin=0
" Configure for ctags
:set tags=./tags;
" set clipboard=unnamedplus
set clipboard+=unnamed
" Use ack instead of grep
" set grepprg=ack
" Use Silver Searcher instead of grep
set grepprg=ag

Vim, why do I have some parts highlighted?

When I edit html, I have highlights like this picture
I don't want it highlighted. FYI this is my .vimrc
set nocompatible " be iMproved, required
filetype off " required
set rtp+=~/.vim/bundle/vundle/ " set the runtime path to include Vundle and initialize
call vundle#rc()
" Bundle 'gmarik/vundle' " let Vundle manage Vundle, required
Bundle "wookiehangover/jshint.vim"
Bundle "mru.vim"
Bundle 'godlygeek/tabular'
Bundle 'plasticboy/vim-markdown'
filetype plugin indent on " required
syntax on " Enable syntax highlighting
set wildmenu " Better command-line completion
set showcmd " Show partial commands in the last line of the screen
set hlsearch
set autoindent
set shiftwidth=2
set softtabstop=2
set expandtab " Allow backspacing over autoindent, line breaks and start of insert action
set ignorecase " for case insensitive search
set smartcase " except when using capital letters
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
set splitright " when vertically split, open new window on the right(default, left)
set splitbelow " when horizontally split, open new window on the bottom(default, top)
" Keyboard Mapping
nnoremap <Leader>b :MRU<CR> " \b to see the most recent used files
" = to run tidy on html
au FileType html setlocal equalprg=tidy\ -q\ -i\ --show-errors\ 0\ --tab-size\ 4\ --wrap\ 200\ --indent-spaces\ 4
" for markdown plugin
let g:vim_markdown_folding_disabled=1
let g:vim_markdown_no_default_key_mappings=1
EDIT ----
I love this SO community.
I followed all comments and answers, and found out the following soultion;
changed <i/> to <i></i>
syntax off
syntax on
It might be because of the <i/> tag... your syntax highlighting might not recognize that you self-closed it.
Otherwise you might have the 'list' option set (it's not in your vimrc, but a plugin might have added it)... If some of your code is indented with tabs and other parts spaces, then if 'list' is set then it will highlight just the tabs, for example.
Try doing :set nolist and see if the highlighted areas go away. You can remove stray tabs or spaces (depending on your expandtab setting) by doing :retab.
The visual result of :set list depends on your colorscheme and your setting for listchars. For example, I have set listchars=tab:▸\ ,eol:¬ in my .vimrc at home. See :help 'listchars' for more information.
If you want to still have some visual distinction between leading tabs and spaces, you can modify your colorscheme. This is a bit more involved. From the Vim help:
The "NonText" highlighting will be used for "eol", "extends" and
"precedes". "SpecialKey" for "nbsp", "tab" and "trail".
To change the visual appearance of these syntax groups, add your own :highlight commands in your .vimrc or edit a colorscheme file.

Does the order of the sections of code in my _vimrc matter?

How do the sections of code in the _vimrc file interact with each other?
My current file looks like the following but I'm wondering if it matters if a line such as filetype plugin indent on is at the start or the end of this file?
Does it matter if a line like filetype plugin indent on is repeated twice in the file?
Should the Pathogen settings be near the start?
"------------------------------------------------------------
" Must have options {{{1
"this will make the window maximized on startup
au GUIEnter * simalt ~x
" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on
set omnifunc=syntaxcomplete#Complete
" Enable syntax highlighting
syntax on
"set highlight search always on
:set hlsearch
"------------------------------------------------------------
" Usability options {{{1
" Show partial commands in the last line of the screen
set showcmd
" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase
" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start
" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent
" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline
" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler
" Always display the status line, even if only one window is displayed
set laststatus=2
" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm
" Use visual bell instead of beeping when doing something wrong
set visualbell
" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=
" Enable use of the mouse for all modes
set mouse=a
" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2
" Display line numbers on the left
set number
" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200
" Use <F11> to toggle between 'paste' and 'nopaste'
set pastetoggle=<F11>
"------------------------------------------------------------
" Indentation options {{{1
"
" Indentation settings according to personal preference.
" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
"set shiftwidth=2
"set softtabstop=2
"set expandtab
" Indentation settings for using hard tabs for indent. Display tabs as
" two characters wide.
set shiftwidth=2
set tabstop=2
"------------------------------------------------------------
" Look and Feel {{{1
"
" Use CTRL-S for saving, also in Insert mode
:nnoremap <C-S> :<C-U>update<CR>
:vnoremap <C-S> :<C-U>update<CR>gv
:cnoremap <C-S> <C-C>:update<CR>
:inoremap <C-S> <C-O>:update<CR>
"color scheme setting
" Set nice colors
" background for normal text is light grey
" Text below the last line is darker grey
" Cursor is green, Cyan when ":lmap" mappings are active
" Constants are not underlined but have a slightly lighter background
set guifont=Consolas:h16:cANSI
colorscheme pyte
"highlight Normal guibg=grey90
"highlight Cursor guibg=Green guifg=NONE
"highlight lCursor guibg=Cyan guifg=NONE
"highlight NonText guibg=grey80
"highlight Constant gui=NONE guibg=grey95
"highlight Special gui=NONE guibg=grey95
"a quick way to locate python files
nnoremap <Leader>p :pyf P:\Computer Applications\Python\
"quick quit command
noremap <Leader>e :quit<CR> "quits the current window
"------------------------------------------------------------
" NERTtree settings {{{1
"
"get NERDTree command quick
nnoremap <Leader>nd :NERDTree M:\
map <F2> :NERDTreeToggle<CR>
let NERDTreeQuitOnOpen = 1
" Rebind <Leader> key...not sure about this one
"let mapleader = ","
map <Leader>n <esc>:tabprevious<CR>
map <Leader>m <esc>:tabnext<CR>
"------------------------------------------------------------
" dbext settings {{{1
"
"let g:sql_type_default = 'SQLSVR'
" Since I repeatedly need to edit stored procedures, the CREATE PROCEDURE
" statement is preceeded by an IF ... END IF block which will drop
" the procedure or it uses the CREATE OR REPLACE syntax.
" This function will visually select the IF block to the END; statement
" of the stored procedure and execute it. Or check for the
" CREATE OR REPLACE and stop there and look to the end.
function! SQLExecuteIfCreateReplace()
let l:old_sel = &sel
let &sel = 'inclusive'
let saveWrapScan=&wrapscan
let saveSearch=#/
let l:reg_z = #z
let &wrapscan=0
let #z = ''
let found = 0
let startLine = 0
let endLine = 0
let curLine = line(".")
let curCol = virtcol(".")
" Must default the command terminator
let l:dbext_cmd_terminator = ";"
try
" Search backwards and do NOT wrap
" Find the line beginning with an IF clause
" IF EXISTS( SELECT 1 ...
" or find an or replace clause
" CREATE OR REPLACE PROCEDURE ...
" And execute it until we find an
" END
" at the beginning of a line.
let startLine = search('\c\(^\<if\>\|^\<alter\s\+procedure\>\|\<or\s\+replace\>\)', 'bcnW' )
if startLine > 0
" Search forward and visually select all lines
" until we find an END; clause
let endLine = search('^END'.l:dbext_cmd_terminator.'\s*$', 'cnW')
exec startLine.','.endLine.'DBExecRangeSQL'
endif
finally
call cursor(curLine, curCol)
noh
let l:query = #z
let #z = l:reg_z
let #/=saveSearch
let &wrapscan=saveWrapScan
let &sel = l:old_sel
endtry
endfunction
"------------------------------------------------------------
" pathogen settings {{{1
"pathogen customization
"set nocp
" Use pathogen to easily modify the runtime path to include all plugins under
" the ~/.vim/bundle directory
filetype off " force reloading *after* pathogen loaded
call pathogen#infect()
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
syntax on
filetype plugin indent on " enable detection, plugins and indenting in one step
The order does matter.
e.g. you have two lines:
Options:
set nu
set nonu
the latter will overwrite the previous setting.
for functions, if you declared a function at the end of your file, but called it at the 1st line. When you load your vimrc the first time, you will get the error Unknown function: function name
Also if you manually set some hi group before the color scheme (if you used one) loading, the color scheme is gonna overwrite your settings too.
If you call some command/function defined in a plugin before it was loaded, you will have error message too.
so , it is ok if you have some command/setting in vimrc multiple times, but the last one will take effect.
tl;dr: Some do, some don't; use a logical structure from simple to complex.
Pathogen wants its settings to appear at the top, because it modifies the way other scripts are loaded (explicitly via :runtime, or as a side effect of calling autoload functions).
The order of :set usually doesn't matter (unless you have conflicting settings), and any mappings or autocmds you define are only activated after the startup, so you can put them anywhere.
In general, I'd recommend a logical structure, starting with basic stuff like Pathogen, settings, plugin configuration, followed by custom mappings and more involved adaptations like autocmds.
Also, I'd avoid putting filetype-specific stuff into ~/.vimrc; rather, put those into the corresponding ~/.vim/after/ftplugin/<filetype>.vim script and use filetype plugin on.

Resources