We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free. Anti-spam check. Do not fill this in!==Toggle forward/back slashes== The following script provides a command and a mapping to easily toggle slashes in the current line, or a range of lines. <pre> function! ToggleSlash(independent) range let from = '' for lnum in range(a:firstline, a:lastline) let line = getline(lnum) let first = matchstr(line, '[/\\]') if !empty(first) if a:independent || empty(from) let from = first endif let opposite = (from == '/' ? '\' : '/') call setline(lnum, substitute(line, from, opposite, 'g')) endif endfor endfunction command! -bang -range ToggleSlash <line1>,<line2>call ToggleSlash(<bang>1) noremap <silent> <F8> :ToggleSlash<CR> </pre> After sourcing the script, press F8 or enter <code>:ToggleSlash</code> to toggle between forward and back slashes. If no lines are selected, the command operates on the current line. If multiple lines are selected, the command operates on each selected line. A line is ignored if it does not contain a slash. By default, each line is handled independently: if the first slash in the line is a forward slash, all slashes in that line are changed to backslashes; if the first slash is a backslash, all slashes are changed to forward slashes. Enter <code>:ToggleSlash!</code> to force changes to each selected line to be the same: if the first slash found is a forward slash, all slashes in all selected lines are changed to backslashes; otherwise, all slashes in all selected lines are changed to forward slashes. Summary: Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA Cancel Editing help (opens in new window) Retrieved from "https://vim.fandom.com/wiki/Change_between_backslash_and_forward_slash"